Fri, 12 Jan 2018 18:12:42 +0100
adds vfs pread/pwrite functions
--- a/src/server/daemon/vfs.c Fri Jan 12 17:54:52 2018 +0100 +++ b/src/server/daemon/vfs.c Fri Jan 12 18:12:42 2018 +0100 @@ -60,6 +60,8 @@ static VFS_IO sys_file_io = { sys_file_read, sys_file_write, + sys_file_pread, + sys_file_pwrite, sys_file_seek, sys_file_close, //sys_file_aioread, @@ -496,6 +498,14 @@ return write(fd->fd, buf, nbyte); } +ssize_t sys_file_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) { + return pread(fd->fd, buf, nbyte, offset); +} + +ssize_t sys_file_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) { + return pwrite(fd->fd, buf, nbyte, offset); +} + off_t sys_file_seek(SYS_FILE fd, off_t offset, int whence) { return lseek(fd->fd, offset, whence); } @@ -584,6 +594,14 @@ return fd->io->write(fd, buf, nbyte); } +NSAPI_PUBLIC int system_pread(SYS_FILE fd, void *buf, int nbyte, off_t offset) { + return fd->io->pread(fd, buf, nbyte, offset); +} + +NSAPI_PUBLIC int system_pwrite(SYS_FILE fd, const void *buf, int nbyte, off_t offset) { + return fd->io->pwrite(fd, buf, nbyte, offset); +} + NSAPI_PUBLIC off_t system_lseek(SYS_FILE fd, off_t offset, int whence) { return fd->io->seek(fd, offset, whence); } @@ -626,8 +644,7 @@ } static void* vfs_aio_read(aiocb_s *aiocb) { - system_lseek(aiocb->filedes, aiocb->offset, SEEK_SET); - int result = system_fread(aiocb->filedes, aiocb->buf, aiocb->nbytes); + int result = system_pread(aiocb->filedes, aiocb->buf, aiocb->nbytes, aiocb->offset); aiocb->result = result; if(result < 0) { aiocb->result_errno = errno; @@ -637,8 +654,7 @@ } static void* vfs_aio_write(aiocb_s *aiocb) { - system_lseek(aiocb->filedes, aiocb->offset, SEEK_SET); - int result = system_fwrite(aiocb->filedes, aiocb->buf, aiocb->nbytes); + int result = system_pwrite(aiocb->filedes, aiocb->buf, aiocb->nbytes, aiocb->offset); aiocb->result = result; if(result < 0) { aiocb->result_errno = errno;
--- a/src/server/daemon/vfs.h Fri Jan 12 17:54:52 2018 +0100 +++ b/src/server/daemon/vfs.h Fri Jan 12 18:12:42 2018 +0100 @@ -66,6 +66,8 @@ ssize_t sys_file_read(SYS_FILE fd, void *buf, size_t nbyte); ssize_t sys_file_write(SYS_FILE fd, const void *buf, size_t nbyte); +ssize_t sys_file_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset); +ssize_t sys_file_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset); off_t sys_file_seek(SYS_FILE fd, off_t offset, int whence); void sys_file_close(SYS_FILE fd); int sys_file_aioread(aiocb_s *aiocb);
--- a/src/server/public/nsapi.h Fri Jan 12 17:54:52 2018 +0100 +++ b/src/server/public/nsapi.h Fri Jan 12 18:12:42 2018 +0100 @@ -1538,6 +1538,8 @@ /* file */ NSAPI_PUBLIC int system_fread(SYS_FILE fd, void *buf, int nbyte); NSAPI_PUBLIC int system_fwrite(SYS_FILE fd, const void *buf, int nbyte); +NSAPI_PUBLIC int system_pread(SYS_FILE fd, void *buf, int nbyte, off_t offset); +NSAPI_PUBLIC int system_pwrite(SYS_FILE fd, const void *buf, int nbyte, off_t offset); NSAPI_PUBLIC off_t system_lseek(SYS_FILE fd, off_t offset, int whence); NSAPI_PUBLIC int system_fclose(SYS_FILE fd);
--- a/src/server/public/vfs.h Fri Jan 12 17:54:52 2018 +0100 +++ b/src/server/public/vfs.h Fri Jan 12 18:12:42 2018 +0100 @@ -92,6 +92,8 @@ struct VFS_IO { ssize_t (*read)(SYS_FILE fd, void *buf, size_t nbyte); ssize_t (*write)(SYS_FILE fd, const void *buf, size_t nbyte); + ssize_t (*pread)(SYS_FILE fd, void *buf, size_t nbyte, off_t offset); + ssize_t (*pwrite)(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset); off_t (*seek)(SYS_FILE fd, off_t offset, int whence); void (*close)(SYS_FILE fd); int (*opt_aioread)(aiocb_s *aiocb);