7 #include <sys/sysmacros.h>
14 uint64_t stx_attributes
;
23 uint64_t stx_attributes_mask
;
28 } stx_atime
, stx_btime
, stx_ctime
, stx_mtime
;
29 uint32_t stx_rdev_major
;
30 uint32_t stx_rdev_minor
;
31 uint32_t stx_dev_major
;
32 uint32_t stx_dev_minor
;
36 static int fstatat_statx(int fd
, const char *restrict path
, struct stat
*restrict st
, int flag
)
40 int ret
= __syscall(SYS_statx
, fd
, path
, flag
, 0x7ff, &stx
);
44 .st_dev
= makedev(stx
.stx_dev_major
, stx
.stx_dev_minor
),
45 .st_ino
= stx
.stx_ino
,
46 .st_mode
= stx
.stx_mode
,
47 .st_nlink
= stx
.stx_nlink
,
48 .st_uid
= stx
.stx_uid
,
49 .st_gid
= stx
.stx_gid
,
50 .st_rdev
= makedev(stx
.stx_rdev_major
, stx
.stx_rdev_minor
),
51 .st_size
= stx
.stx_size
,
52 .st_blksize
= stx
.stx_blksize
,
53 .st_blocks
= stx
.stx_blocks
,
54 .st_atim
.tv_sec
= stx
.stx_atime
.tv_sec
,
55 .st_atim
.tv_nsec
= stx
.stx_atime
.tv_nsec
,
56 .st_mtim
.tv_sec
= stx
.stx_mtime
.tv_sec
,
57 .st_mtim
.tv_nsec
= stx
.stx_mtime
.tv_nsec
,
58 .st_ctim
.tv_sec
= stx
.stx_ctime
.tv_sec
,
59 .st_ctim
.tv_nsec
= stx
.stx_ctime
.tv_nsec
,
64 static int fstatat_kstat(int fd
, const char *restrict path
, struct stat
*restrict st
, int flag
)
69 if (flag
==AT_EMPTY_PATH
&& fd
>=0 && !*path
) {
70 ret
= __syscall(SYS_fstat
, fd
, &kst
);
71 if (ret
==-EBADF
&& __syscall(SYS_fcntl
, fd
, F_GETFD
)>=0) {
72 ret
= __syscall(SYS_fstatat
, fd
, path
, &kst
, flag
);
74 char buf
[15+3*sizeof(int)];
75 __procfdname(buf
, fd
);
77 ret
= __syscall(SYS_stat
, buf
, &kst
);
79 ret
= __syscall(SYS_fstatat
, AT_FDCWD
, buf
, &kst
, 0);
85 else if ((fd
== AT_FDCWD
|| *path
=='/') && flag
==AT_SYMLINK_NOFOLLOW
)
86 ret
= __syscall(SYS_lstat
, path
, &kst
);
89 else if ((fd
== AT_FDCWD
|| *path
=='/') && !flag
)
90 ret
= __syscall(SYS_stat
, path
, &kst
);
92 else ret
= __syscall(SYS_fstatat
, fd
, path
, &kst
, flag
);
99 .st_mode
= kst
.st_mode
,
100 .st_nlink
= kst
.st_nlink
,
101 .st_uid
= kst
.st_uid
,
102 .st_gid
= kst
.st_gid
,
103 .st_rdev
= kst
.st_rdev
,
104 .st_size
= kst
.st_size
,
105 .st_blksize
= kst
.st_blksize
,
106 .st_blocks
= kst
.st_blocks
,
107 .st_atim
.tv_sec
= kst
.st_atime_sec
,
108 .st_atim
.tv_nsec
= kst
.st_atime_nsec
,
109 .st_mtim
.tv_sec
= kst
.st_mtime_sec
,
110 .st_mtim
.tv_nsec
= kst
.st_mtime_nsec
,
111 .st_ctim
.tv_sec
= kst
.st_ctime_sec
,
112 .st_ctim
.tv_nsec
= kst
.st_ctime_nsec
,
118 int fstatat(int fd
, const char *restrict path
, struct stat
*restrict st
, int flag
)
121 if (sizeof((struct kstat
){0}.st_atime_sec
) < sizeof(time_t)) {
122 ret
= fstatat_statx(fd
, path
, st
, flag
);
123 if (ret
!=-ENOSYS
) return __syscall_ret(ret
);
125 ret
= fstatat_kstat(fd
, path
, st
, flag
);
126 return __syscall_ret(ret
);
129 weak_alias(fstatat
, fstatat64
);