akaros/kern/include/ros/fs.h
<<
>>
Prefs
   1#pragma once
   2
   3#include <sys/types.h>
   4#include <ros/limits.h>
   5#include <ros/time.h>
   6
   7/* This will change once we have a decent readdir / getdents syscall, and
   8 * send the strlen along with the d_name.  The sizes need rechecked too, since
   9 * they are probably wrong. */
  10struct kdirent {
  11        __ino64_t               d_ino;          /* inode number */
  12        __off64_t               d_off;          /* offset to the next dirent */
  13        unsigned short          d_reclen;       /* length of this record */
  14        unsigned char           d_type;
  15        char                    d_name[MAX_FILENAME_SZ + 1];    /* filename */
  16} __attribute__((aligned(8)));
  17
  18/* These stat sizes should match the types in stat.h and types.h and the sizes
  19 * in typesizes in glibc (which we modified slightly).  While glibc has it's own
  20 * stat, we have this here so that the kernel is exporting the interface it
  21 * expects.  We #def stat for our own internal use at the end. */
  22struct kstat {
  23        __dev_t                 st_dev;         /* Device.  */
  24        __ino64_t               st_ino;         /* File serial number.  */
  25        __mode_t                st_mode;        /* File mode.  */
  26        __nlink_t               st_nlink;       /* Link count.  */
  27        __uid_t                 st_uid;         /* User ID of the file owner */
  28        __gid_t                 st_gid;         /* Group ID of the file group */
  29        __dev_t                 st_rdev;        /* Device number, if device.  */
  30        __off64_t               st_size;        /* Size of file, in bytes.  */
  31        __blksize_t             st_blksize;     /* Optimal block size for I/O */
  32        __blkcnt64_t            st_blocks;      /* Nr 512-byte blocks allocd. */
  33        struct timespec         st_atim;        /* Time of last access.  */
  34        struct timespec         st_mtim;        /* Time of last modification */
  35        struct timespec         st_ctim;        /* Time of last status change */
  36};
  37
  38/* File access modes for open and fcntl. */
  39#define O_READ                  0x01            /* Open for reading */
  40#define O_WRITE                 0x02            /* Open for writing */
  41#define O_EXEC                  0x04            /* Open for exec */
  42#define O_RDONLY                O_READ          /* Open read-only */
  43#define O_WRONLY                O_WRITE         /* Open write-only */
  44#define O_RDWR                  (O_READ | O_WRITE)      /* Open read/write */
  45#define O_ACCMODE               0x07
  46
  47/* Bits OR'd into the second argument to open */
  48#define O_CREAT                 00000100        /* not fcntl */
  49#define O_CREATE                O_CREAT 
  50#define O_EXCL                  00000200        /* not fcntl */
  51#define O_NOCTTY                00000400        /* not fcntl */
  52#define O_TRUNC                 00001000        /* not fcntl */
  53#define O_APPEND                00002000
  54#define O_NONBLOCK              00004000
  55#define O_SYNC                  00010000
  56#define O_FSYNC                 O_SYNC
  57#define O_ASYNC                 00020000
  58#define O_DIRECT                00040000        /* Direct disk access. */
  59#define O_PATH                  00100000        /* Path only, no I/O */
  60#define O_DIRECTORY             00200000        /* Must be a directory. */
  61#define O_NOFOLLOW              00400000        /* Do not follow links. */
  62#define O_NOATIME               01000000        /* Do not set atime. */
  63#define O_CLOEXEC               02000000        /* Set close_on_exec. */
  64#define O_REMCLO                04000000        /* Remove on close. */
  65
  66/* Keep this value in sync with glibc (io/fcntl.h) */
  67#define AT_FDCWD                -100
  68
  69#define F_DUPFD                 0       /* Duplicate file descriptor */
  70#define F_GETFD                 1       /* Get file descriptor flags */
  71#define F_SETFD                 2       /* Set file descriptor flags */
  72#define F_GETFL                 3       /* Get file status flags */
  73#define F_SETFL                 4       /* Set file status flags */
  74#define F_SYNC                  101     /* fsync() */
  75#define F_ADVISE                102     /* posix_fadvise{,64}() */
  76#define F_CHANCTL_BASE          1000
  77
  78/* We don't need a GET_FL.  The caller has the chan / FID.  If you have the
  79 * chan, you already have the flags.  It's not like when you have an FD and
  80 * don't (yet) have the Unix struct file. */
  81#define CCTL_SET_FL             (F_CHANCTL_BASE + 0)
  82#define CCTL_SYNC               (F_CHANCTL_BASE + 1)
  83#define CCTL_DEBUG              (F_CHANCTL_BASE + 2)
  84
  85/* For F_[GET|SET]FD */
  86#define FD_CLOEXEC              1
  87#define FD_VALID_FLAGS (FD_CLOEXEC)
  88
  89/* Advise to `posix_fadvise'.  */
  90#define POSIX_FADV_NORMAL       0       /* No further special treatment */
  91#define POSIX_FADV_RANDOM       1       /* Expect random page references */
  92#define POSIX_FADV_SEQUENTIAL   2       /* Expect sequential page references */
  93#define POSIX_FADV_WILLNEED     3       /* Will need these pages */
  94#define POSIX_FADV_DONTNEED     4       /* Don't need these pages */
  95#define POSIX_FADV_NOREUSE      5       /* Data will be accessed once */
  96
  97/* TODO: have userpsace use our stuff from bits/stats.h */
  98#ifdef ROS_KERNEL
  99
 100/* Access mode bits (unistd.h) */
 101#define R_OK 4
 102#define W_OK 2
 103#define X_OK 1
 104#define F_OK 0
 105
 106/* File creation modes (access controls) */
 107#define S_IRWXU 00700   /* user (file owner) has read, write and execute perms */
 108#define S_IRUSR 00400   /* user has read permission */
 109#define S_IWUSR 00200   /* user has write permission */
 110#define S_IXUSR 00100   /* user has execute permission */
 111#define S_IRWXG 00070   /* group has read, write and execute permission */
 112#define S_IRGRP 00040   /* group has read permission */
 113#define S_IWGRP 00020   /* group has write permission */
 114#define S_IXGRP 00010   /* group has execute permission */
 115#define S_IRWXO 00007   /* others have read, write and execute permission */
 116#define S_IROTH 00004   /* others have read permission */
 117#define S_IWOTH 00002   /* others have write permission */
 118#define S_IXOTH 00001   /* others have execute permission */
 119#define S_PMASK 00777   /* mask for all perms */
 120
 121/* File type is encoded in the file mode */
 122#define __S_IFMT                000170000       /* These bits determine file type */
 123/* File types */
 124#define __S_IFDIR               000040000       /* Directory */
 125#define __S_IFCHR               000020000       /* Character device */
 126#define __S_IFBLK               000060000       /* Block device */
 127#define __S_IFREG               000100000       /* Regular file */
 128#define __S_IFIFO               000010000       /* FIFO */
 129#define __S_IFLNK               000120000       /* Symbolic link */
 130#define __S_IFSOCK              000140000       /* Socket */
 131/* Protection bits */
 132#define __S_ISUID               000004000       /* Set user ID on execution */
 133#define __S_ISGID               000002000       /* Set group ID on execution */
 134#define __S_ISVTX               000001000       /* Save swapped text after use (sticky) */
 135#define __S_IREAD               000000400       /* Read by owner */
 136#define __S_IWRITE              000000200       /* Write by owner */
 137#define __S_IEXEC               000000100       /* Execute by owner */
 138
 139/* Test macros for file types */
 140#define __S_ISTYPE(mode, mask)  (((mode) & __S_IFMT) == (mask))
 141#define S_ISDIR(mode)   __S_ISTYPE((mode), __S_IFDIR)
 142#define S_ISCHR(mode)   __S_ISTYPE((mode), __S_IFCHR)
 143#define S_ISBLK(mode)   __S_ISTYPE((mode), __S_IFBLK)
 144#define S_ISREG(mode)   __S_ISTYPE((mode), __S_IFREG)
 145#define S_ISFIFO(mode)  __S_ISTYPE((mode), __S_IFIFO)
 146#define S_ISLNK(mode)   __S_ISTYPE((mode), __S_IFLNK)
 147
 148#endif /* ROS_KERNEL */
 149
 150/* Non-standard bits */
 151#define __S_NONSTD              077000000       /* Magic Akaros bits */
 152#define __S_READABLE            001000000       /* File is readable */
 153#define __S_WRITABLE            002000000       /* File is writable */
 154
 155/* Test macros for non-standard bits */
 156#define S_READABLE(mode)        (((mode) & __S_READABLE) != 0)
 157#define S_WRITABLE(mode)        (((mode) & __S_WRITABLE) != 0)
 158