[freenos] [freenos commit] r203 - libposix S_* values now uses FileType.h/FileMode.h definitions.

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Tue, 07 Jul 2009 09:24:36 +0000

Author: nieklinnenbank
Date: Tue Jul  7 02:24:01 2009
New Revision: 203

Modified:
   trunk/lib/libposix/sys/stat.h
   trunk/srv/filesystem/FileMode.h
   trunk/srv/filesystem/FileStat.h
   trunk/srv/filesystem/FileType.h
   trunk/srv/filesystem/ext2/Ext2Inode.h

Log:
libposix S_* values now uses FileType.h/FileMode.h definitions.
The libposix library uses these values to define e.g. S_IFREG.
Macros FILE{MODE|TYPE}_BITS have been added to FileType.h/FileMode.h,
and specify how many bits are used. FILE{MODE|TYPE}_MASK may be used
as an masker value. Additionally, setuid/setgid macros have been removed
from libposix.


Modified: trunk/lib/libposix/sys/stat.h
==============================================================================
--- trunk/lib/libposix/sys/stat.h       (original)
+++ trunk/lib/libposix/sys/stat.h       Tue Jul  7 02:24:01 2009
@@ -18,7 +18,9 @@
 #ifndef __LIBPOSIX_STAT_H
 #define __LIBPOSIX_STAT_H

-#include <FileSystemMessage.h>
+#include <FileType.h>
+#include <FileMode.h>
+#include <FileStat.h>
 #include <Macros.h>
 #include <Error.h>
 #include "types.h"
@@ -40,28 +42,28 @@
  */

 /** Type of file. */
-#define S_IFMT  0170000
+#define S_IFMT  (FILETYPE_MASK << FILEMODE_BITS)

 /** Block special. */
-#define S_IFBLK         0060000
+#define S_IFBLK         (BlockDeviceFile << FILEMODE_BITS)

 /** Character special. */
-#define S_IFCHR  0020000
+#define S_IFCHR  (CharacterDeviceFile << FILEMODE_BITS)

 /** FIFO special. */
-#define S_IFIFO         0010000
+#define S_IFIFO         (FIFOFile << FILEMODE_BITS)

 /** Regular. */
-#define S_IFREG         0100000
+#define S_IFREG         (RegularFile << FILEMODE_BITS)

 /** Directory. */
-#define S_IFDIR         0040000
+#define S_IFDIR         (DirectoryFile << FILEMODE_BITS)

 /** Symbolic link. */
-#define S_IFLNK         0120000
+#define S_IFLNK         (SymlinkFile << FILEMODE_BITS)

 /** Socket. */
-#define S_IFSOCK 0140000
+#define S_IFSOCK (SocketFile << FILEMODE_BITS)

 /** @} */

@@ -79,46 +81,40 @@
  */

 /** Read, write, execute/search by owner. */
-#define S_IRWXU         0700
+#define S_IRWXU         OwnerRWX

 /** Read permission, owner. */
-#define S_IRUSR  0400
+#define S_IRUSR  OwnerR

 /** Write permission, owner. */
-#define S_IWUSR  0200
+#define S_IWUSR  OwnerW

 /** Execute/search permission, owner. */
-#define S_IXUSR  0100
+#define S_IXUSR  OwnerX

 /** Read, write, execute/search by group. */
-#define S_IRWXG  0070
+#define S_IRWXG  GroupRWX

 /** Read permission, group. */
-#define S_IRGRP  0040
+#define S_IRGRP  GroupR

 /** Write permission, group. */
-#define S_IWGRP  0020
+#define S_IWGRP  GroupW

 /** Execute/search permission, group. */
-#define S_IXGRP  0010
+#define S_IXGRP  GroupX

 /** Read, write, execute/search by others. */
-#define S_IRWXO  0007
+#define S_IRWXO  OtherRWX

 /** Read permission, others. */
-#define S_IROTH  0004
+#define S_IROTH  OtherR

 /** Write permission, others. */
-#define S_IWOTH  0002
+#define S_IWOTH  OtherW

 /** Execute/search permission, others. */
-#define S_IXOTH  0001
-
-/** Set-user-ID on execution. */
-#define S_ISUID  04000
-
-/** Set-group-ID on execution. */
-#define S_ISGID  02000
+#define S_IXOTH  OtherX

 /** @} */

@@ -172,17 +168,7 @@
      */
     void fromFileStat(FileStat *stat)
     {
-       mode_t modes[] =
-        {
-           S_IFREG,
-           S_IFDIR,
-           S_IFBLK,
-           S_IFCHR,
-           S_IFLNK,
-           S_IFIFO,
-           S_IFSOCK,
-       };
-       this->st_mode = modes[stat->type];
+       this->st_mode = stat->type << FILEMODE_BITS;
         this->st_size = stat->size;
         this->st_uid  = stat->userID;
         this->st_gid  = stat->groupID;

Modified: trunk/srv/filesystem/FileMode.h
==============================================================================
--- trunk/srv/filesystem/FileMode.h     (original)
+++ trunk/srv/filesystem/FileMode.h     Tue Jul  7 02:24:01 2009
@@ -18,6 +18,14 @@
 #ifndef __FILESYSTEM_FILEMODE_H
 #define __FILESYSTEM_FILEMODE_H

+#include <Types.h>
+
+/** Number of bits required for all FileModes. */
+#define FILEMODE_BITS 9
+
+/** Masker value for all FileMode values. */
+#define FILEMODE_MASK 0777
+
 /**
  * File access permissions.
  */
@@ -43,5 +51,8 @@
     OtherRWX = 0007,
 }
 FileMode;
+
+/** Multiple FileMode values combined. */
+typedef u16 FileModes;

 #endif /* __FILESYSTEM_FILEMODE_H */

Modified: trunk/srv/filesystem/FileStat.h
==============================================================================
--- trunk/srv/filesystem/FileStat.h     (original)
+++ trunk/srv/filesystem/FileStat.h     Tue Jul  7 02:24:01 2009
@@ -29,6 +29,9 @@
     /** File type. */
     FileType type;

+    /** File access permission bits. */
+    FileMode access;
+
     /** Size of the file in bytes. */
     Size size;


Modified: trunk/srv/filesystem/FileType.h
==============================================================================
--- trunk/srv/filesystem/FileType.h     (original)
+++ trunk/srv/filesystem/FileType.h     Tue Jul  7 02:24:01 2009
@@ -18,6 +18,12 @@
 #ifndef __FILESYSTEM_FILETYPE_H
 #define __FILESYSTEM_FILETYPE_H

+/** Number of bits needed to store a FileType. */
+#define FILETYPE_BITS  3
+
+/** Masker value for all FileTypes. */
+#define FILETYPE_MASK  7
+
 /**
  * All possible filetypes.
  */

Modified: trunk/srv/filesystem/ext2/Ext2Inode.h
==============================================================================
--- trunk/srv/filesystem/ext2/Ext2Inode.h       (original)
+++ trunk/srv/filesystem/ext2/Ext2Inode.h       Tue Jul  7 02:24:01 2009
@@ -35,7 +35,6 @@

 #ifndef __HOST__
 #include <FileSystemMessage.h>
-#include <sys/stat.h>
 #endif /* __HOST__ */

 /**
@@ -157,7 +156,7 @@
            UnknownFile, \
            SocketFile, \
        }; \
-       types[((i)->mode & S_IFMT) >> 12]; \
+       types[((i)->mode & 0170000) >> 12]; \
     })

 /**

Other related posts:

  • » [freenos] [freenos commit] r203 - libposix S_* values now uses FileType.h/FileMode.h definitions. - codesite-noreply