2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1994-1995 Søren Schmidt
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_compat.h"
34 #include <sys/param.h>
35 #include <sys/capsicum.h>
36 #include <sys/dirent.h>
38 #include <sys/filedesc.h>
40 #include <sys/malloc.h>
41 #include <sys/mount.h>
42 #include <sys/namei.h>
44 #include <sys/syscallsubr.h>
45 #include <sys/systm.h>
47 #include <sys/vnode.h>
49 #include <sys/fcntl.h>
52 #include <machine/../linux32/linux.h>
53 #include <machine/../linux32/linux32_proto.h>
55 #include <machine/../linux/linux.h>
56 #include <machine/../linux/linux_proto.h>
59 #include <compat/linux/linux_util.h>
60 #include <compat/linux/linux_file.h>
63 translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
68 sb->st_mode &= ~S_IFMT;
69 sb->st_mode |= S_IFBLK;
73 * Return the same st_dev for every devfs instance. The reason
74 * for this is to work around an idiosyncrasy of glibc getttynam()
75 * implementation: it checks whether st_dev returned for fd 0
76 * is the same as st_dev returned for the target of /proc/self/fd/0
77 * symlink, and with linux chroots having their own devfs instance,
78 * the check will fail if you chroot into it.
80 if (rootdevmp != NULL && vp->v_mount->mnt_vfc == rootdevmp->mnt_vfc)
81 sb->st_dev = rootdevmp->mnt_stat.f_fsid.val[0];
83 if (linux_vn_get_major_minor(vp, &major, &minor) == 0)
84 sb->st_rdev = (major << 8 | minor);
88 linux_kern_statat(struct thread *td, int flag, int fd, const char *path,
89 enum uio_seg pathseg, struct stat *sbp)
92 return (kern_statat(td, flag, fd, path, pathseg, sbp,
93 translate_vnhook_major_minor));
96 #ifdef LINUX_LEGACY_SYSCALLS
98 linux_kern_stat(struct thread *td, const char *path, enum uio_seg pathseg,
102 return (linux_kern_statat(td, 0, AT_FDCWD, path, pathseg, sbp));
106 linux_kern_lstat(struct thread *td, const char *path, enum uio_seg pathseg,
110 return (linux_kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
116 translate_fd_major_minor(struct thread *td, int fd, struct stat *buf)
124 * No capability rights required here.
126 if ((!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode)) ||
127 fget(td, fd, &cap_no_rights, &fp) != 0)
130 if (vp != NULL && vn_isdisk(vp)) {
131 buf->st_mode &= ~S_IFMT;
132 buf->st_mode |= S_IFBLK;
134 if (vp != NULL && rootdevmp != NULL) {
137 if (mp != NULL && mp->mnt_vfc == rootdevmp->mnt_vfc)
138 buf->st_dev = rootdevmp->mnt_stat.f_fsid.val[0];
140 if (linux_vn_get_major_minor(vp, &major, &minor) == 0) {
141 buf->st_rdev = (major << 8 | minor);
142 } else if (fp->f_type == DTYPE_PTS) {
143 struct tty *tp = fp->f_data;
145 /* Convert the numbers for the slave device. */
146 if (linux_driver_get_major_minor(devtoname(tp->t_dev),
147 &major, &minor) == 0) {
148 buf->st_rdev = (major << 8 | minor);
155 * l_dev_t has the same encoding as dev_t in the latter's low 16 bits, so
156 * truncation of a dev_t to 16 bits gives the same result as unpacking
157 * using major() and minor() and repacking in the l_dev_t format. This
158 * detail is hidden in dev_to_ldev(). Overflow in conversions of dev_t's
159 * are not checked for, as for other fields.
161 * dev_to_ldev() is only used for translating st_dev. When we convert
162 * st_rdev for copying it out, it isn't really a dev_t, but has already
163 * been translated to an l_dev_t in a nontrivial way. Translating it
164 * again would be illogical but would have no effect since the low 16
165 * bits have the same encoding.
167 * The nontrivial translation for st_rdev renumbers some devices, but not
168 * ones that can be mounted on, so it is consistent with the translation
169 * for st_dev except when the renumbering or truncation causes conflicts.
171 #define dev_to_ldev(d) ((uint16_t)(d))
174 newstat_copyout(struct stat *buf, void *ubuf)
176 struct l_newstat tbuf;
178 bzero(&tbuf, sizeof(tbuf));
179 tbuf.st_dev = dev_to_ldev(buf->st_dev);
180 tbuf.st_ino = buf->st_ino;
181 tbuf.st_mode = buf->st_mode;
182 tbuf.st_nlink = buf->st_nlink;
183 tbuf.st_uid = buf->st_uid;
184 tbuf.st_gid = buf->st_gid;
185 tbuf.st_rdev = buf->st_rdev;
186 tbuf.st_size = buf->st_size;
187 tbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
188 tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
189 tbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
190 tbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
191 tbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
192 tbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
193 tbuf.st_blksize = buf->st_blksize;
194 tbuf.st_blocks = buf->st_blocks;
196 return (copyout(&tbuf, ubuf, sizeof(tbuf)));
200 statx_copyout(struct stat *buf, void *ubuf)
204 bzero(&tbuf, sizeof(tbuf));
205 tbuf.stx_mask = STATX_ALL;
206 tbuf.stx_blksize = buf->st_blksize;
207 tbuf.stx_attributes = 0;
208 tbuf.stx_nlink = buf->st_nlink;
209 tbuf.stx_uid = buf->st_uid;
210 tbuf.stx_gid = buf->st_gid;
211 tbuf.stx_mode = buf->st_mode;
212 tbuf.stx_ino = buf->st_ino;
213 tbuf.stx_size = buf->st_size;
214 tbuf.stx_blocks = buf->st_blocks;
216 tbuf.stx_atime.tv_sec = buf->st_atim.tv_sec;
217 tbuf.stx_atime.tv_nsec = buf->st_atim.tv_nsec;
218 tbuf.stx_btime.tv_sec = buf->st_birthtim.tv_sec;
219 tbuf.stx_btime.tv_nsec = buf->st_birthtim.tv_nsec;
220 tbuf.stx_ctime.tv_sec = buf->st_ctim.tv_sec;
221 tbuf.stx_ctime.tv_nsec = buf->st_ctim.tv_nsec;
222 tbuf.stx_mtime.tv_sec = buf->st_mtim.tv_sec;
223 tbuf.stx_mtime.tv_nsec = buf->st_mtim.tv_nsec;
225 tbuf.stx_rdev_major = buf->st_rdev >> 8;
226 tbuf.stx_rdev_minor = buf->st_rdev & 0xff;
227 tbuf.stx_dev_major = buf->st_dev >> 8;
228 tbuf.stx_dev_minor = buf->st_dev & 0xff;
230 return (copyout(&tbuf, ubuf, sizeof(tbuf)));
233 #ifdef LINUX_LEGACY_SYSCALLS
235 linux_newstat(struct thread *td, struct linux_newstat_args *args)
241 if (!LUSECONVPATH(td)) {
242 error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
244 LCONVPATHEXIST(td, args->path, &path);
245 error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
250 return (newstat_copyout(&buf, args->buf));
254 linux_newlstat(struct thread *td, struct linux_newlstat_args *args)
260 if (!LUSECONVPATH(td)) {
261 error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &sb);
263 LCONVPATHEXIST(td, args->path, &path);
264 error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb);
269 return (newstat_copyout(&sb, args->buf));
274 linux_newfstat(struct thread *td, struct linux_newfstat_args *args)
279 error = kern_fstat(td, args->fd, &buf);
280 translate_fd_major_minor(td, args->fd, &buf);
282 error = newstat_copyout(&buf, args->buf);
287 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
289 stat_copyout(struct stat *buf, void *ubuf)
293 bzero(&lbuf, sizeof(lbuf));
294 lbuf.st_dev = dev_to_ldev(buf->st_dev);
295 lbuf.st_ino = buf->st_ino;
296 lbuf.st_mode = buf->st_mode;
297 lbuf.st_nlink = buf->st_nlink;
298 lbuf.st_uid = buf->st_uid;
299 lbuf.st_gid = buf->st_gid;
300 lbuf.st_rdev = buf->st_rdev;
301 lbuf.st_size = MIN(buf->st_size, INT32_MAX);
302 lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
303 lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
304 lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
305 lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
306 lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
307 lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
308 lbuf.st_blksize = buf->st_blksize;
309 lbuf.st_blocks = buf->st_blocks;
310 lbuf.st_flags = buf->st_flags;
311 lbuf.st_gen = buf->st_gen;
313 return (copyout(&lbuf, ubuf, sizeof(lbuf)));
317 linux_stat(struct thread *td, struct linux_stat_args *args)
323 if (!LUSECONVPATH(td)) {
324 error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
326 LCONVPATHEXIST(td, args->path, &path);
327 error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
333 return (stat_copyout(&buf, args->up));
337 linux_lstat(struct thread *td, struct linux_lstat_args *args)
343 if (!LUSECONVPATH(td)) {
344 error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &buf);
346 LCONVPATHEXIST(td, args->path, &path);
347 error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf);
353 return (stat_copyout(&buf, args->up));
355 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
372 #define LINUX_CODA_SUPER_MAGIC 0x73757245L
373 #define LINUX_EXT2_SUPER_MAGIC 0xEF53L
374 #define LINUX_HPFS_SUPER_MAGIC 0xf995e849L
375 #define LINUX_ISOFS_SUPER_MAGIC 0x9660L
376 #define LINUX_MSDOS_SUPER_MAGIC 0x4d44L
377 #define LINUX_NCP_SUPER_MAGIC 0x564cL
378 #define LINUX_NFS_SUPER_MAGIC 0x6969L
379 #define LINUX_NTFS_SUPER_MAGIC 0x5346544EL
380 #define LINUX_PROC_SUPER_MAGIC 0x9fa0L
381 #define LINUX_UFS_SUPER_MAGIC 0x00011954L /* XXX - UFS_MAGIC in Linux */
382 #define LINUX_ZFS_SUPER_MAGIC 0x2FC12FC1
383 #define LINUX_DEVFS_SUPER_MAGIC 0x1373L
384 #define LINUX_SHMFS_MAGIC 0x01021994
387 bsd_to_linux_ftype(const char *fstypename)
390 static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = {
391 {"ufs", LINUX_UFS_SUPER_MAGIC},
392 {"zfs", LINUX_ZFS_SUPER_MAGIC},
393 {"cd9660", LINUX_ISOFS_SUPER_MAGIC},
394 {"nfs", LINUX_NFS_SUPER_MAGIC},
395 {"ext2fs", LINUX_EXT2_SUPER_MAGIC},
396 {"procfs", LINUX_PROC_SUPER_MAGIC},
397 {"msdosfs", LINUX_MSDOS_SUPER_MAGIC},
398 {"ntfs", LINUX_NTFS_SUPER_MAGIC},
399 {"nwfs", LINUX_NCP_SUPER_MAGIC},
400 {"hpfs", LINUX_HPFS_SUPER_MAGIC},
401 {"coda", LINUX_CODA_SUPER_MAGIC},
402 {"devfs", LINUX_DEVFS_SUPER_MAGIC},
403 {"tmpfs", LINUX_SHMFS_MAGIC},
406 for (i = 0; b2l_tbl[i].bsd_name != NULL; i++)
407 if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0)
408 return (b2l_tbl[i].linux_type);
414 bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs)
416 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
419 #define LINUX_HIBITS 0xffffffff00000000ULL
421 tmp = bsd_statfs->f_blocks | bsd_statfs->f_bfree | bsd_statfs->f_files |
423 if ((bsd_statfs->f_bavail != -1 && (bsd_statfs->f_bavail & LINUX_HIBITS)) ||
424 (bsd_statfs->f_ffree != -1 && (bsd_statfs->f_ffree & LINUX_HIBITS)) ||
425 (tmp & LINUX_HIBITS))
429 linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
430 linux_statfs->f_bsize = bsd_statfs->f_bsize;
431 linux_statfs->f_blocks = bsd_statfs->f_blocks;
432 linux_statfs->f_bfree = bsd_statfs->f_bfree;
433 linux_statfs->f_bavail = bsd_statfs->f_bavail;
434 linux_statfs->f_ffree = bsd_statfs->f_ffree;
435 linux_statfs->f_files = bsd_statfs->f_files;
436 linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
437 linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
438 linux_statfs->f_namelen = MAXNAMLEN;
439 linux_statfs->f_frsize = bsd_statfs->f_bsize;
440 linux_statfs->f_flags = 0;
441 memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
447 linux_statfs(struct thread *td, struct linux_statfs_args *args)
449 struct l_statfs linux_statfs;
450 struct statfs *bsd_statfs;
454 if (!LUSECONVPATH(td)) {
455 bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
456 error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
458 LCONVPATHEXIST(td, args->path, &path);
459 bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
460 error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
464 error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
465 free(bsd_statfs, M_STATFS);
468 return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
471 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
473 bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs)
476 linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
477 linux_statfs->f_bsize = bsd_statfs->f_bsize;
478 linux_statfs->f_blocks = bsd_statfs->f_blocks;
479 linux_statfs->f_bfree = bsd_statfs->f_bfree;
480 linux_statfs->f_bavail = bsd_statfs->f_bavail;
481 linux_statfs->f_ffree = bsd_statfs->f_ffree;
482 linux_statfs->f_files = bsd_statfs->f_files;
483 linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
484 linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
485 linux_statfs->f_namelen = MAXNAMLEN;
486 linux_statfs->f_frsize = bsd_statfs->f_bsize;
487 linux_statfs->f_flags = 0;
488 memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
492 linux_statfs64(struct thread *td, struct linux_statfs64_args *args)
494 struct l_statfs64 linux_statfs;
495 struct statfs *bsd_statfs;
499 if (args->bufsize != sizeof(struct l_statfs64))
502 if (!LUSECONVPATH(td)) {
503 bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
504 error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
506 LCONVPATHEXIST(td, args->path, &path);
507 bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
508 error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
512 bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
513 free(bsd_statfs, M_STATFS);
516 return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
520 linux_fstatfs64(struct thread *td, struct linux_fstatfs64_args *args)
522 struct l_statfs64 linux_statfs;
523 struct statfs *bsd_statfs;
526 if (args->bufsize != sizeof(struct l_statfs64))
529 bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
530 error = kern_fstatfs(td, args->fd, bsd_statfs);
532 bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
533 free(bsd_statfs, M_STATFS);
536 return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
538 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
541 linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args)
543 struct l_statfs linux_statfs;
544 struct statfs *bsd_statfs;
547 bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
548 error = kern_fstatfs(td, args->fd, bsd_statfs);
550 error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
551 free(bsd_statfs, M_STATFS);
554 return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
565 #ifdef LINUX_LEGACY_SYSCALLS
567 linux_ustat(struct thread *td, struct linux_ustat_args *args)
574 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
577 stat64_copyout(struct stat *buf, void *ubuf)
579 struct l_stat64 lbuf;
581 bzero(&lbuf, sizeof(lbuf));
582 lbuf.st_dev = dev_to_ldev(buf->st_dev);
583 lbuf.st_ino = buf->st_ino;
584 lbuf.st_mode = buf->st_mode;
585 lbuf.st_nlink = buf->st_nlink;
586 lbuf.st_uid = buf->st_uid;
587 lbuf.st_gid = buf->st_gid;
588 lbuf.st_rdev = buf->st_rdev;
589 lbuf.st_size = buf->st_size;
590 lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
591 lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
592 lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
593 lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
594 lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
595 lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
596 lbuf.st_blksize = buf->st_blksize;
597 lbuf.st_blocks = buf->st_blocks;
600 * The __st_ino field makes all the difference. In the Linux kernel
601 * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO,
602 * but without the assignment to __st_ino the runtime linker refuses
603 * to mmap(2) any shared libraries. I guess it's broken alright :-)
605 lbuf.__st_ino = buf->st_ino;
607 return (copyout(&lbuf, ubuf, sizeof(lbuf)));
611 linux_stat64(struct thread *td, struct linux_stat64_args *args)
617 if (!LUSECONVPATH(td)) {
618 error = linux_kern_stat(td, args->filename, UIO_USERSPACE, &buf);
620 LCONVPATHEXIST(td, args->filename, &filename);
621 error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf);
626 return (stat64_copyout(&buf, args->statbuf));
630 linux_lstat64(struct thread *td, struct linux_lstat64_args *args)
636 if (!LUSECONVPATH(td)) {
637 error = linux_kern_lstat(td, args->filename, UIO_USERSPACE, &sb);
639 LCONVPATHEXIST(td, args->filename, &filename);
640 error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb);
645 return (stat64_copyout(&sb, args->statbuf));
649 linux_fstat64(struct thread *td, struct linux_fstat64_args *args)
654 error = kern_fstat(td, args->fd, &buf);
655 translate_fd_major_minor(td, args->fd, &buf);
657 error = stat64_copyout(&buf, args->statbuf);
663 linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args)
666 int error, dfd, flag, unsupported;
669 unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
670 if (unsupported != 0) {
671 linux_msg(td, "fstatat64 unsupported flag 0x%x", unsupported);
674 flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
675 AT_SYMLINK_NOFOLLOW : 0;
676 flag |= (args->flag & LINUX_AT_EMPTY_PATH) ?
679 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
680 if (!LUSECONVPATH(td)) {
681 error = linux_kern_statat(td, flag, dfd, args->pathname,
682 UIO_USERSPACE, &buf);
684 LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
685 error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
689 error = stat64_copyout(&buf, args->statbuf);
694 #else /* __amd64__ && !COMPAT_LINUX32 */
697 linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args)
700 int error, dfd, flag, unsupported;
703 unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
704 if (unsupported != 0) {
705 linux_msg(td, "fstatat unsupported flag 0x%x", unsupported);
709 flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
710 AT_SYMLINK_NOFOLLOW : 0;
711 flag |= (args->flag & LINUX_AT_EMPTY_PATH) ?
714 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
715 if (!LUSECONVPATH(td)) {
716 error = linux_kern_statat(td, flag, dfd, args->pathname,
717 UIO_USERSPACE, &buf);
719 LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
720 error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
724 error = newstat_copyout(&buf, args->statbuf);
729 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
732 linux_syncfs(struct thread *td, struct linux_syncfs_args *args)
738 error = fgetvp(td, args->fd, &cap_fsync_rights, &vp);
741 * Linux syncfs() returns only EBADF, however fgetvp()
742 * can return EINVAL in case of file descriptor does
743 * not represent a vnode. XXX.
748 mtx_lock(&mountlist_mtx);
749 error = vfs_busy(mp, MBF_MNTLSTLOCK);
751 /* See comment above. */
752 mtx_unlock(&mountlist_mtx);
755 if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
756 vn_start_write(NULL, &mp, V_NOWAIT) == 0) {
757 save = curthread_pflags_set(TDP_SYNCIO);
758 vfs_periodic(mp, MNT_NOWAIT);
759 VFS_SYNC(mp, MNT_NOWAIT);
760 curthread_pflags_restore(save);
761 vn_finished_write(mp);
771 linux_statx(struct thread *td, struct linux_statx_args *args)
774 int error, dirfd, flags, unsupported;
777 unsupported = args->flags & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
778 if (unsupported != 0) {
779 linux_msg(td, "statx unsupported flags 0x%x", unsupported);
783 flags = (args->flags & LINUX_AT_SYMLINK_NOFOLLOW) ?
784 AT_SYMLINK_NOFOLLOW : 0;
785 flags |= (args->flags & LINUX_AT_EMPTY_PATH) ?
788 dirfd = (args->dirfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dirfd;
789 if (!LUSECONVPATH(td)) {
790 error = linux_kern_statat(td, flags, dirfd, args->pathname,
791 UIO_USERSPACE, &buf);
793 LCONVPATHEXIST_AT(td, args->pathname, &path, dirfd);
794 error = linux_kern_statat(td, flags, dirfd, path, UIO_SYSSPACE, &buf);
798 error = statx_copyout(&buf, args->statxbuf);