VSF Documented
stat.h
Go to the documentation of this file.
1#ifndef __VSF_LINUX_SYS_STAT_H__
2#define __VSF_LINUX_SYS_STAT_H__
3
5
6#if VSF_LINUX_CFG_RELATIVE_PATH == ENABLED
7# include "../sys/types.h"
8# include "../simple_libc/time.h"
9#else
10# include <sys/types.h>
11# include <time.h>
12#endif
13
14// for fs constants
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#if VSF_LINUX_CFG_WRAPPER == ENABLED
22#define stat VSF_LINUX_WRAPPER(stat)
23#define lstat VSF_LINUX_WRAPPER(lstat)
24#define fstat VSF_LINUX_WRAPPER(fstat)
25#define fstatat VSF_LINUX_WRAPPER(fstatat)
26#define umask VSF_LINUX_WRAPPER(umask)
27#define chmod VSF_LINUX_WRAPPER(chmod)
28#define fchmod VSF_LINUX_WRAPPER(fchmod)
29#define futimens VSF_LINUX_WRAPPER(futimens)
30#define utimensat VSF_LINUX_WRAPPER(utimensat)
31#define mkdir VSF_LINUX_WRAPPER(mkdir)
32#define mkfifo VSF_LINUX_WRAPPER(mkfifo)
33#define mkfifoat VSF_LINUX_WRAPPER(mkfifoat)
34#define mknod VSF_LINUX_WRAPPER(mknod)
35#define mknodat VSF_LINUX_WRAPPER(mknodat)
36#endif
37
38// syscalls
39
40#define __NR_stat stat
41#define __NR_fstat fstat
42#define __NR_fstatat fstatat
43#define __NR_umask umask
44#define __NR_chmod chmod
45#define __NR_fchmod fchmod
46#define __NR_fchmodat fchmodat
47#define __NR_futimesat futimesat
48#define __NR_utimensat utimensat
49
50// TODO: assert extension attr is fit in vk_file_attr_t
51#define VSF_FILE_ATTR_CHR (VSF_FILE_ATTR_USER << 0)
52#define VSF_FILE_ATTR_BLK (VSF_FILE_ATTR_USER << 1)
53#define VSF_FILE_ATTR_EXCL (VSF_FILE_ATTR_USER << 3)
54#define VSF_FILE_ATTR_SOCK (VSF_FILE_ATTR_USER << 4)
55#define VSF_FILE_ATTR_TTY (VSF_FILE_ATTR_USER << 5)
56#define VSF_FILE_ATTR_FIFO (VSF_FILE_ATTR_USER << 6)
57// internal use, indicating priv of sfd is shared, do not free
58#define __VSF_FILE_ATTR_SHARE_PRIV (VSF_FILE_ATTR_USER << 16)
59
60#define UTIME_NOW ((1l << 30) - 1l)
61#define UTIME_OMIT ((1l << 30) - 2l)
62
63#define S_IFDIR 0040000
64#define S_IFREG 0100000
65#define S_IFLNK 0120000
66#define S_IFIFO 0010000
67#define S_IFCHR 0020000
68#define S_IFSOCK 0140000
69#define S_IFBLK 0060000
70#define S_IFMT 0170000
71
72#define __S_IR 04
73#define __S_IW 02
74#define __S_IX 01
75#define S_IROTH (__S_IR << 0)
76#define S_IWOTH (__S_IW << 0)
77#define S_IXOTH (__S_IX << 0)
78#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
79#define S_IRGRP (__S_IR << 3)
80#define S_IWGRP (__S_IW << 3)
81#define S_IXGRP (__S_IX << 3)
82#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
83#define S_IRUSR (__S_IR << 6)
84#define S_IWUSR (__S_IW << 6)
85#define S_IXUSR (__S_IX << 6)
86#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
87
88#define S_IREAD S_IRUSR
89#define S_IWRITE S_IWUSR
90#define S_IEXEC S_IXUSR
91
92// protection bits
93#define S_ISUID 0004000
94#define S_ISGID 0002000
95#define S_ISVTX 0001000
96
97#define S_ISLNK(__MODE) (((__MODE) & S_IFMT) == S_IFLNK)
98#define S_ISREG(__MODE) (((__MODE) & S_IFMT) == S_IFREG)
99#define S_ISDIR(__MODE) (((__MODE) & S_IFMT) == S_IFDIR)
100#define S_ISFIFO(__MODE) (((__MODE) & S_IFMT) == S_IFIFO)
101#define S_ISSOCK(__MODE) (((__MODE) & S_IFMT) == S_IFSOCK)
102#define S_ISCHR(__MODE) (((__MODE) & S_IFMT) == S_IFCHR)
103#define S_ISBLK(__MODE) (((__MODE) & S_IFMT) == S_IFBLK)
104
105// struct stat is actually stat64
106struct stat {
118
122#define st_atime st_atim.tv_sec
123#define st_mtime st_mtim.tv_sec
124#define st_ctime st_ctim.tv_sec
125};
126
127struct stat64 {
139
143#define st_atime st_atim.tv_sec
144#define st_mtime st_mtim.tv_sec
145#define st_ctime st_ctim.tv_sec
146};
147
148#if VSF_LINUX_APPLET_USE_SYS_STAT == ENABLED
151
167# ifndef __VSF_APPLET__
169# endif
170#endif
171
172#if defined(__VSF_APPLET__) && (defined(__VSF_APPLET_LIB__) || defined(__VSF_APPLET_LINUX_SYS_STAT_LIB__))\
173 && VSF_APPLET_CFG_ABI_PATCH != ENABLED && VSF_LINUX_APPLET_USE_SYS_STAT == ENABLED
174
175#ifndef VSF_LINUX_APPLET_SYS_STAT_VPLT
176# if VSF_LINUX_USE_APPLET == ENABLED
177# define VSF_LINUX_APPLET_SYS_STAT_VPLT \
178 ((vsf_linux_sys_stat_vplt_t *)(VSF_LINUX_APPLET_VPLT->sys_stat_vplt))
179# else
180# define VSF_LINUX_APPLET_SYS_STAT_VPLT \
181 ((vsf_linux_sys_stat_vplt_t *)vsf_vplt((void *)0))
182# endif
183#endif
184
185#define VSF_LINUX_APPLET_SYS_STAT_ENTRY(__NAME) \
186 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_LINUX_APPLET_SYS_STAT_VPLT, __NAME)
187#define VSF_LINUX_APPLET_SYS_STAT_IMP(...) \
188 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_LINUX_APPLET_SYS_STAT_VPLT, __VA_ARGS__)
189
190VSF_LINUX_APPLET_SYS_STAT_IMP(umask, mode_t, mode_t mask) {
192 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(umask)(mask);
193}
194VSF_LINUX_APPLET_SYS_STAT_IMP(stat, int, const char *pathname, struct stat *buf) {
196 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(stat)(pathname, buf);
197}
198VSF_LINUX_APPLET_SYS_STAT_IMP(lstat, int, const char *pathname, struct stat *buf) {
200 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(lstat)(pathname, buf);
201}
202VSF_LINUX_APPLET_SYS_STAT_IMP(fstat, int, int fd, struct stat *buf) {
204 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(fstat)(fd, buf);
205}
206VSF_LINUX_APPLET_SYS_STAT_IMP(fstatat, int, int dirfd, const char *pathname, struct stat *buf, int flags) {
208 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(fstatat)(dirfd, pathname, buf, flags);
209}
210VSF_LINUX_APPLET_SYS_STAT_IMP(chmod, int, const char *pathname, mode_t mode) {
212 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(chmod)(pathname, mode);
213}
214VSF_LINUX_APPLET_SYS_STAT_IMP(fchmod, int, int fd, mode_t mode) {
216 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(fchmod)(fd, mode);
217}
218VSF_LINUX_APPLET_SYS_STAT_IMP(mkdir, int, const char *pathname, mode_t mode) {
220 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(mkdir)(pathname, mode);
221}
222VSF_LINUX_APPLET_SYS_STAT_IMP(mkfifo, int, const char *pathname, mode_t mode) {
224 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(mkfifo)(pathname, mode);
225}
226VSF_LINUX_APPLET_SYS_STAT_IMP(mkfifoat, int, int dirfd, const char *pathname, mode_t mode) {
228 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(mkfifoat)(dirfd, pathname, mode);
229}
230VSF_LINUX_APPLET_SYS_STAT_IMP(mknod, int, const char *pathname, mode_t mode, dev_t dev) {
232 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(mknod)(pathname, mode, dev);
233}
234VSF_LINUX_APPLET_SYS_STAT_IMP(mknodat, int, int dirfd, const char *pathname, mode_t mode, dev_t dev) {
236 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(mknodat)(dirfd, pathname, mode, dev);
237}
238VSF_LINUX_APPLET_SYS_STAT_IMP(futimens, int, int fd, const struct timespec times[2]) {
240 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(futimens)(fd, times);
241}
242VSF_LINUX_APPLET_SYS_STAT_IMP(utimensat, int, int dirfd, const char *pathname, const struct timespec times[2], int flags) {
244 return VSF_LINUX_APPLET_SYS_STAT_ENTRY(utimensat)(dirfd, pathname, times, flags);
245}
246
247#else // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_SYS_STAT
248
249mode_t umask(mode_t mask);
250int stat(const char *pathname, struct stat *buf);
251int lstat(const char *pathname, struct stat *buf);
252int fstat(int fd, struct stat *buf);
253int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
254int futimens(int fd, const struct timespec times[2]);
255int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
256int chmod(const char *pathname, mode_t mode);
257int fchmod(int fd, mode_t mode);
258int mkdir(const char *pathname, mode_t mode);
259int mkfifo(const char *pathname, mode_t mode);
260int mkfifoat(int dirfd, const char *pathname, mode_t mode);
261int mknod(const char *pathname, mode_t mode, dev_t dev);
262int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev);
263
264#endif // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_SYS_STAT
265
266static inline int stat64(const char *pathname, struct stat64 *buf)
267{
268 return stat(pathname, (struct stat *)buf);
269}
270static inline int lstat64(const char *pathname, struct stat64 *buf)
271{
272 return lstat(pathname, (struct stat *)buf);
273}
274static inline int fstat64(int fd, struct stat64 *buf)
275{
276 return fstat(fd, (struct stat *)buf);
277}
278
279#ifdef __cplusplus
280}
281#endif
282
283#endif
unsigned long long ino64_t
Definition types.h:100
unsigned int blksiz_t
Definition types.h:101
unsigned long long blkcnt64_t
Definition types.h:103
unsigned int uid_t
Definition types.h:90
unsigned int gid_t
Definition types.h:91
long long off64_t
Definition types.h:97
unsigned long dev_t
Definition types.h:98
unsigned int mode_t
Definition types.h:87
unsigned int nlink_t
Definition types.h:89
#define mknodat
Definition stat.h:35
#define stat
Definition stat.h:22
#define mkdir
Definition stat.h:31
#define chmod
Definition stat.h:27
#define fchmod
Definition stat.h:28
#define mkfifo
Definition stat.h:32
#define mkfifoat
Definition stat.h:33
__VSF_VPLT_DECORATOR__ vsf_linux_sys_stat_vplt_t vsf_linux_sys_stat_vplt
Definition vsf_linux_fs.c:3664
#define fstatat
Definition stat.h:25
#define mknod
Definition stat.h:34
#define futimens
Definition stat.h:29
#define fstat
Definition stat.h:24
#define umask
Definition stat.h:26
#define lstat
Definition stat.h:23
#define utimensat
Definition stat.h:30
Definition stat.h:127
mode_t st_mode
Definition stat.h:131
ino64_t st_ino
Definition stat.h:130
gid_t st_gid
Definition stat.h:134
nlink_t st_nlink
Definition stat.h:132
dev_t st_dev
Definition stat.h:128
off64_t st_size
Definition stat.h:135
struct timespec st_ctim
Definition stat.h:142
dev_t st_rdev
Definition stat.h:129
mode_t st_attr
Definition stat.h:138
struct timespec st_mtim
Definition stat.h:141
blksiz_t st_blksize
Definition stat.h:136
uid_t st_uid
Definition stat.h:133
blkcnt64_t st_blocks
Definition stat.h:137
struct timespec st_atim
Definition stat.h:140
Definition stat.h:106
nlink_t st_nlink
Definition stat.h:111
ino64_t st_ino
Definition stat.h:109
blkcnt64_t st_blocks
Definition stat.h:116
uid_t st_uid
Definition stat.h:112
mode_t st_mode
Definition stat.h:110
struct timespec st_mtim
Definition stat.h:120
struct timespec st_atim
Definition stat.h:119
struct timespec st_ctim
Definition stat.h:121
dev_t st_rdev
Definition stat.h:108
mode_t st_attr
Definition stat.h:117
gid_t st_gid
Definition stat.h:113
off64_t st_size
Definition stat.h:114
dev_t st_dev
Definition stat.h:107
blksiz_t st_blksize
Definition stat.h:115
Definition time.h:67
Definition stat.h:149
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(mknodat)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(fstatat)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(fchmod)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(utimensat)
vsf_vplt_info_t info
Definition stat.h:150
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(futimens)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(mkfifoat)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(mkfifo)
#define times
Definition times.h:18
Definition vsf_cfg.h:95
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
#define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
Definition vsf_cfg.h:165