| 1 | #define _GNU_SOURCE |
| 2 | #include <sys/stat.h> |
| 3 | #include <string.h> |
| 4 | #include <syscall.h> |
| 5 | #include <sys/sysmacros.h> |
| 6 | #include <errno.h> |
| 7 | |
| 8 | int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct statx *restrict stx) |
| 9 | { |
| 10 | 	int ret = __syscall(SYS_statx, dirfd, path, flags, mask, stx); |
| 11 | |
| 12 | #ifndef SYS_fstatat |
| 13 | 	return __syscall_ret(ret); |
| 14 | #endif |
| 15 | |
| 16 | 	if (ret != -ENOSYS) return __syscall_ret(ret); |
| 17 | |
| 18 | 	struct stat st; |
| 19 | 	ret = fstatat(dirfd, path, &st, flags); |
| 20 | 	if (ret) return ret; |
| 21 | |
| 22 | 	stx->stx_dev_major = major(st.st_dev); |
| 23 | 	stx->stx_dev_minor = minor(st.st_dev); |
| 24 | 	stx->stx_ino = st.st_ino; |
| 25 | 	stx->stx_mode = st.st_mode; |
| 26 | 	stx->stx_nlink = st.st_nlink; |
| 27 | 	stx->stx_uid = st.st_uid; |
| 28 | 	stx->stx_gid = st.st_gid; |
| 29 | 	stx->stx_size = st.st_size; |
| 30 | 	stx->stx_blksize = st.st_blksize; |
| 31 | 	stx->stx_blocks = st.st_blocks; |
| 32 | 	stx->stx_atime.tv_sec = st.st_atim.tv_sec; |
| 33 | 	stx->stx_atime.tv_nsec = st.st_atim.tv_nsec; |
| 34 | 	stx->stx_mtime.tv_sec = st.st_mtim.tv_sec; |
| 35 | 	stx->stx_mtime.tv_nsec = st.st_mtim.tv_nsec; |
| 36 | 	stx->stx_ctime.tv_sec = st.st_ctim.tv_sec; |
| 37 | 	stx->stx_ctime.tv_nsec = st.st_ctim.tv_nsec; |
| 38 | 	stx->stx_btime = (struct statx_timestamp){.tv_sec=0, .tv_nsec=0}; |
| 39 | 	stx->stx_mask = STATX_BASIC_STATS; |
| 40 | |
| 41 | 	return 0; |
| 42 | } |