xref: /freebsd/sys/compat/linux/linux_stats.c (revision 0ba1b36553ab50d2498d37178d5e9704f19ccc1e)
1c21dee17SSøren Schmidt /*-
2*0ba1b365SEd Maste  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
37f2d13d6SPedro F. Giffuni  *
49a14aa01SUlrich Spörlein  * Copyright (c) 1994-1995 Søren Schmidt
5c21dee17SSøren Schmidt  * All rights reserved.
6c21dee17SSøren Schmidt  *
7c21dee17SSøren Schmidt  * Redistribution and use in source and binary forms, with or without
8c21dee17SSøren Schmidt  * modification, are permitted provided that the following conditions
9c21dee17SSøren Schmidt  * are met:
10c21dee17SSøren Schmidt  * 1. Redistributions of source code must retain the above copyright
11*0ba1b365SEd Maste  *    notice, this list of conditions and the following disclaimer.
12c21dee17SSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
13c21dee17SSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
14c21dee17SSøren Schmidt  *    documentation and/or other materials provided with the distribution.
15c21dee17SSøren Schmidt  *
16*0ba1b365SEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*0ba1b365SEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*0ba1b365SEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*0ba1b365SEd Maste  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*0ba1b365SEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*0ba1b365SEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*0ba1b365SEd Maste  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*0ba1b365SEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*0ba1b365SEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*0ba1b365SEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*0ba1b365SEd Maste  * SUCH DAMAGE.
27c21dee17SSøren Schmidt  */
28c21dee17SSøren Schmidt 
2916dbc7f2SDavid E. O'Brien #include <sys/cdefs.h>
3016dbc7f2SDavid E. O'Brien __FBSDID("$FreeBSD$");
3116dbc7f2SDavid E. O'Brien 
32aefce619SRuslan Ermilov #include "opt_compat.h"
33eddc160eSRobert Watson 
34c21dee17SSøren Schmidt #include <sys/param.h>
359802eb9eSDmitry Chagin #include <sys/capsicum.h>
36c21dee17SSøren Schmidt #include <sys/dirent.h>
37c21dee17SSøren Schmidt #include <sys/file.h>
38c21dee17SSøren Schmidt #include <sys/filedesc.h>
39c21dee17SSøren Schmidt #include <sys/proc.h>
4085422e62SBruce Evans #include <sys/malloc.h>
41c21dee17SSøren Schmidt #include <sys/mount.h>
42c21dee17SSøren Schmidt #include <sys/namei.h>
43c21dee17SSøren Schmidt #include <sys/stat.h>
44f7a25872SJohn Baldwin #include <sys/syscallsubr.h>
45408da119SMarcel Moolenaar #include <sys/systm.h>
46bc093719SEd Schouten #include <sys/tty.h>
47c21dee17SSøren Schmidt #include <sys/vnode.h>
48060e4882SDoug Ambrisko #include <sys/conf.h>
49060e4882SDoug Ambrisko #include <sys/fcntl.h>
50c21dee17SSøren Schmidt 
511997c537SDavid E. O'Brien #ifdef COMPAT_LINUX32
524af27623STim J. Robbins #include <machine/../linux32/linux.h>
534af27623STim J. Robbins #include <machine/../linux32/linux32_proto.h>
541997c537SDavid E. O'Brien #else
551997c537SDavid E. O'Brien #include <machine/../linux/linux.h>
561997c537SDavid E. O'Brien #include <machine/../linux/linux_proto.h>
574af27623STim J. Robbins #endif
5885422e62SBruce Evans 
59ac951e62SMarcel Moolenaar #include <compat/linux/linux_util.h>
6048b05c3fSKonstantin Belousov #include <compat/linux/linux_file.h>
61762e6b85SEivind Eklund 
62529844c7SAlexander Leidinger 
630eee862aSEd Schouten static void
640eee862aSEd Schouten translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
650eee862aSEd Schouten {
660eee862aSEd Schouten 	int major, minor;
670eee862aSEd Schouten 
680eee862aSEd Schouten 	if (vp->v_type == VCHR && vp->v_rdev != NULL &&
697870adb6SEd Schouten 	    linux_driver_get_major_minor(devtoname(vp->v_rdev),
700eee862aSEd Schouten 	    &major, &minor) == 0) {
710eee862aSEd Schouten 		sb->st_rdev = (major << 8 | minor);
720eee862aSEd Schouten 	}
730eee862aSEd Schouten }
740eee862aSEd Schouten 
750eee862aSEd Schouten static int
760eee862aSEd Schouten linux_kern_statat(struct thread *td, int flag, int fd, char *path,
770eee862aSEd Schouten     enum uio_seg pathseg, struct stat *sbp)
780eee862aSEd Schouten {
790eee862aSEd Schouten 
806e646651SKonstantin Belousov 	return (kern_statat(td, flag, fd, path, pathseg, sbp,
810eee862aSEd Schouten 	    translate_vnhook_major_minor));
820eee862aSEd Schouten }
830eee862aSEd Schouten 
840eee862aSEd Schouten static int
850eee862aSEd Schouten linux_kern_stat(struct thread *td, char *path, enum uio_seg pathseg,
860eee862aSEd Schouten     struct stat *sbp)
870eee862aSEd Schouten {
880eee862aSEd Schouten 
890eee862aSEd Schouten 	return (linux_kern_statat(td, 0, AT_FDCWD, path, pathseg, sbp));
900eee862aSEd Schouten }
910eee862aSEd Schouten 
920eee862aSEd Schouten static int
930eee862aSEd Schouten linux_kern_lstat(struct thread *td, char *path, enum uio_seg pathseg,
940eee862aSEd Schouten     struct stat *sbp)
950eee862aSEd Schouten {
960eee862aSEd Schouten 
970eee862aSEd Schouten 	return (linux_kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
980eee862aSEd Schouten 	    pathseg, sbp));
990eee862aSEd Schouten }
1000eee862aSEd Schouten 
101060e4882SDoug Ambrisko static void
102060e4882SDoug Ambrisko translate_fd_major_minor(struct thread *td, int fd, struct stat *buf)
103060e4882SDoug Ambrisko {
104060e4882SDoug Ambrisko 	struct file *fp;
1050eee862aSEd Schouten 	struct vnode *vp;
106f131759fSMateusz Guzik 	cap_rights_t rights;
107060e4882SDoug Ambrisko 	int major, minor;
108060e4882SDoug Ambrisko 
109a9d2f8d8SRobert Watson 	/*
110a9d2f8d8SRobert Watson 	 * No capability rights required here.
111a9d2f8d8SRobert Watson 	 */
112b256a1e1SJung-uk Kim 	if ((!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode)) ||
113f131759fSMateusz Guzik 	    fget(td, fd, cap_rights_init(&rights), &fp) != 0)
114060e4882SDoug Ambrisko 		return;
1150eee862aSEd Schouten 	vp = fp->f_vnode;
1160eee862aSEd Schouten 	if (vp != NULL && vp->v_rdev != NULL &&
1177870adb6SEd Schouten 	    linux_driver_get_major_minor(devtoname(vp->v_rdev),
118bc093719SEd Schouten 					 &major, &minor) == 0) {
119060e4882SDoug Ambrisko 		buf->st_rdev = (major << 8 | minor);
120bc093719SEd Schouten 	} else if (fp->f_type == DTYPE_PTS) {
121bc093719SEd Schouten 		struct tty *tp = fp->f_data;
122bc093719SEd Schouten 
123bc093719SEd Schouten 		/* Convert the numbers for the slave device. */
1247870adb6SEd Schouten 		if (linux_driver_get_major_minor(devtoname(tp->t_dev),
125bc093719SEd Schouten 					 &major, &minor) == 0) {
126bc093719SEd Schouten 			buf->st_rdev = (major << 8 | minor);
127bc093719SEd Schouten 		}
128bc093719SEd Schouten 	}
129060e4882SDoug Ambrisko 	fdrop(fp, td);
130060e4882SDoug Ambrisko }
131060e4882SDoug Ambrisko 
132bbbc2d96SPoul-Henning Kamp static int
133bbbc2d96SPoul-Henning Kamp newstat_copyout(struct stat *buf, void *ubuf)
134bbbc2d96SPoul-Henning Kamp {
135bbbc2d96SPoul-Henning Kamp 	struct l_newstat tbuf;
136bbbc2d96SPoul-Henning Kamp 
137bbbc2d96SPoul-Henning Kamp 	bzero(&tbuf, sizeof(tbuf));
138a4611ab6SEd Schouten 	tbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8);
139bbbc2d96SPoul-Henning Kamp 	tbuf.st_ino = buf->st_ino;
140bbbc2d96SPoul-Henning Kamp 	tbuf.st_mode = buf->st_mode;
141bbbc2d96SPoul-Henning Kamp 	tbuf.st_nlink = buf->st_nlink;
142bbbc2d96SPoul-Henning Kamp 	tbuf.st_uid = buf->st_uid;
143bbbc2d96SPoul-Henning Kamp 	tbuf.st_gid = buf->st_gid;
144bbbc2d96SPoul-Henning Kamp 	tbuf.st_rdev = buf->st_rdev;
145bbbc2d96SPoul-Henning Kamp 	tbuf.st_size = buf->st_size;
146510ea843SEd Schouten 	tbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
147510ea843SEd Schouten 	tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
148510ea843SEd Schouten 	tbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
149510ea843SEd Schouten 	tbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
150510ea843SEd Schouten 	tbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
151510ea843SEd Schouten 	tbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
152bbbc2d96SPoul-Henning Kamp 	tbuf.st_blksize = buf->st_blksize;
153bbbc2d96SPoul-Henning Kamp 	tbuf.st_blocks = buf->st_blocks;
154bbbc2d96SPoul-Henning Kamp 
1554e0eaf69SMarcel Moolenaar 	return (copyout(&tbuf, ubuf, sizeof(tbuf)));
156c21dee17SSøren Schmidt }
157c21dee17SSøren Schmidt 
158c21dee17SSøren Schmidt int
159b40ce416SJulian Elischer linux_newstat(struct thread *td, struct linux_newstat_args *args)
160c21dee17SSøren Schmidt {
161c21dee17SSøren Schmidt 	struct stat buf;
162206a5d3aSIan Dowse 	char *path;
163c21dee17SSøren Schmidt 	int error;
164d66a5066SPeter Wemm 
165206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->path, &path);
166c21dee17SSøren Schmidt 
167c21dee17SSøren Schmidt #ifdef DEBUG
16824593369SJonathan Lemon 	if (ldebug(newstat))
169206a5d3aSIan Dowse 		printf(ARGS(newstat, "%s, *"), path);
170c21dee17SSøren Schmidt #endif
1714e0eaf69SMarcel Moolenaar 
1720eee862aSEd Schouten 	error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
173206a5d3aSIan Dowse 	LFREEPATH(path);
1744e0eaf69SMarcel Moolenaar 	if (error)
1754e0eaf69SMarcel Moolenaar 		return (error);
1764e0eaf69SMarcel Moolenaar 	return (newstat_copyout(&buf, args->buf));
177c21dee17SSøren Schmidt }
178c21dee17SSøren Schmidt 
179c21dee17SSøren Schmidt int
180b40ce416SJulian Elischer linux_newlstat(struct thread *td, struct linux_newlstat_args *args)
181c21dee17SSøren Schmidt {
1824e0eaf69SMarcel Moolenaar 	struct stat sb;
183206a5d3aSIan Dowse 	char *path;
184f7a25872SJohn Baldwin 	int error;
185d66a5066SPeter Wemm 
186206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->path, &path);
187c21dee17SSøren Schmidt 
188c21dee17SSøren Schmidt #ifdef DEBUG
18924593369SJonathan Lemon 	if (ldebug(newlstat))
190206a5d3aSIan Dowse 		printf(ARGS(newlstat, "%s, *"), path);
191c21dee17SSøren Schmidt #endif
1924e0eaf69SMarcel Moolenaar 
1930eee862aSEd Schouten 	error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb);
194206a5d3aSIan Dowse 	LFREEPATH(path);
195d66a5066SPeter Wemm 	if (error)
196d66a5066SPeter Wemm 		return (error);
1975002a60fSMarcel Moolenaar 	return (newstat_copyout(&sb, args->buf));
198d66a5066SPeter Wemm }
199c21dee17SSøren Schmidt 
200c21dee17SSøren Schmidt int
201b40ce416SJulian Elischer linux_newfstat(struct thread *td, struct linux_newfstat_args *args)
202c21dee17SSøren Schmidt {
203c21dee17SSøren Schmidt 	struct stat buf;
204c21dee17SSøren Schmidt 	int error;
205c21dee17SSøren Schmidt 
206c21dee17SSøren Schmidt #ifdef DEBUG
20724593369SJonathan Lemon 	if (ldebug(newfstat))
20824593369SJonathan Lemon 		printf(ARGS(newfstat, "%d, *"), args->fd);
209c21dee17SSøren Schmidt #endif
2104e0eaf69SMarcel Moolenaar 
211f7a25872SJohn Baldwin 	error = kern_fstat(td, args->fd, &buf);
212060e4882SDoug Ambrisko 	translate_fd_major_minor(td, args->fd, &buf);
213c21dee17SSøren Schmidt 	if (!error)
214c21dee17SSøren Schmidt 		error = newstat_copyout(&buf, args->buf);
2154e0eaf69SMarcel Moolenaar 
2164e0eaf69SMarcel Moolenaar 	return (error);
217c21dee17SSøren Schmidt }
218c21dee17SSøren Schmidt 
2197f8f1d7fSDmitry Chagin #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
2205c8919adSAlexander Leidinger static int
2215c8919adSAlexander Leidinger stat_copyout(struct stat *buf, void *ubuf)
2225c8919adSAlexander Leidinger {
2235c8919adSAlexander Leidinger 	struct l_stat lbuf;
2245c8919adSAlexander Leidinger 
2255c8919adSAlexander Leidinger 	bzero(&lbuf, sizeof(lbuf));
2265c8919adSAlexander Leidinger 	lbuf.st_dev = buf->st_dev;
2275c8919adSAlexander Leidinger 	lbuf.st_ino = buf->st_ino;
2285c8919adSAlexander Leidinger 	lbuf.st_mode = buf->st_mode;
2295c8919adSAlexander Leidinger 	lbuf.st_nlink = buf->st_nlink;
2305c8919adSAlexander Leidinger 	lbuf.st_uid = buf->st_uid;
2315c8919adSAlexander Leidinger 	lbuf.st_gid = buf->st_gid;
2325c8919adSAlexander Leidinger 	lbuf.st_rdev = buf->st_rdev;
2335c8919adSAlexander Leidinger 	if (buf->st_size < (quad_t)1 << 32)
2345c8919adSAlexander Leidinger 		lbuf.st_size = buf->st_size;
2355c8919adSAlexander Leidinger 	else
2365c8919adSAlexander Leidinger 		lbuf.st_size = -2;
237510ea843SEd Schouten 	lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
238510ea843SEd Schouten 	lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
239510ea843SEd Schouten 	lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
240510ea843SEd Schouten 	lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
241510ea843SEd Schouten 	lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
242510ea843SEd Schouten 	lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
2435c8919adSAlexander Leidinger 	lbuf.st_blksize = buf->st_blksize;
2445c8919adSAlexander Leidinger 	lbuf.st_blocks = buf->st_blocks;
2455c8919adSAlexander Leidinger 	lbuf.st_flags = buf->st_flags;
2465c8919adSAlexander Leidinger 	lbuf.st_gen = buf->st_gen;
2475c8919adSAlexander Leidinger 
2485c8919adSAlexander Leidinger 	return (copyout(&lbuf, ubuf, sizeof(lbuf)));
2495c8919adSAlexander Leidinger }
2505c8919adSAlexander Leidinger 
2515c8919adSAlexander Leidinger int
2525c8919adSAlexander Leidinger linux_stat(struct thread *td, struct linux_stat_args *args)
2535c8919adSAlexander Leidinger {
2545c8919adSAlexander Leidinger 	struct stat buf;
25515b78ac5SKonstantin Belousov 	char *path;
2565c8919adSAlexander Leidinger 	int error;
25715b78ac5SKonstantin Belousov 
25815b78ac5SKonstantin Belousov 	LCONVPATHEXIST(td, args->path, &path);
25915b78ac5SKonstantin Belousov 
2605c8919adSAlexander Leidinger #ifdef DEBUG
2615c8919adSAlexander Leidinger 	if (ldebug(stat))
262d075105dSKonstantin Belousov 		printf(ARGS(stat, "%s, *"), path);
2635c8919adSAlexander Leidinger #endif
2640eee862aSEd Schouten 	error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
265d075105dSKonstantin Belousov 	if (error) {
26615b78ac5SKonstantin Belousov 		LFREEPATH(path);
2675c8919adSAlexander Leidinger 		return (error);
268d075105dSKonstantin Belousov 	}
269d075105dSKonstantin Belousov 	LFREEPATH(path);
2705c8919adSAlexander Leidinger 	return (stat_copyout(&buf, args->up));
2715c8919adSAlexander Leidinger }
2725c8919adSAlexander Leidinger 
2735c8919adSAlexander Leidinger int
2745c8919adSAlexander Leidinger linux_lstat(struct thread *td, struct linux_lstat_args *args)
2755c8919adSAlexander Leidinger {
2765c8919adSAlexander Leidinger 	struct stat buf;
27715b78ac5SKonstantin Belousov 	char *path;
2785c8919adSAlexander Leidinger 	int error;
2795c8919adSAlexander Leidinger 
28015b78ac5SKonstantin Belousov 	LCONVPATHEXIST(td, args->path, &path);
28115b78ac5SKonstantin Belousov 
2825c8919adSAlexander Leidinger #ifdef DEBUG
2835c8919adSAlexander Leidinger 	if (ldebug(lstat))
284d075105dSKonstantin Belousov 		printf(ARGS(lstat, "%s, *"), path);
2855c8919adSAlexander Leidinger #endif
2860eee862aSEd Schouten 	error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf);
287d075105dSKonstantin Belousov 	if (error) {
28815b78ac5SKonstantin Belousov 		LFREEPATH(path);
2895c8919adSAlexander Leidinger 		return (error);
290d075105dSKonstantin Belousov 	}
291d075105dSKonstantin Belousov 	LFREEPATH(path);
2925c8919adSAlexander Leidinger 	return (stat_copyout(&buf, args->up));
2935c8919adSAlexander Leidinger }
2947f8f1d7fSDmitry Chagin #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
2955c8919adSAlexander Leidinger 
2965002a60fSMarcel Moolenaar struct l_statfs {
297297f61ccSDmitry Chagin 	l_long		f_type;
298297f61ccSDmitry Chagin 	l_long		f_bsize;
299297f61ccSDmitry Chagin 	l_long		f_blocks;
300297f61ccSDmitry Chagin 	l_long		f_bfree;
301297f61ccSDmitry Chagin 	l_long		f_bavail;
302297f61ccSDmitry Chagin 	l_long		f_files;
303297f61ccSDmitry Chagin 	l_long		f_ffree;
3045002a60fSMarcel Moolenaar 	l_fsid_t	f_fsid;
305297f61ccSDmitry Chagin 	l_long		f_namelen;
306e801ac78SEdward Tomasz Napierala 	l_long		f_frsize;
307e801ac78SEdward Tomasz Napierala 	l_long		f_flags;
308e801ac78SEdward Tomasz Napierala 	l_long		f_spare[4];
309c21dee17SSøren Schmidt };
310c21dee17SSøren Schmidt 
311dca60efcSMarcel Moolenaar #define	LINUX_CODA_SUPER_MAGIC	0x73757245L
312dca60efcSMarcel Moolenaar #define	LINUX_EXT2_SUPER_MAGIC	0xEF53L
313dca60efcSMarcel Moolenaar #define	LINUX_HPFS_SUPER_MAGIC	0xf995e849L
314dca60efcSMarcel Moolenaar #define	LINUX_ISOFS_SUPER_MAGIC	0x9660L
315dca60efcSMarcel Moolenaar #define	LINUX_MSDOS_SUPER_MAGIC	0x4d44L
316dca60efcSMarcel Moolenaar #define	LINUX_NCP_SUPER_MAGIC	0x564cL
317dca60efcSMarcel Moolenaar #define	LINUX_NFS_SUPER_MAGIC	0x6969L
318dca60efcSMarcel Moolenaar #define	LINUX_NTFS_SUPER_MAGIC	0x5346544EL
319dca60efcSMarcel Moolenaar #define	LINUX_PROC_SUPER_MAGIC	0x9fa0L
320dca60efcSMarcel Moolenaar #define	LINUX_UFS_SUPER_MAGIC	0x00011954L	/* XXX - UFS_MAGIC in Linux */
321dbaa9ebfSEd Maste #define	LINUX_ZFS_SUPER_MAGIC	0x2FC12FC1
322e83d253bSOlivier Houchard #define	LINUX_DEVFS_SUPER_MAGIC	0x1373L
3232166e4e0SDmitry Chagin #define	LINUX_SHMFS_MAGIC	0x01021994
324dca60efcSMarcel Moolenaar 
325dca60efcSMarcel Moolenaar static long
326962cf420SMaxim Sobolev bsd_to_linux_ftype(const char *fstypename)
327dca60efcSMarcel Moolenaar {
328962cf420SMaxim Sobolev 	int i;
329962cf420SMaxim Sobolev 	static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = {
330962cf420SMaxim Sobolev 		{"ufs",     LINUX_UFS_SUPER_MAGIC},
331dbaa9ebfSEd Maste 		{"zfs",     LINUX_ZFS_SUPER_MAGIC},
332962cf420SMaxim Sobolev 		{"cd9660",  LINUX_ISOFS_SUPER_MAGIC},
333962cf420SMaxim Sobolev 		{"nfs",     LINUX_NFS_SUPER_MAGIC},
334962cf420SMaxim Sobolev 		{"ext2fs",  LINUX_EXT2_SUPER_MAGIC},
335962cf420SMaxim Sobolev 		{"procfs",  LINUX_PROC_SUPER_MAGIC},
336962cf420SMaxim Sobolev 		{"msdosfs", LINUX_MSDOS_SUPER_MAGIC},
337962cf420SMaxim Sobolev 		{"ntfs",    LINUX_NTFS_SUPER_MAGIC},
338962cf420SMaxim Sobolev 		{"nwfs",    LINUX_NCP_SUPER_MAGIC},
339962cf420SMaxim Sobolev 		{"hpfs",    LINUX_HPFS_SUPER_MAGIC},
340962cf420SMaxim Sobolev 		{"coda",    LINUX_CODA_SUPER_MAGIC},
341e83d253bSOlivier Houchard 		{"devfs",   LINUX_DEVFS_SUPER_MAGIC},
3422166e4e0SDmitry Chagin 		{"tmpfs",   LINUX_SHMFS_MAGIC},
343962cf420SMaxim Sobolev 		{NULL,      0L}};
344dca60efcSMarcel Moolenaar 
345962cf420SMaxim Sobolev 	for (i = 0; b2l_tbl[i].bsd_name != NULL; i++)
346962cf420SMaxim Sobolev 		if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0)
347962cf420SMaxim Sobolev 			return (b2l_tbl[i].linux_type);
348dca60efcSMarcel Moolenaar 
349dca60efcSMarcel Moolenaar 	return (0L);
350dca60efcSMarcel Moolenaar }
351dca60efcSMarcel Moolenaar 
352525c9796SDmitry Chagin static int
353d0cad55dSPawel Jakub Dawidek bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs)
354f7a25872SJohn Baldwin {
355525c9796SDmitry Chagin #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
356525c9796SDmitry Chagin 	uint64_t tmp;
357f7a25872SJohn Baldwin 
358525c9796SDmitry Chagin #define	LINUX_HIBITS	0xffffffff00000000ULL
359525c9796SDmitry Chagin 
360525c9796SDmitry Chagin 	tmp = bsd_statfs->f_blocks | bsd_statfs->f_bfree | bsd_statfs->f_files |
361525c9796SDmitry Chagin 	    bsd_statfs->f_bsize;
362525c9796SDmitry Chagin 	if ((bsd_statfs->f_bavail != -1 && (bsd_statfs->f_bavail & LINUX_HIBITS)) ||
363525c9796SDmitry Chagin 	    (bsd_statfs->f_ffree != -1 && (bsd_statfs->f_ffree & LINUX_HIBITS)) ||
364525c9796SDmitry Chagin 	    (tmp & LINUX_HIBITS))
365525c9796SDmitry Chagin 		return (EOVERFLOW);
366525c9796SDmitry Chagin #undef	LINUX_HIBITS
367525c9796SDmitry Chagin #endif
368f7a25872SJohn Baldwin 	linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
369f7a25872SJohn Baldwin 	linux_statfs->f_bsize = bsd_statfs->f_bsize;
370f7a25872SJohn Baldwin 	linux_statfs->f_blocks = bsd_statfs->f_blocks;
371f7a25872SJohn Baldwin 	linux_statfs->f_bfree = bsd_statfs->f_bfree;
372f7a25872SJohn Baldwin 	linux_statfs->f_bavail = bsd_statfs->f_bavail;
373f7a25872SJohn Baldwin 	linux_statfs->f_ffree = bsd_statfs->f_ffree;
374f7a25872SJohn Baldwin 	linux_statfs->f_files = bsd_statfs->f_files;
375f7a25872SJohn Baldwin 	linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
376f7a25872SJohn Baldwin 	linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
377f7a25872SJohn Baldwin 	linux_statfs->f_namelen = MAXNAMLEN;
378e801ac78SEdward Tomasz Napierala 	linux_statfs->f_frsize = bsd_statfs->f_bsize;
379e801ac78SEdward Tomasz Napierala 	linux_statfs->f_flags = 0;
380e801ac78SEdward Tomasz Napierala 	memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
381525c9796SDmitry Chagin 
382525c9796SDmitry Chagin 	return (0);
383f7a25872SJohn Baldwin }
384f7a25872SJohn Baldwin 
385c21dee17SSøren Schmidt int
386b40ce416SJulian Elischer linux_statfs(struct thread *td, struct linux_statfs_args *args)
387c21dee17SSøren Schmidt {
3885002a60fSMarcel Moolenaar 	struct l_statfs linux_statfs;
3892f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
390206a5d3aSIan Dowse 	char *path;
3912166e4e0SDmitry Chagin 	int error;
392d66a5066SPeter Wemm 
393206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->path, &path);
394c21dee17SSøren Schmidt 
395c21dee17SSøren Schmidt #ifdef DEBUG
39624593369SJonathan Lemon 	if (ldebug(statfs))
397206a5d3aSIan Dowse 		printf(ARGS(statfs, "%s, *"), path);
398c21dee17SSøren Schmidt #endif
3992f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4002f304845SKonstantin Belousov 	error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
401206a5d3aSIan Dowse 	LFREEPATH(path);
4022f304845SKonstantin Belousov 	if (error == 0)
4032f304845SKonstantin Belousov 		error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
4042f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
4052f304845SKonstantin Belousov 	if (error != 0)
4062ad02313SDmitry Chagin 		return (error);
4077958a34cSDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
408c21dee17SSøren Schmidt }
409c21dee17SSøren Schmidt 
4107f8f1d7fSDmitry Chagin #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
411835e5061SAlexander Leidinger static void
412835e5061SAlexander Leidinger bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs)
413835e5061SAlexander Leidinger {
414835e5061SAlexander Leidinger 
415835e5061SAlexander Leidinger 	linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
416835e5061SAlexander Leidinger 	linux_statfs->f_bsize = bsd_statfs->f_bsize;
417835e5061SAlexander Leidinger 	linux_statfs->f_blocks = bsd_statfs->f_blocks;
418835e5061SAlexander Leidinger 	linux_statfs->f_bfree = bsd_statfs->f_bfree;
419835e5061SAlexander Leidinger 	linux_statfs->f_bavail = bsd_statfs->f_bavail;
420835e5061SAlexander Leidinger 	linux_statfs->f_ffree = bsd_statfs->f_ffree;
421835e5061SAlexander Leidinger 	linux_statfs->f_files = bsd_statfs->f_files;
422835e5061SAlexander Leidinger 	linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
423835e5061SAlexander Leidinger 	linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
424835e5061SAlexander Leidinger 	linux_statfs->f_namelen = MAXNAMLEN;
425e801ac78SEdward Tomasz Napierala 	linux_statfs->f_frsize = bsd_statfs->f_bsize;
426e801ac78SEdward Tomasz Napierala 	linux_statfs->f_flags = 0;
427e801ac78SEdward Tomasz Napierala 	memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
428835e5061SAlexander Leidinger }
429835e5061SAlexander Leidinger 
430835e5061SAlexander Leidinger int
431835e5061SAlexander Leidinger linux_statfs64(struct thread *td, struct linux_statfs64_args *args)
432835e5061SAlexander Leidinger {
433835e5061SAlexander Leidinger 	struct l_statfs64 linux_statfs;
4342f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
435835e5061SAlexander Leidinger 	char *path;
436835e5061SAlexander Leidinger 	int error;
437835e5061SAlexander Leidinger 
4383ab85269SDavid Malone 	if (args->bufsize != sizeof(struct l_statfs64))
4393ab85269SDavid Malone 		return EINVAL;
4403ab85269SDavid Malone 
441835e5061SAlexander Leidinger 	LCONVPATHEXIST(td, args->path, &path);
442835e5061SAlexander Leidinger 
443835e5061SAlexander Leidinger #ifdef DEBUG
444835e5061SAlexander Leidinger 	if (ldebug(statfs64))
445835e5061SAlexander Leidinger 		printf(ARGS(statfs64, "%s, *"), path);
446835e5061SAlexander Leidinger #endif
4472f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4482f304845SKonstantin Belousov 	error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
449835e5061SAlexander Leidinger 	LFREEPATH(path);
4502f304845SKonstantin Belousov 	if (error == 0)
4512f304845SKonstantin Belousov 		bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
4522f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
4532f304845SKonstantin Belousov 	if (error != 0)
454835e5061SAlexander Leidinger 		return (error);
4557958a34cSDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
456835e5061SAlexander Leidinger }
45799546279SDmitry Chagin 
45899546279SDmitry Chagin int
45999546279SDmitry Chagin linux_fstatfs64(struct thread *td, struct linux_fstatfs64_args *args)
46099546279SDmitry Chagin {
46199546279SDmitry Chagin 	struct l_statfs64 linux_statfs;
4622f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
46399546279SDmitry Chagin 	int error;
46499546279SDmitry Chagin 
46599546279SDmitry Chagin #ifdef DEBUG
46699546279SDmitry Chagin 	if (ldebug(fstatfs64))
46799546279SDmitry Chagin 		printf(ARGS(fstatfs64, "%d, *"), args->fd);
46899546279SDmitry Chagin #endif
46999546279SDmitry Chagin 	if (args->bufsize != sizeof(struct l_statfs64))
47099546279SDmitry Chagin 		return (EINVAL);
47199546279SDmitry Chagin 
4722f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4732f304845SKonstantin Belousov 	error = kern_fstatfs(td, args->fd, bsd_statfs);
4742f304845SKonstantin Belousov 	if (error == 0)
4752f304845SKonstantin Belousov 		bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
4762f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
4772f304845SKonstantin Belousov 	if (error != 0)
4782f304845SKonstantin Belousov 		return (error);
47999546279SDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
48099546279SDmitry Chagin }
4817f8f1d7fSDmitry Chagin #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
482835e5061SAlexander Leidinger 
483c21dee17SSøren Schmidt int
484b40ce416SJulian Elischer linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args)
485c21dee17SSøren Schmidt {
4865002a60fSMarcel Moolenaar 	struct l_statfs linux_statfs;
4872f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
488c21dee17SSøren Schmidt 	int error;
489c21dee17SSøren Schmidt 
490c21dee17SSøren Schmidt #ifdef DEBUG
49124593369SJonathan Lemon 	if (ldebug(fstatfs))
49224593369SJonathan Lemon 		printf(ARGS(fstatfs, "%d, *"), args->fd);
493c21dee17SSøren Schmidt #endif
4942f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4952f304845SKonstantin Belousov 	error = kern_fstatfs(td, args->fd, bsd_statfs);
4962f304845SKonstantin Belousov 	if (error == 0)
4972f304845SKonstantin Belousov 		error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
4982f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
4992f304845SKonstantin Belousov 	if (error != 0)
5002ad02313SDmitry Chagin 		return (error);
5017958a34cSDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
502c21dee17SSøren Schmidt }
503408da119SMarcel Moolenaar 
5045002a60fSMarcel Moolenaar struct l_ustat
505408da119SMarcel Moolenaar {
5065002a60fSMarcel Moolenaar 	l_daddr_t	f_tfree;
5075002a60fSMarcel Moolenaar 	l_ino_t		f_tinode;
5085002a60fSMarcel Moolenaar 	char		f_fname[6];
5095002a60fSMarcel Moolenaar 	char		f_fpack[6];
5105002a60fSMarcel Moolenaar };
5115002a60fSMarcel Moolenaar 
5125002a60fSMarcel Moolenaar int
513b40ce416SJulian Elischer linux_ustat(struct thread *td, struct linux_ustat_args *args)
5145002a60fSMarcel Moolenaar {
5151e247cc2SPoul-Henning Kamp #ifdef DEBUG
5161e247cc2SPoul-Henning Kamp 	if (ldebug(ustat))
5174ca75bedSDmitry Chagin 		printf(ARGS(ustat, "%ju, *"), (uintmax_t)args->dev);
5181e247cc2SPoul-Henning Kamp #endif
5191e247cc2SPoul-Henning Kamp 
5201e247cc2SPoul-Henning Kamp 	return (EOPNOTSUPP);
521408da119SMarcel Moolenaar }
5225002a60fSMarcel Moolenaar 
5231997c537SDavid E. O'Brien #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
5245002a60fSMarcel Moolenaar 
5255002a60fSMarcel Moolenaar static int
5265002a60fSMarcel Moolenaar stat64_copyout(struct stat *buf, void *ubuf)
5275002a60fSMarcel Moolenaar {
5285002a60fSMarcel Moolenaar 	struct l_stat64 lbuf;
5295002a60fSMarcel Moolenaar 
5305002a60fSMarcel Moolenaar 	bzero(&lbuf, sizeof(lbuf));
531a4611ab6SEd Schouten 	lbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8);
5325002a60fSMarcel Moolenaar 	lbuf.st_ino = buf->st_ino;
5335002a60fSMarcel Moolenaar 	lbuf.st_mode = buf->st_mode;
5345002a60fSMarcel Moolenaar 	lbuf.st_nlink = buf->st_nlink;
5355002a60fSMarcel Moolenaar 	lbuf.st_uid = buf->st_uid;
5365002a60fSMarcel Moolenaar 	lbuf.st_gid = buf->st_gid;
5375002a60fSMarcel Moolenaar 	lbuf.st_rdev = buf->st_rdev;
5385002a60fSMarcel Moolenaar 	lbuf.st_size = buf->st_size;
539510ea843SEd Schouten 	lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
540510ea843SEd Schouten 	lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
541510ea843SEd Schouten 	lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
542510ea843SEd Schouten 	lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
543510ea843SEd Schouten 	lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
544510ea843SEd Schouten 	lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
5455002a60fSMarcel Moolenaar 	lbuf.st_blksize = buf->st_blksize;
5465002a60fSMarcel Moolenaar 	lbuf.st_blocks = buf->st_blocks;
5475002a60fSMarcel Moolenaar 
5485002a60fSMarcel Moolenaar 	/*
5495002a60fSMarcel Moolenaar 	 * The __st_ino field makes all the difference. In the Linux kernel
5505002a60fSMarcel Moolenaar 	 * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO,
5515002a60fSMarcel Moolenaar 	 * but without the assignment to __st_ino the runtime linker refuses
5525002a60fSMarcel Moolenaar 	 * to mmap(2) any shared libraries. I guess it's broken alright :-)
5535002a60fSMarcel Moolenaar 	 */
5545002a60fSMarcel Moolenaar 	lbuf.__st_ino = buf->st_ino;
5555002a60fSMarcel Moolenaar 
5565002a60fSMarcel Moolenaar 	return (copyout(&lbuf, ubuf, sizeof(lbuf)));
5575002a60fSMarcel Moolenaar }
5585002a60fSMarcel Moolenaar 
5595002a60fSMarcel Moolenaar int
560b40ce416SJulian Elischer linux_stat64(struct thread *td, struct linux_stat64_args *args)
5615002a60fSMarcel Moolenaar {
5625002a60fSMarcel Moolenaar 	struct stat buf;
563206a5d3aSIan Dowse 	char *filename;
564f7a25872SJohn Baldwin 	int error;
5655002a60fSMarcel Moolenaar 
566206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->filename, &filename);
5675002a60fSMarcel Moolenaar 
5685002a60fSMarcel Moolenaar #ifdef DEBUG
5695002a60fSMarcel Moolenaar 	if (ldebug(stat64))
570206a5d3aSIan Dowse 		printf(ARGS(stat64, "%s, *"), filename);
5715002a60fSMarcel Moolenaar #endif
5725002a60fSMarcel Moolenaar 
5730eee862aSEd Schouten 	error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf);
574206a5d3aSIan Dowse 	LFREEPATH(filename);
5755002a60fSMarcel Moolenaar 	if (error)
5765002a60fSMarcel Moolenaar 		return (error);
5775002a60fSMarcel Moolenaar 	return (stat64_copyout(&buf, args->statbuf));
5785002a60fSMarcel Moolenaar }
5795002a60fSMarcel Moolenaar 
5805002a60fSMarcel Moolenaar int
581b40ce416SJulian Elischer linux_lstat64(struct thread *td, struct linux_lstat64_args *args)
5825002a60fSMarcel Moolenaar {
5835002a60fSMarcel Moolenaar 	struct stat sb;
584206a5d3aSIan Dowse 	char *filename;
585f7a25872SJohn Baldwin 	int error;
5865002a60fSMarcel Moolenaar 
587206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->filename, &filename);
5885002a60fSMarcel Moolenaar 
5895002a60fSMarcel Moolenaar #ifdef DEBUG
5905002a60fSMarcel Moolenaar 	if (ldebug(lstat64))
5915002a60fSMarcel Moolenaar 		printf(ARGS(lstat64, "%s, *"), args->filename);
5925002a60fSMarcel Moolenaar #endif
5935002a60fSMarcel Moolenaar 
5940eee862aSEd Schouten 	error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb);
595206a5d3aSIan Dowse 	LFREEPATH(filename);
5965002a60fSMarcel Moolenaar 	if (error)
5975002a60fSMarcel Moolenaar 		return (error);
5985002a60fSMarcel Moolenaar 	return (stat64_copyout(&sb, args->statbuf));
5995002a60fSMarcel Moolenaar }
6005002a60fSMarcel Moolenaar 
6015002a60fSMarcel Moolenaar int
602b40ce416SJulian Elischer linux_fstat64(struct thread *td, struct linux_fstat64_args *args)
6035002a60fSMarcel Moolenaar {
6045002a60fSMarcel Moolenaar 	struct stat buf;
6055002a60fSMarcel Moolenaar 	int error;
6065002a60fSMarcel Moolenaar 
6075002a60fSMarcel Moolenaar #ifdef DEBUG
6085002a60fSMarcel Moolenaar 	if (ldebug(fstat64))
6095002a60fSMarcel Moolenaar 		printf(ARGS(fstat64, "%d, *"), args->fd);
6105002a60fSMarcel Moolenaar #endif
6115002a60fSMarcel Moolenaar 
612f7a25872SJohn Baldwin 	error = kern_fstat(td, args->fd, &buf);
613060e4882SDoug Ambrisko 	translate_fd_major_minor(td, args->fd, &buf);
6145002a60fSMarcel Moolenaar 	if (!error)
6155002a60fSMarcel Moolenaar 		error = stat64_copyout(&buf, args->statbuf);
6165002a60fSMarcel Moolenaar 
6175002a60fSMarcel Moolenaar 	return (error);
6185002a60fSMarcel Moolenaar }
6195002a60fSMarcel Moolenaar 
62048b05c3fSKonstantin Belousov int
62148b05c3fSKonstantin Belousov linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args)
62248b05c3fSKonstantin Belousov {
62348b05c3fSKonstantin Belousov 	char *path;
62448b05c3fSKonstantin Belousov 	int error, dfd, flag;
62548b05c3fSKonstantin Belousov 	struct stat buf;
62648b05c3fSKonstantin Belousov 
62748b05c3fSKonstantin Belousov 	if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW)
62848b05c3fSKonstantin Belousov 		return (EINVAL);
62948b05c3fSKonstantin Belousov 	flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
63048b05c3fSKonstantin Belousov 	    AT_SYMLINK_NOFOLLOW : 0;
63148b05c3fSKonstantin Belousov 
63248b05c3fSKonstantin Belousov 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
63348b05c3fSKonstantin Belousov 	LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
63448b05c3fSKonstantin Belousov 
63548b05c3fSKonstantin Belousov #ifdef DEBUG
63648b05c3fSKonstantin Belousov 	if (ldebug(fstatat64))
63748b05c3fSKonstantin Belousov 		printf(ARGS(fstatat64, "%i, %s, %i"), args->dfd, path, args->flag);
63848b05c3fSKonstantin Belousov #endif
63948b05c3fSKonstantin Belousov 
6400eee862aSEd Schouten 	error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
64148b05c3fSKonstantin Belousov 	if (!error)
64248b05c3fSKonstantin Belousov 		error = stat64_copyout(&buf, args->statbuf);
64348b05c3fSKonstantin Belousov 	LFREEPATH(path);
64448b05c3fSKonstantin Belousov 
64548b05c3fSKonstantin Belousov 	return (error);
64648b05c3fSKonstantin Belousov }
64748b05c3fSKonstantin Belousov 
648606bcc17SDmitry Chagin #else /* __amd64__ && !COMPAT_LINUX32 */
649606bcc17SDmitry Chagin 
650606bcc17SDmitry Chagin int
651606bcc17SDmitry Chagin linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args)
652606bcc17SDmitry Chagin {
653606bcc17SDmitry Chagin 	char *path;
654606bcc17SDmitry Chagin 	int error, dfd, flag;
655606bcc17SDmitry Chagin 	struct stat buf;
656606bcc17SDmitry Chagin 
657606bcc17SDmitry Chagin 	if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW)
658606bcc17SDmitry Chagin 		return (EINVAL);
659606bcc17SDmitry Chagin 	flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
660606bcc17SDmitry Chagin 	    AT_SYMLINK_NOFOLLOW : 0;
661606bcc17SDmitry Chagin 
662606bcc17SDmitry Chagin 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
663606bcc17SDmitry Chagin 	LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
664606bcc17SDmitry Chagin 
665606bcc17SDmitry Chagin #ifdef DEBUG
666606bcc17SDmitry Chagin 	if (ldebug(newfstatat))
667606bcc17SDmitry Chagin 		printf(ARGS(newfstatat, "%i, %s, %i"), args->dfd, path, args->flag);
668606bcc17SDmitry Chagin #endif
669606bcc17SDmitry Chagin 
670606bcc17SDmitry Chagin 	error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
671606bcc17SDmitry Chagin 	if (error == 0)
672606bcc17SDmitry Chagin 		error = newstat_copyout(&buf, args->statbuf);
673606bcc17SDmitry Chagin 	LFREEPATH(path);
674606bcc17SDmitry Chagin 
675606bcc17SDmitry Chagin 	return (error);
676606bcc17SDmitry Chagin }
677606bcc17SDmitry Chagin 
6781997c537SDavid E. O'Brien #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
6799802eb9eSDmitry Chagin 
6809802eb9eSDmitry Chagin int
6819802eb9eSDmitry Chagin linux_syncfs(struct thread *td, struct linux_syncfs_args *args)
6829802eb9eSDmitry Chagin {
6839802eb9eSDmitry Chagin 	cap_rights_t rights;
6849802eb9eSDmitry Chagin 	struct mount *mp;
6859802eb9eSDmitry Chagin 	struct vnode *vp;
6869802eb9eSDmitry Chagin 	int error, save;
6879802eb9eSDmitry Chagin 
6889802eb9eSDmitry Chagin 	error = fgetvp(td, args->fd, cap_rights_init(&rights, CAP_FSYNC), &vp);
6899802eb9eSDmitry Chagin 	if (error != 0)
6909802eb9eSDmitry Chagin 		/*
6919802eb9eSDmitry Chagin 		 * Linux syncfs() returns only EBADF, however fgetvp()
6929802eb9eSDmitry Chagin 		 * can return EINVAL in case of file descriptor does
6939802eb9eSDmitry Chagin 		 * not represent a vnode. XXX.
6949802eb9eSDmitry Chagin 		 */
6959802eb9eSDmitry Chagin 		return (error);
6969802eb9eSDmitry Chagin 
6979802eb9eSDmitry Chagin 	mp = vp->v_mount;
6989802eb9eSDmitry Chagin 	mtx_lock(&mountlist_mtx);
6999802eb9eSDmitry Chagin 	error = vfs_busy(mp, MBF_MNTLSTLOCK);
7009802eb9eSDmitry Chagin 	if (error != 0) {
7019802eb9eSDmitry Chagin 		/* See comment above. */
7029802eb9eSDmitry Chagin 		mtx_unlock(&mountlist_mtx);
7039802eb9eSDmitry Chagin 		goto out;
7049802eb9eSDmitry Chagin 	}
7059802eb9eSDmitry Chagin 	if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
7069802eb9eSDmitry Chagin 	    vn_start_write(NULL, &mp, V_NOWAIT) == 0) {
7079802eb9eSDmitry Chagin 		save = curthread_pflags_set(TDP_SYNCIO);
7089802eb9eSDmitry Chagin 		vfs_msync(mp, MNT_NOWAIT);
7099802eb9eSDmitry Chagin 		VFS_SYNC(mp, MNT_NOWAIT);
7109802eb9eSDmitry Chagin 		curthread_pflags_restore(save);
7119802eb9eSDmitry Chagin 		vn_finished_write(mp);
7129802eb9eSDmitry Chagin 	}
7139802eb9eSDmitry Chagin 	vfs_unbusy(mp);
7149802eb9eSDmitry Chagin 
7159802eb9eSDmitry Chagin  out:
7169802eb9eSDmitry Chagin 	vrele(vp);
7179802eb9eSDmitry Chagin 	return (error);
7189802eb9eSDmitry Chagin }
719