summaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_stats.c
diff options
context:
space:
mode:
authorPhilippe Michaud-Boudreault <pitwuu@gmail.com>2021-06-08 08:24:10 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2022-02-14 00:07:33 +0000
commitb630d64c3da1f669859ae61300191be09a744577 (patch)
tree54bcf39114963419b132cd35118814e0f001b58b /sys/compat/linux/linux_stats.c
parente0effca49904e8414275e9cb93170685a99d67cb (diff)
Diffstat (limited to 'sys/compat/linux/linux_stats.c')
-rw-r--r--sys/compat/linux/linux_stats.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index c88f6f53bdd7..4e6304500a8b 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -196,6 +196,40 @@ newstat_copyout(struct stat *buf, void *ubuf)
return (copyout(&tbuf, ubuf, sizeof(tbuf)));
}
+static int
+statx_copyout(struct stat *buf, void *ubuf)
+{
+ struct l_statx tbuf;
+
+ bzero(&tbuf, sizeof(tbuf));
+ tbuf.stx_mask = STATX_ALL;
+ tbuf.stx_blksize = buf->st_blksize;
+ tbuf.stx_attributes = 0;
+ tbuf.stx_nlink = buf->st_nlink;
+ tbuf.stx_uid = buf->st_uid;
+ tbuf.stx_gid = buf->st_gid;
+ tbuf.stx_mode = buf->st_mode;
+ tbuf.stx_ino = buf->st_ino;
+ tbuf.stx_size = buf->st_size;
+ tbuf.stx_blocks = buf->st_blocks;
+
+ tbuf.stx_atime.tv_sec = buf->st_atim.tv_sec;
+ tbuf.stx_atime.tv_nsec = buf->st_atim.tv_nsec;
+ tbuf.stx_btime.tv_sec = buf->st_birthtim.tv_sec;
+ tbuf.stx_btime.tv_nsec = buf->st_birthtim.tv_nsec;
+ tbuf.stx_ctime.tv_sec = buf->st_ctim.tv_sec;
+ tbuf.stx_ctime.tv_nsec = buf->st_ctim.tv_nsec;
+ tbuf.stx_mtime.tv_sec = buf->st_mtim.tv_sec;
+ tbuf.stx_mtime.tv_nsec = buf->st_mtim.tv_nsec;
+
+ tbuf.stx_rdev_major = buf->st_rdev >> 8;
+ tbuf.stx_rdev_minor = buf->st_rdev & 0xff;
+ tbuf.stx_dev_major = buf->st_dev >> 8;
+ tbuf.stx_dev_minor = buf->st_dev & 0xff;
+
+ return (copyout(&tbuf, ubuf, sizeof(tbuf)));
+}
+
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_newstat(struct thread *td, struct linux_newstat_args *args)
@@ -730,3 +764,36 @@ linux_syncfs(struct thread *td, struct linux_syncfs_args *args)
vrele(vp);
return (error);
}
+
+int
+linux_statx(struct thread *td, struct linux_statx_args *args)
+{
+ char *path;
+ int error, dirfd, flags;
+ struct stat buf;
+
+ if (args->flags & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH)) {
+ linux_msg(td, "statx unsupported flags 0x%x", args->flags);
+ return (EINVAL);
+ }
+
+ flags = (args->flags & LINUX_AT_SYMLINK_NOFOLLOW) ?
+ AT_SYMLINK_NOFOLLOW : 0;
+ flags |= (args->flags & LINUX_AT_EMPTY_PATH) ?
+ AT_EMPTY_PATH : 0;
+
+ dirfd = (args->dirfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dirfd;
+ if (!LUSECONVPATH(td)) {
+ error = linux_kern_statat(td, flags, dirfd, args->pathname,
+ UIO_USERSPACE, &buf);
+ } else {
+ LCONVPATHEXIST_AT(td, args->pathname, &path, dirfd);
+ error = linux_kern_statat(td, flags, dirfd, path, UIO_SYSSPACE, &buf);
+ LFREEPATH(path);
+ }
+ if (error == 0)
+ error = statx_copyout(&buf, args->statxbuf);
+
+ return (error);
+}
+