The devices report their stat in 9p's format.  This meant nothing to the
POSIX/glibc world.  Now we have access to those bits (in a different
location in the mode) in usermode.

Reinstall your kernel headers.

Signed-off-by: Barret Rhoden <[email protected]>
---
 kern/include/ros/fs.h       | 40 +++++++++++++++++++++++++---------------
 kern/src/ns/convM2kdirent.c | 29 +++++++++++++++++++----------
 2 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/kern/include/ros/fs.h b/kern/include/ros/fs.h
index 1f0b1df9384c..8088c1c397f4 100644
--- a/kern/include/ros/fs.h
+++ b/kern/include/ros/fs.h
@@ -104,23 +104,24 @@ struct kstat {
 #define S_PMASK 00777  /* mask for all perms */
 
 /* File type is encoded in the file mode */
-#define __S_IFMT       0170000 /* These bits determine file type */
+#define __S_IFMT               000170000       /* These bits determine file 
type */
 /* File types */
-#define __S_IFDIR      0040000 /* Directory */
-#define __S_IFCHR      0020000 /* Character device */
-#define __S_IFBLK      0060000 /* Block device */
-#define __S_IFREG      0100000 /* Regular file */
-#define __S_IFIFO      0010000 /* FIFO */
-#define __S_IFLNK      0120000 /* Symbolic link */
-#define __S_IFSOCK     0140000 /* Socket */
+#define __S_IFDIR              000040000       /* Directory */
+#define __S_IFCHR              000020000       /* Character device */
+#define __S_IFBLK              000060000       /* Block device */
+#define __S_IFREG              000100000       /* Regular file */
+#define __S_IFIFO              000010000       /* FIFO */
+#define __S_IFLNK              000120000       /* Symbolic link */
+#define __S_IFSOCK             000140000       /* Socket */
 /* Protection bits */
-#define __S_ISUID      04000   /* Set user ID on execution */
-#define __S_ISGID      02000   /* Set group ID on execution */
-#define __S_ISVTX      01000   /* Save swapped text after use (sticky) */
-#define __S_IREAD      0400    /* Read by owner */
-#define __S_IWRITE     0200    /* Write by owner */
-#define __S_IEXEC      0100    /* Execute by owner */
-/* Test macros for file types. */
+#define __S_ISUID              000004000       /* Set user ID on execution */
+#define __S_ISGID              000002000       /* Set group ID on execution */
+#define __S_ISVTX              000001000       /* Save swapped text after use 
(sticky) */
+#define __S_IREAD              000000400       /* Read by owner */
+#define __S_IWRITE             000000200       /* Write by owner */
+#define __S_IEXEC              000000100       /* Execute by owner */
+
+/* Test macros for file types */
 #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
 #define S_ISDIR(mode)  __S_ISTYPE((mode), __S_IFDIR)
 #define S_ISCHR(mode)  __S_ISTYPE((mode), __S_IFCHR)
@@ -130,3 +131,12 @@ struct kstat {
 #define S_ISLNK(mode)  __S_ISTYPE((mode), __S_IFLNK)
 
 #endif /* ROS_KERNEL */
+
+/* Non-standard bits */
+#define __S_NONSTD             077000000       /* Magic Akaros bits */
+#define __S_READABLE   001000000       /* File is readable */
+#define __S_WRITABLE   002000000       /* File is writable */
+
+/* Test macros for non-standard bits */
+#define S_READABLE(mode)       (((mode) & __S_READABLE) != 0)
+#define S_WRITABLE(mode)       (((mode) & __S_WRITABLE) != 0)
diff --git a/kern/src/ns/convM2kdirent.c b/kern/src/ns/convM2kdirent.c
index bd3d2b15a619..4475b9e6a6a6 100644
--- a/kern/src/ns/convM2kdirent.c
+++ b/kern/src/ns/convM2kdirent.c
@@ -96,6 +96,24 @@ unsigned int convM2kdirent(uint8_t * buf, unsigned int nbuf, 
struct kdirent *kd,
        return p - buf;
 }
 
+static int mode_9ns_to_posix(int mode_9ns)
+{
+       int mode_posix = 0;
+
+       if (mode_9ns & DMDIR)
+               mode_posix |= __S_IFDIR;
+       else if (mode_9ns & DMSYMLINK)
+               mode_posix |= __S_IFLNK;
+       else
+               mode_posix |= __S_IFREG;
+       if (mode_9ns & DMREADABLE)
+               mode_posix |= __S_READABLE;
+       if (mode_9ns & DMWRITABLE)
+               mode_posix |= __S_WRITABLE;
+       mode_posix |= mode_9ns & 0777;
+       return mode_posix;
+}
+
 unsigned int convM2kstat(uint8_t * buf, unsigned int nbuf, struct kstat *ks)
 {
        uint8_t *p, *ebuf;
@@ -120,16 +138,7 @@ unsigned int convM2kstat(uint8_t * buf, unsigned int nbuf, 
struct kstat *ks)
        p += BIT32SZ;
        ks->st_ino = GBIT64(p);
        p += BIT64SZ;
-       ks->st_mode = GBIT32(p);
-       if (ks->st_mode & DMDIR) {
-               ks->st_mode &= ~DMDIR;
-               ks->st_mode |= __S_IFDIR;
-       } else if (ks->st_mode & DMSYMLINK) {
-               ks->st_mode &= ~DMSYMLINK;
-               ks->st_mode |= __S_IFLNK;
-       } else {
-               ks->st_mode |= __S_IFREG;
-       }
+       ks->st_mode = mode_9ns_to_posix(GBIT32(p));
        p += BIT32SZ;
        ks->st_atim.tv_sec = GBIT32(p);
        p += BIT32SZ;
-- 
2.8.0.rc3.226.g39d4020

-- 
You received this message because you are subscribed to the Google Groups 
"Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to