adds vfs pread/pwrite functions aio

Fri, 12 Jan 2018 18:12:42 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 12 Jan 2018 18:12:42 +0100
branch
aio
changeset 189
a2438f6d1e73
parent 188
0e6a05c779e0
child 190
1f73302461e0

adds vfs pread/pwrite functions

src/server/daemon/vfs.c file | annotate | diff | comparison | revisions
src/server/daemon/vfs.h file | annotate | diff | comparison | revisions
src/server/public/nsapi.h file | annotate | diff | comparison | revisions
src/server/public/vfs.h file | annotate | diff | comparison | revisions
src/server/safs/service.c file | annotate | diff | comparison | revisions
--- 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);
--- a/src/server/safs/service.c	Fri Jan 12 17:54:52 2018 +0100
+++ b/src/server/safs/service.c	Fri Jan 12 18:12:42 2018 +0100
@@ -644,7 +644,7 @@
         if(send_range(sn, fd, offset, length, NULL, 0)) {
             // TODO: error
         }
-*/
+//*/
     } else {
         if(send_multi_range(sn, rq, fd, s.st_size, range)) {
             // TODO: error

mercurial