[freenos] r303 committed - ReadFile and WriteFile now return the number of bytes in FileSystemMes...

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Fri, 07 Aug 2009 22:34:35 +0000

Revision: 303
Author: nieklinnenbank
Date: Fri Aug  7 15:34:17 2009
Log: ReadFile and WriteFile now return the number of bytes in FileSystemMessage::result.
On error, the result field still contains the error code. This change makes
the implementation of the FileSystem and DeviceServer simpler.

http://code.google.com/p/freenos/source/detail?r=303

Modified:
 /trunk/lib/libposix/unistd/read.cpp
 /trunk/lib/libposix/unistd/write.cpp
 /trunk/srv/DeviceServer.h
 /trunk/srv/filesystem/FileSystem.h

=======================================
--- /trunk/lib/libposix/unistd/read.cpp Sun Aug  2 04:34:12 2009
+++ /trunk/lib/libposix/unistd/read.cpp Fri Aug  7 15:34:17 2009
@@ -44,5 +44,5 @@
        errno = ENOENT;

     /* Success. */
-    return errno == ESUCCESS ? msg.size : (ssize_t) -1;
-}
+    return errno >= 0 ? errno : (ssize_t) -1;
+}
=======================================
--- /trunk/lib/libposix/unistd/write.cpp        Sun Aug  2 04:34:12 2009
+++ /trunk/lib/libposix/unistd/write.cpp        Fri Aug  7 15:34:17 2009
@@ -44,5 +44,5 @@
        errno = ENOENT;

     /* Give the result back. */
-    return errno == ESUCCESS ? msg.size : (ssize_t) -1;
-}
+    return errno >= 0 ? errno : (ssize_t) -1;
+}
=======================================
--- /trunk/srv/DeviceServer.h   Mon Aug  3 14:28:50 2009
+++ /trunk/srv/DeviceServer.h   Fri Aug  7 15:34:17 2009
@@ -347,7 +347,6 @@
         */
        bool performRead(FileSystemMessage *msg)
        {
-           Error result;
            Device *dev = devices[msg->deviceID.minor];

            /* Allocate a temporary buffer. */
@@ -357,30 +356,17 @@
             * Perform the read operation using the underlying
             * read() implementation of the Device.
             */
-           result = dev->read(buffer, msg->size, msg->offset);
-
-           /* Did it complete successfully? */
-           if (result >= 0)
-           {
-               msg->result = ESUCCESS;
-               msg->size   = result;
-
+           if ((msg->result = dev->read(buffer, msg->size, msg->offset)) >= 0)
+           {
                /* Write the result into the process' buffer. */
-               if (VMCopy(msg->from, Write, (Address) buffer,
-                                            (Address) msg->buffer, msg->size) 
< 0)
-               {
-                   msg->result = EFAULT;
-               }
-           }
-           else
-           {
-               /* Take care that we may need to try again. */
-               msg->result = result;
+               msg->result = VMCopy(msg->from, Write, (Address) buffer,
+                                   (Address) msg->buffer, msg->result);
            }
            /* Update FileDescriptor and send a reply if processed. */
            if (msg->result != EAGAIN)
            {
-               getFileDescriptor(files, msg->from, msg->fd)->position += 
msg->size;
+               if (msg->result > 0)
+ getFileDescriptor(files, msg->from, msg->fd)->position += msg->result;
                msg->ipc(msg->from, Send, sizeof(*msg));
            }
            /* Release memory. And return. */
@@ -396,42 +382,26 @@
         */
        bool performWrite(FileSystemMessage *msg)
        {
-           Error result;
            Device *dev = devices[msg->deviceID.minor];

            /* Allocate a temporary buffer. */
            s8 *buffer = new s8[msg->size];

            /* Obtain input bytes from the process' buffer. */
-           if (VMCopy(msg->from, Read, (Address) buffer,
-                                       (Address) msg->buffer, msg->size) < 0)
-           {
-               msg->result = EFAULT;
-           }
-           else
-           {
+           if ((msg->result = VMCopy(msg->from, Read, (Address) buffer,
+                                    (Address) msg->buffer, msg->size)) >= 0)
+           {
                /*
                 * Perform the write operation using the underlying
                 * write() implementation of the Device.
                 */
-               result = dev->write(buffer, msg->size, msg->offset);
-
-               /* Did it complete successfully? */
-               if (result >= 0)
-               {
-                   msg->result = ESUCCESS;
-                   msg->size   = result;
-               }
-               /* Take care that we may need to try again. */
-               else
-               {
-                   msg->result = result;
-               }
+               msg->result = dev->write(buffer, msg->size, msg->offset);
            }
            /* Send a reply if processed. */
            if (msg->result != EAGAIN)
            {
-               getFileDescriptor(files, msg->from, msg->fd)->position += 
msg->size;
+               if (msg->result > 0)
+ getFileDescriptor(files, msg->from, msg->fd)->position += msg->result;
                msg->ipc(msg->from, Send, sizeof(*msg));
            }
            /* Release memory. And return. */
=======================================
--- /trunk/srv/filesystem/FileSystem.h  Fri Aug  7 05:42:20 2009
+++ /trunk/srv/filesystem/FileSystem.h  Fri Aug  7 15:34:17 2009
@@ -284,9 +284,7 @@

                    if ((msg->result = file->read(&io, msg->size, fd->position)) 
>= 0)
                    {
-                        fd->position += msg->result;
-                        msg->size = msg->result;
-                        msg->result = ESUCCESS;
+                       fd->position += msg->result;
                    }
                    break;

@@ -295,8 +293,6 @@
                    if ((msg->result = file->write(&io, msg->size, fd->position)) 
>= 0)
                    {
                        fd->position += msg->result;
-                       msg->size = msg->result;
-                       msg->result = ESUCCESS;
                    }
                    break;


Other related posts:

  • » [freenos] r303 committed - ReadFile and WriteFile now return the number of bytes in FileSystemMes... - codesite-noreply