[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 2/5] lib/vfscore: handle uio properly in stdio functions



Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 lib/vfscore/stdio.c | 59 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 45 insertions(+), 14 deletions(-)

diff --git a/lib/vfscore/stdio.c b/lib/vfscore/stdio.c
index b73b132c..8e3ccbdb 100644
--- a/lib/vfscore/stdio.c
+++ b/lib/vfscore/stdio.c
@@ -40,31 +40,41 @@
 #include <termios.h>
 #include <vfscore/vnode.h>
 #include <unistd.h>
+#include <vfscore/uio.h>
+
+static int __coutk_wrapper(void *dst __unused, void *src, size_t *cnt)
+{
+       int ret = ukplat_coutk(src, *cnt);
+
+       if (ret < 0)
+               /* TODO: remove -1 when vfscore switches to negative
+                * error numbers
+                */
+               return ret * -1;
+
+       *cnt = (size_t) ret;
+       return 0;
+}
 
 /* One function for stderr and stdout */
 static ssize_t stdio_write(struct vnode *vp __unused,
                           struct uio *uio,
                           int ioflag __unused)
 {
-       UK_ASSERT(!uio->uio_offset);
-       UK_ASSERT(uio->uio_iovcnt == 1);
-       return ukplat_coutk(uio->uio_iov->iov_base, uio->uio_iov->iov_len);
+       if (uio->uio_offset)
+               return ESPIPE;
+
+       return vfscore_uioforeach(__coutk_wrapper, NULL, uio->uio_resid, uio);
 }
 
-static ssize_t stdio_read(struct vnode *vp __unused,
-                     struct vfscore_file *file __unused,
-                     struct uio *uio,
-                     int ioflag __unused)
+
+static int __read_fn(void *dst, void *src __unused, size_t *cnt)
 {
        int bytes_read;
        size_t bytes_total = 0, count;
-       char *buf;
-
-       UK_ASSERT(!uio->uio_offset);
-       UK_ASSERT(uio->uio_iovcnt == 1);
+       char *buf = dst;
 
-       buf = uio->uio_iov->iov_base;
-       count = uio->uio_iov->iov_len;
+       count = *cnt;
 
        do {
                while ((bytes_read = ukplat_cink(buf,
@@ -82,7 +92,28 @@ static ssize_t stdio_read(struct vnode *vp __unused,
        } while (bytes_total < count && *(buf - 1) != '\n'
                        && *(buf - 1) != VEOF);
 
-       return bytes_total;
+       *cnt = bytes_total;
+
+       if (*(buf - 1) == '\n' || *(buf - 1) == VEOF)
+               return INT_MIN;
+
+       return 0;
+}
+
+static ssize_t stdio_read(struct vnode *vp __unused,
+                     struct vfscore_file *file __unused,
+                     struct uio *uio,
+                     int ioflag __unused)
+{
+       int ret;
+
+       if (uio->uio_offset)
+               return ESPIPE;
+
+       ret = vfscore_uioforeach(__read_fn, NULL, uio->uio_resid, uio);
+       ret = (ret == INT_MIN) ? 0 : ret;
+
+       return ret;
 }
 
 static int
-- 
2.19.2


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.