7 #include <sys/sysmacros.h>
13 uint64_t stx_attributes;
22 uint64_t stx_attributes_mask;
27 } stx_atime, stx_btime, stx_ctime, stx_mtime;
28 uint32_t stx_rdev_major;
29 uint32_t stx_rdev_minor;
30 uint32_t stx_dev_major;
31 uint32_t stx_dev_minor;
35 static int fstatat_statx(int fd, const char *restrict path, struct stat *restrict st, int flag)
39 int ret = __syscall(SYS_statx, fd, path, flag, 0x7ff, &stx);
43 .st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor),
44 .st_ino = stx.stx_ino,
45 .st_mode = stx.stx_mode,
46 .st_nlink = stx.stx_nlink,
47 .st_uid = stx.stx_uid,
48 .st_gid = stx.stx_gid,
49 .st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor),
50 .st_size = stx.stx_size,
51 .st_blksize = stx.stx_blksize,
52 .st_blocks = stx.stx_blocks,
53 .st_atim.tv_sec = stx.stx_atime.tv_sec,
54 .st_atim.tv_nsec = stx.stx_atime.tv_nsec,
55 .st_mtim.tv_sec = stx.stx_mtime.tv_sec,
56 .st_mtim.tv_nsec = stx.stx_mtime.tv_nsec,
57 .st_ctim.tv_sec = stx.stx_ctime.tv_sec,
58 .st_ctim.tv_nsec = stx.stx_ctime.tv_nsec,
60 .__st_atim32.tv_sec = stx.stx_atime.tv_sec,
61 .__st_atim32.tv_nsec = stx.stx_atime.tv_nsec,
62 .__st_mtim32.tv_sec = stx.stx_mtime.tv_sec,
63 .__st_mtim32.tv_nsec = stx.stx_mtime.tv_nsec,
64 .__st_ctim32.tv_sec = stx.stx_ctime.tv_sec,
65 .__st_ctim32.tv_nsec = stx.stx_ctime.tv_nsec,
75 static int fstatat_kstat(int fd, const char *restrict path, struct stat *restrict st, int flag)
80 if (flag==AT_EMPTY_PATH && fd>=0 && !*path) {
81 ret = __syscall(SYS_fstat, fd, &kst);
82 if (ret==-EBADF && __syscall(SYS_fcntl, fd, F_GETFD)>=0) {
83 ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
85 char buf[15+3*sizeof(int)];
86 __procfdname(buf, fd);
88 ret = __syscall(SYS_stat, buf, &kst);
90 ret = __syscall(SYS_fstatat, AT_FDCWD, buf, &kst, 0);
96 else if ((fd == AT_FDCWD || *path=='/') && flag==AT_SYMLINK_NOFOLLOW)
97 ret = __syscall(SYS_lstat, path, &kst);
100 else if ((fd == AT_FDCWD || *path=='/') && !flag)
101 ret = __syscall(SYS_stat, path, &kst);
103 else ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
108 .st_dev = kst.st_dev,
109 .st_ino = kst.st_ino,
110 .st_mode = kst.st_mode,
111 .st_nlink = kst.st_nlink,
112 .st_uid = kst.st_uid,
113 .st_gid = kst.st_gid,
114 .st_rdev = kst.st_rdev,
115 .st_size = kst.st_size,
116 .st_blksize = kst.st_blksize,
117 .st_blocks = kst.st_blocks,
118 .st_atim.tv_sec = kst.st_atime_sec,
119 .st_atim.tv_nsec = kst.st_atime_nsec,
120 .st_mtim.tv_sec = kst.st_mtime_sec,
121 .st_mtim.tv_nsec = kst.st_mtime_nsec,
122 .st_ctim.tv_sec = kst.st_ctime_sec,
123 .st_ctim.tv_nsec = kst.st_ctime_nsec,
125 .__st_atim32.tv_sec = kst.st_atime_sec,
126 .__st_atim32.tv_nsec = kst.st_atime_nsec,
127 .__st_mtim32.tv_sec = kst.st_mtime_sec,
128 .__st_mtim32.tv_nsec = kst.st_mtime_nsec,
129 .__st_ctim32.tv_sec = kst.st_ctime_sec,
130 .__st_ctim32.tv_nsec = kst.st_ctime_nsec,
138 int __fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
142 if (sizeof((struct kstat){0}.st_atime_sec) < sizeof(time_t)) {
143 ret = fstatat_statx(fd, path, st, flag);
144 if (ret!=-ENOSYS) return __syscall_ret(ret);
146 ret = fstatat_kstat(fd, path, st, flag);
148 ret = fstatat_statx(fd, path, st, flag);
150 return __syscall_ret(ret);
153 weak_alias(__fstatat, fstatat);