bug-hurd
[Top][All Lists]
Advanced

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

[PATCH (long)] hello.c follow-up


From: PUYDT Julien
Subject: [PATCH (long)] hello.c follow-up
Date: 18 Jul 2003 18:11:30 +0200

Hi,

this long patch is supposed to make hello.c correct and "robust"... it
includes the previously posted patch.

Notice that in storeio, trivfs_S_io_seek uses open_seek, which doesn't
check the offset sanity either; I'll take a look at it when I'll have
understood things a little more.

Here is a ChangeLog entry-like summary of the changes:

2003-07-18  Julien PUYDT <julien.puydt@laposte.net>

* hello.c
        (): cut some comments, obsoleted by the addition of functions
        (trivfs_modify_stat): struct stat -> io_statbuf_t
        (trivfs_S_io_seek): off_t -> loff_t, and check for offset sanity
        (trivfs_S_io_get_openmodes,
        trivfs_S_io_clear_some_openmodes,
        trivfs_S_io_set_some_openmodes,
        trivfs_S_io_set_all_openmodes,
        trivfs_S_io_readable,
        trivfs_S_io_select): added, to comply with asserts in libtrivfs

of course, advices and comments are welcome,

Snark on #hurd, #hurdfr

PS: the patch:
--- hello.c.orig        2003-07-18 16:47:59.000000000 +0200
+++ hello.c.nouv        2003-07-18 16:47:47.000000000 +0200
@@ -46,24 +46,6 @@
 int trivfs_support_write = 0;
 int trivfs_support_exec = 0;
 
-/* NOTE: This example is not robust: it is possible to trigger some
-   assertion failures because we don't implement the following:
-
-   $ cd /src/hurd/libtrivfs
-   $ grep -l 'assert.*!trivfs_support_read' *.c |
-     xargs grep '^trivfs_S_' | sed 's/^[^:]*:\([^      ]*\).*$/\1/'
-   trivfs_S_io_get_openmodes
-   trivfs_S_io_clear_some_openmodes
-   trivfs_S_io_set_some_openmodes
-   trivfs_S_io_set_all_openmodes
-   trivfs_S_io_readable
-   trivfs_S_io_select
-   $
-
-   For that reason, you should run this as an active translator
-   `settrans -ac testnode /path/to/thello' so that you can see the
-   error messages when they appear. */
-
 /* A hook for us to keep track of the file descriptor state. */
 struct open
 {
@@ -71,7 +53,7 @@
 };
 
 void
-trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
+trivfs_modify_stat (struct trivfs_protid *cred, io_statbuf_t *st)
 {
   /* Mark the node as a read-only plain file. */
   st->st_mode &= ~(S_IFMT | ALLPERMS);
@@ -161,10 +143,12 @@
 error_t
 trivfs_S_io_seek (struct trivfs_protid *cred,
                  mach_port_t reply, mach_msg_type_name_t reply_type,
-                 off_t offs, int whence, off_t *new_offs)
+                 loff_t offs, int whence, loff_t *new_offs)
 {
   struct open *op;
+  loff_t tmp_offs;
   error_t err = 0;
+
   if (! cred)
     return EOPNOTSUPP;
 
@@ -172,17 +156,23 @@
   switch (whence)
     {
     case SEEK_SET:
-      op->offs = offs; break;
+      tmp_offs = offs; break;
     case SEEK_CUR:
-      op->offs += offs; break;
+      tmp_offs = op->offs+offs; break;
     case SEEK_END:
-      op->offs = contents_len - offs; break;
+      tmp_offs = contents_len - offs; break;
     default:
       err = EINVAL;
     }
+  
+  if (tmp_offs < 0)
+    err = EINVAL;
 
   if (! err)
-    *new_offs = op->offs;
+    {
+      op->offs = tmp_offs;
+      *new_offs = op->offs;
+    }
 
   return err;
 }
@@ -286,3 +276,84 @@
 
   return 0;
 }
+
+kern_return_t
+trivfs_S_io_get_openmodes (struct trivfs_protid *cred,
+                           mach_port_t reply,
+                           mach_msg_type_name_t replytype,
+                           int *bits)
+{
+  if (!cred)
+    return EOPNOTSUPP;
+  else
+    {
+      *bits = cred->po->openmodes;
+      return 0;
+    }
+}
+
+kern_return_t
+trivfs_S_io_clear_some_openmodes (struct trivfs_protid *cred,
+                                  mach_port_t reply,
+                                  mach_msg_type_name_t replytype,
+                                  int bits)
+{ 
+  return EOPNOTSUPP;
+}
+
+kern_return_t
+trivfs_S_io_set_some_openmodes (struct trivfs_protid *cred,
+                                mach_port_t reply,
+                                mach_msg_type_name_t replytype,
+                                int bits)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+trivfs_S_io_set_all_openmodes (struct trivfs_protid *cred,
+                               mach_port_t reply,
+                               mach_msg_type_name_t replytype,
+                               int mode)
+{
+  return EOPNOTSUPP;
+}
+
+kern_return_t
+trivfs_S_io_readable (struct trivfs_protid *cred,
+                      mach_port_t reply,
+                      mach_msg_type_name_t replytype,
+                      mach_msg_type_number_t *amount)
+{
+  struct open *op;
+
+  if (!cred)
+    return EOPNOTSUPP;
+ 
+  if(! (cred->po->openmodes & O_READ))
+    return EINVAL;
+
+  op=cred->po->hook; 
+  *amount=contents_len - op->offs;
+
+  return 0;
+
+}
+
+kern_return_t
+trivfs_S_io_select (struct trivfs_protid *cred,
+                    mach_port_t reply,
+                    mach_msg_type_name_t replytype,
+                    int *seltype)
+{
+  if (!cred)
+    return EOPNOTSUPP;
+
+  if ((*seltype & SELECT_READ) && !(cred->po->openmodes & O_READ))
+    return EBADF;
+  
+  *seltype &= ~SELECT_URG;
+  *seltype &= ~SELECT_WRITE;
+  
+  return 0;
+}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]