int fio_batch_write(struct fio_batch *batch, int fd) { ssize_t bytes_written = fio_writev(fd, batch->iov, batch->iovcnt); if (bytes_written <= 0) return 0; if (bytes_written == batch->bytes) return batch->rows; /* returns the number of written rows */ say_warn("fio_batch_write, [%s]: partial write," " wrote %jd out of %jd bytes", fio_filename(fd), (intmax_t) bytes_written, (intmax_t) batch->bytes); /* Iterate over end of row flags */ struct bit_iterator bit_it; bit_iterator_init(&bit_it, batch->rowflag, batch->max_iov / CHAR_BIT + 1, 1); size_t row_last_iov = bit_iterator_next(&bit_it); int good_rows = 0; /* the number of fully written rows */ ssize_t good_bytes = 0; /* the number of bytes in fully written rows */ ssize_t row_bytes = 0; /* the number of bytes in the current row */ struct iovec *iov = batch->iov; while (iov < batch->iov + batch->iovcnt) { if (good_bytes + row_bytes + iov->iov_len > bytes_written) break; row_bytes += iov->iov_len; if ((iov - batch->iov) == row_last_iov) { /* the end of current row */ good_bytes += row_bytes; row_bytes = 0; good_rows++; row_last_iov = bit_iterator_next(&bit_it); } iov++; } /* * Unwind file position back to ensure we do not leave * partially written rows. */ off_t good_offset = fio_lseek(fd, good_bytes - bytes_written, SEEK_CUR); /* * The caller may choose to close the file right after * a partial write. Don't take chances and make sure that * there is no garbage at the end of file if it happens. */ if (good_offset != -1) (void) fio_truncate(fd, good_offset); /* * writev() doesn't set errno in case of a partial write. * If nothing else from the above failed, set errno to * EAGAIN. */ if (! errno) errno = EAGAIN; return good_rows; /* returns the number of written rows */ }
int fio_batch_write(struct fio_batch *batch, int fd) { ssize_t bytes_written = fio_writev(fd, batch->iov, batch->rows); if (bytes_written <= 0) return 0; if (bytes_written == batch->bytes) return batch->rows; say_warn("fio_batch_write, [%s]: partial write," " wrote %jd out of %jd bytes", fio_filename(fd), (intmax_t) bytes_written, (intmax_t) batch->bytes); ssize_t good_bytes = 0; struct iovec *iov = batch->iov; while (iov < batch->iov + batch->rows) { if (good_bytes + iov->iov_len > bytes_written) break; good_bytes += iov->iov_len; iov++; } /* * Unwind file position back to ensure we do not leave * partially written rows. */ off_t good_offset = fio_lseek(fd, good_bytes - bytes_written, SEEK_CUR); /* * The caller may choose to close the file right after * a partial write. Don't take chances and make sure that * there is no garbage at the end of file if it happens. */ if (good_offset != -1) (void) fio_truncate(fd, good_offset); /* * writev() doesn't set errno in case of a partial write. * If nothing else from the above failed, set errno to * EAGAIN. */ if (! errno) errno = EAGAIN; return iov - batch->iov; }
int main() { int whichdrawbuf = 0; int s; char *buffer; int i; int size; int rc; int fd; // Initialise RPC system. sif_rpc_init(0); // Setup the Video. DmaReset(); initGraph(3); SetVideoMode(); //install_VRstart_handler(); // Setup the double buffers. // SetDrawFrameBuffer(1); // SetDrawFrameBuffer(0); // SetCrtFrameBuffer(1); // Load the modules! loadModules(); // Loaded the modules.. now try ps2ip now.. if(ps2ip_init()<0) { printf("ERROR: ps2ip_init failed2"); k_SleepThread(); } //put here your file path fd=fio_open("ps2vfs:\\primer\\segun\\mio.txt",O_RDONLY); if (fd>0) { printf("file id kernel is %d \n"); size=fio_lseek(fd,0,SEEK_END); i=fio_lseek(fd,0,SEEK_SET); buffer=(char *)malloc(sizeof(char)*size); i=fio_read(fd,buffer,size); printf("receive size: %d \n",i); printf("receive: buffer= %s \n",buffer); fio_close(fd); } while ( 1 ) { //WaitForNextVRstart(1); //ClearVRcount(); //SetCrtFrameBuffer(whichdrawbuf); //whichdrawbuf ^= 1; //SetDrawFrameBuffer(whichdrawbuf); // scr_printf( "t" ); } // We shouldn't get here.. but just in case. k_SleepThread(); }