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