1 /* 2 * Copyright 2002-2006, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SYS_STAT_H_ 6 #define _SYS_STAT_H_ 7 8 9 #include <sys/types.h> 10 11 12 struct stat { 13 dev_t st_dev; /* "device" that this file resides on */ 14 ino_t st_ino; /* this file's inode #, unique per device */ 15 mode_t st_mode; /* mode bits (rwx for user, group, etc) */ 16 nlink_t st_nlink; /* number of hard links to this file */ 17 uid_t st_uid; /* user id of the owner of this file */ 18 gid_t st_gid; /* group id of the owner of this file */ 19 off_t st_size; /* size in bytes of this file */ 20 dev_t st_rdev; /* device type (not used) */ 21 size_t st_blksize; /* preferred block size for i/o */ 22 time_t st_atime; /* last access time */ 23 time_t st_mtime; /* last modification time */ 24 time_t st_ctime; /* last change time, not creation time */ 25 time_t st_crtime; /* creation time */ 26 27 // Haiku extensions: 28 // TODO: we might also define special types for files and TTYs 29 // TODO: we should find another solution for this, as BStatable::GetStat() 30 // can only retrieve the R5 stat structure 31 unsigned int st_type; /* attribute/index type */ 32 }; 33 34 /* extended file types */ 35 #define S_ATTR_DIR 01000000000 /* attribute directory */ 36 #define S_ATTR 02000000000 /* attribute */ 37 #define S_INDEX_DIR 04000000000 /* index (or index directory) */ 38 #define S_STR_INDEX 00100000000 /* string index */ 39 #define S_INT_INDEX 00200000000 /* int32 index */ 40 #define S_UINT_INDEX 00400000000 /* uint32 index */ 41 #define S_LONG_LONG_INDEX 00010000000 /* int64 index */ 42 #define S_ULONG_LONG_INDEX 00020000000 /* uint64 index */ 43 #define S_FLOAT_INDEX 00040000000 /* float index */ 44 #define S_DOUBLE_INDEX 00001000000 /* double index */ 45 #define S_ALLOW_DUPS 00002000000 /* allow duplicate entries (currently unused) */ 46 47 /* link types */ 48 #define S_LINK_SELF_HEALING 00001000000 /* link will be updated if you move its target */ 49 #define S_LINK_AUTO_DELETE 00002000000 /* link will be deleted if you delete its target */ 50 51 /* standard file types */ 52 #define S_IFMT 00000170000 /* type of file */ 53 #define S_IFLNK 00000120000 /* symbolic link */ 54 #define S_IFREG 00000100000 /* regular */ 55 #define S_IFBLK 00000060000 /* block special */ 56 #define S_IFDIR 00000040000 /* directory */ 57 #define S_IFCHR 00000020000 /* character special */ 58 #define S_IFIFO 00000010000 /* fifo */ 59 60 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 61 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) 62 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 63 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 64 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) 65 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) 66 #define S_ISINDEX(mode) (((mode) & S_INDEX_DIR) == S_INDEX_DIR) 67 68 #define S_IUMSK 07777 /* user settable bits */ 69 70 #define S_ISUID 04000 /* set user id on execution */ 71 #define S_ISGID 02000 /* set group id on execution */ 72 73 #define S_ISVTX 01000 /* save swapped text even after use */ 74 75 #define S_IRWXU 00700 /* read, write, execute: owner */ 76 #define S_IRUSR 00400 /* read permission: owner */ 77 #define S_IWUSR 00200 /* write permission: owner */ 78 #define S_IXUSR 00100 /* execute permission: owner */ 79 #define S_IRWXG 00070 /* read, write, execute: group */ 80 #define S_IRGRP 00040 /* read permission: group */ 81 #define S_IWGRP 00020 /* write permission: group */ 82 #define S_IXGRP 00010 /* execute permission: group */ 83 #define S_IRWXO 00007 /* read, write, execute: other */ 84 #define S_IROTH 00004 /* read permission: other */ 85 #define S_IWOTH 00002 /* write permission: other */ 86 #define S_IXOTH 00001 /* execute permission: other */ 87 88 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) 89 #define ALLPERMS (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO) 90 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) 91 /* default file mode, everyone can read/write */ 92 93 #ifdef __cplusplus 94 extern "C" { 95 #endif 96 97 extern int chmod(const char *path, mode_t mode); 98 extern int fchmod(int fd, mode_t mode); 99 extern int _stat(const char *path, struct stat *st, size_t statSize); 100 extern int _fstat(int fd, struct stat *st, size_t statSize); 101 extern int _lstat(const char *path, struct stat *st, size_t statSize); 102 extern int mkdir(const char *path, mode_t mode); 103 extern int mkfifo(const char *path, mode_t mode); 104 extern mode_t umask(mode_t cmask); 105 106 // This achieves backwards compatibility with R5 107 #if 0 //def HAIKU_TARGET_PLATFORM_HAIKU 108 #define stat(fd, st) _stat(fd, st, sizeof(struct stat)) 109 #define fstat(fd, st) _fstat(fd, st, sizeof(struct stat)) 110 #define lstat(fd, st) _lstat(fd, st, sizeof(struct stat)) 111 #else 112 // ... and this fixes the build for R5 for now 113 extern int stat(const char *path, struct stat *st); 114 extern int fstat(int fd, struct stat *st); 115 extern int lstat(const char *path, struct stat *st); 116 #endif 117 118 #ifdef __cplusplus 119 } 120 #endif 121 122 #endif /* _SYS_STAT_H_ */ 123