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