xref: /freebsd/sys/compat/linux/linux_stats.c (revision 7f2d13d60721803155950276e0282fcd1e6bacc3)
1c21dee17SSøren Schmidt /*-
2*7f2d13d6SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*7f2d13d6SPedro 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
11c21dee17SSøren Schmidt  *    notice, this list of conditions and the following disclaimer
12c21dee17SSøren Schmidt  *    in this position and unchanged.
13c21dee17SSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
14c21dee17SSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
15c21dee17SSøren Schmidt  *    documentation and/or other materials provided with the distribution.
16c21dee17SSøren Schmidt  * 3. The name of the author may not be used to endorse or promote products
1721dc7d4fSJens Schweikhardt  *    derived from this software without specific prior written permission
18c21dee17SSøren Schmidt  *
19c21dee17SSøren Schmidt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20c21dee17SSøren Schmidt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c21dee17SSøren Schmidt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22c21dee17SSøren Schmidt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23c21dee17SSøren Schmidt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24c21dee17SSøren Schmidt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25c21dee17SSøren Schmidt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26c21dee17SSøren Schmidt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27c21dee17SSøren Schmidt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28c21dee17SSøren Schmidt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c21dee17SSøren Schmidt  */
30c21dee17SSøren Schmidt 
3116dbc7f2SDavid E. O'Brien #include <sys/cdefs.h>
3216dbc7f2SDavid E. O'Brien __FBSDID("$FreeBSD$");
3316dbc7f2SDavid E. O'Brien 
34aefce619SRuslan Ermilov #include "opt_compat.h"
35eddc160eSRobert Watson 
36c21dee17SSøren Schmidt #include <sys/param.h>
379802eb9eSDmitry Chagin #include <sys/capsicum.h>
38c21dee17SSøren Schmidt #include <sys/dirent.h>
39c21dee17SSøren Schmidt #include <sys/file.h>
40c21dee17SSøren Schmidt #include <sys/filedesc.h>
41c21dee17SSøren Schmidt #include <sys/proc.h>
4285422e62SBruce Evans #include <sys/malloc.h>
43c21dee17SSøren Schmidt #include <sys/mount.h>
44c21dee17SSøren Schmidt #include <sys/namei.h>
45c21dee17SSøren Schmidt #include <sys/stat.h>
46f7a25872SJohn Baldwin #include <sys/syscallsubr.h>
47408da119SMarcel Moolenaar #include <sys/systm.h>
48bc093719SEd Schouten #include <sys/tty.h>
49c21dee17SSøren Schmidt #include <sys/vnode.h>
50060e4882SDoug Ambrisko #include <sys/conf.h>
51060e4882SDoug Ambrisko #include <sys/fcntl.h>
52c21dee17SSøren Schmidt 
531997c537SDavid E. O'Brien #ifdef COMPAT_LINUX32
544af27623STim J. Robbins #include <machine/../linux32/linux.h>
554af27623STim J. Robbins #include <machine/../linux32/linux32_proto.h>
561997c537SDavid E. O'Brien #else
571997c537SDavid E. O'Brien #include <machine/../linux/linux.h>
581997c537SDavid E. O'Brien #include <machine/../linux/linux_proto.h>
594af27623STim J. Robbins #endif
6085422e62SBruce Evans 
61ac951e62SMarcel Moolenaar #include <compat/linux/linux_util.h>
6248b05c3fSKonstantin Belousov #include <compat/linux/linux_file.h>
63762e6b85SEivind Eklund 
64529844c7SAlexander Leidinger 
650eee862aSEd Schouten static void
660eee862aSEd Schouten translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
670eee862aSEd Schouten {
680eee862aSEd Schouten 	int major, minor;
690eee862aSEd Schouten 
700eee862aSEd Schouten 	if (vp->v_type == VCHR && vp->v_rdev != NULL &&
717870adb6SEd Schouten 	    linux_driver_get_major_minor(devtoname(vp->v_rdev),
720eee862aSEd Schouten 	    &major, &minor) == 0) {
730eee862aSEd Schouten 		sb->st_rdev = (major << 8 | minor);
740eee862aSEd Schouten 	}
750eee862aSEd Schouten }
760eee862aSEd Schouten 
770eee862aSEd Schouten static int
780eee862aSEd Schouten linux_kern_statat(struct thread *td, int flag, int fd, char *path,
790eee862aSEd Schouten     enum uio_seg pathseg, struct stat *sbp)
800eee862aSEd Schouten {
810eee862aSEd Schouten 
826e646651SKonstantin Belousov 	return (kern_statat(td, flag, fd, path, pathseg, sbp,
830eee862aSEd Schouten 	    translate_vnhook_major_minor));
840eee862aSEd Schouten }
850eee862aSEd Schouten 
860eee862aSEd Schouten static int
870eee862aSEd Schouten linux_kern_stat(struct thread *td, char *path, enum uio_seg pathseg,
880eee862aSEd Schouten     struct stat *sbp)
890eee862aSEd Schouten {
900eee862aSEd Schouten 
910eee862aSEd Schouten 	return (linux_kern_statat(td, 0, AT_FDCWD, path, pathseg, sbp));
920eee862aSEd Schouten }
930eee862aSEd Schouten 
940eee862aSEd Schouten static int
950eee862aSEd Schouten linux_kern_lstat(struct thread *td, char *path, enum uio_seg pathseg,
960eee862aSEd Schouten     struct stat *sbp)
970eee862aSEd Schouten {
980eee862aSEd Schouten 
990eee862aSEd Schouten 	return (linux_kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
1000eee862aSEd Schouten 	    pathseg, sbp));
1010eee862aSEd Schouten }
1020eee862aSEd Schouten 
103060e4882SDoug Ambrisko static void
104060e4882SDoug Ambrisko translate_fd_major_minor(struct thread *td, int fd, struct stat *buf)
105060e4882SDoug Ambrisko {
106060e4882SDoug Ambrisko 	struct file *fp;
1070eee862aSEd Schouten 	struct vnode *vp;
108f131759fSMateusz Guzik 	cap_rights_t rights;
109060e4882SDoug Ambrisko 	int major, minor;
110060e4882SDoug Ambrisko 
111a9d2f8d8SRobert Watson 	/*
112a9d2f8d8SRobert Watson 	 * No capability rights required here.
113a9d2f8d8SRobert Watson 	 */
114b256a1e1SJung-uk Kim 	if ((!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode)) ||
115f131759fSMateusz Guzik 	    fget(td, fd, cap_rights_init(&rights), &fp) != 0)
116060e4882SDoug Ambrisko 		return;
1170eee862aSEd Schouten 	vp = fp->f_vnode;
1180eee862aSEd Schouten 	if (vp != NULL && vp->v_rdev != NULL &&
1197870adb6SEd Schouten 	    linux_driver_get_major_minor(devtoname(vp->v_rdev),
120bc093719SEd Schouten 					 &major, &minor) == 0) {
121060e4882SDoug Ambrisko 		buf->st_rdev = (major << 8 | minor);
122bc093719SEd Schouten 	} else if (fp->f_type == DTYPE_PTS) {
123bc093719SEd Schouten 		struct tty *tp = fp->f_data;
124bc093719SEd Schouten 
125bc093719SEd Schouten 		/* Convert the numbers for the slave device. */
1267870adb6SEd Schouten 		if (linux_driver_get_major_minor(devtoname(tp->t_dev),
127bc093719SEd Schouten 					 &major, &minor) == 0) {
128bc093719SEd Schouten 			buf->st_rdev = (major << 8 | minor);
129bc093719SEd Schouten 		}
130bc093719SEd Schouten 	}
131060e4882SDoug Ambrisko 	fdrop(fp, td);
132060e4882SDoug Ambrisko }
133060e4882SDoug Ambrisko 
134bbbc2d96SPoul-Henning Kamp static int
135bbbc2d96SPoul-Henning Kamp newstat_copyout(struct stat *buf, void *ubuf)
136bbbc2d96SPoul-Henning Kamp {
137bbbc2d96SPoul-Henning Kamp 	struct l_newstat tbuf;
138bbbc2d96SPoul-Henning Kamp 
139bbbc2d96SPoul-Henning Kamp 	bzero(&tbuf, sizeof(tbuf));
140a4611ab6SEd Schouten 	tbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8);
141bbbc2d96SPoul-Henning Kamp 	tbuf.st_ino = buf->st_ino;
142bbbc2d96SPoul-Henning Kamp 	tbuf.st_mode = buf->st_mode;
143bbbc2d96SPoul-Henning Kamp 	tbuf.st_nlink = buf->st_nlink;
144bbbc2d96SPoul-Henning Kamp 	tbuf.st_uid = buf->st_uid;
145bbbc2d96SPoul-Henning Kamp 	tbuf.st_gid = buf->st_gid;
146bbbc2d96SPoul-Henning Kamp 	tbuf.st_rdev = buf->st_rdev;
147bbbc2d96SPoul-Henning Kamp 	tbuf.st_size = buf->st_size;
148510ea843SEd Schouten 	tbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
149510ea843SEd Schouten 	tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
150510ea843SEd Schouten 	tbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
151510ea843SEd Schouten 	tbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
152510ea843SEd Schouten 	tbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
153510ea843SEd Schouten 	tbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
154bbbc2d96SPoul-Henning Kamp 	tbuf.st_blksize = buf->st_blksize;
155bbbc2d96SPoul-Henning Kamp 	tbuf.st_blocks = buf->st_blocks;
156bbbc2d96SPoul-Henning Kamp 
1574e0eaf69SMarcel Moolenaar 	return (copyout(&tbuf, ubuf, sizeof(tbuf)));
158c21dee17SSøren Schmidt }
159c21dee17SSøren Schmidt 
160c21dee17SSøren Schmidt int
161b40ce416SJulian Elischer linux_newstat(struct thread *td, struct linux_newstat_args *args)
162c21dee17SSøren Schmidt {
163c21dee17SSøren Schmidt 	struct stat buf;
164206a5d3aSIan Dowse 	char *path;
165c21dee17SSøren Schmidt 	int error;
166d66a5066SPeter Wemm 
167206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->path, &path);
168c21dee17SSøren Schmidt 
169c21dee17SSøren Schmidt #ifdef DEBUG
17024593369SJonathan Lemon 	if (ldebug(newstat))
171206a5d3aSIan Dowse 		printf(ARGS(newstat, "%s, *"), path);
172c21dee17SSøren Schmidt #endif
1734e0eaf69SMarcel Moolenaar 
1740eee862aSEd Schouten 	error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
175206a5d3aSIan Dowse 	LFREEPATH(path);
1764e0eaf69SMarcel Moolenaar 	if (error)
1774e0eaf69SMarcel Moolenaar 		return (error);
1784e0eaf69SMarcel Moolenaar 	return (newstat_copyout(&buf, args->buf));
179c21dee17SSøren Schmidt }
180c21dee17SSøren Schmidt 
181c21dee17SSøren Schmidt int
182b40ce416SJulian Elischer linux_newlstat(struct thread *td, struct linux_newlstat_args *args)
183c21dee17SSøren Schmidt {
1844e0eaf69SMarcel Moolenaar 	struct stat sb;
185206a5d3aSIan Dowse 	char *path;
186f7a25872SJohn Baldwin 	int error;
187d66a5066SPeter Wemm 
188206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->path, &path);
189c21dee17SSøren Schmidt 
190c21dee17SSøren Schmidt #ifdef DEBUG
19124593369SJonathan Lemon 	if (ldebug(newlstat))
192206a5d3aSIan Dowse 		printf(ARGS(newlstat, "%s, *"), path);
193c21dee17SSøren Schmidt #endif
1944e0eaf69SMarcel Moolenaar 
1950eee862aSEd Schouten 	error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb);
196206a5d3aSIan Dowse 	LFREEPATH(path);
197d66a5066SPeter Wemm 	if (error)
198d66a5066SPeter Wemm 		return (error);
1995002a60fSMarcel Moolenaar 	return (newstat_copyout(&sb, args->buf));
200d66a5066SPeter Wemm }
201c21dee17SSøren Schmidt 
202c21dee17SSøren Schmidt int
203b40ce416SJulian Elischer linux_newfstat(struct thread *td, struct linux_newfstat_args *args)
204c21dee17SSøren Schmidt {
205c21dee17SSøren Schmidt 	struct stat buf;
206c21dee17SSøren Schmidt 	int error;
207c21dee17SSøren Schmidt 
208c21dee17SSøren Schmidt #ifdef DEBUG
20924593369SJonathan Lemon 	if (ldebug(newfstat))
21024593369SJonathan Lemon 		printf(ARGS(newfstat, "%d, *"), args->fd);
211c21dee17SSøren Schmidt #endif
2124e0eaf69SMarcel Moolenaar 
213f7a25872SJohn Baldwin 	error = kern_fstat(td, args->fd, &buf);
214060e4882SDoug Ambrisko 	translate_fd_major_minor(td, args->fd, &buf);
215c21dee17SSøren Schmidt 	if (!error)
216c21dee17SSøren Schmidt 		error = newstat_copyout(&buf, args->buf);
2174e0eaf69SMarcel Moolenaar 
2184e0eaf69SMarcel Moolenaar 	return (error);
219c21dee17SSøren Schmidt }
220c21dee17SSøren Schmidt 
2217f8f1d7fSDmitry Chagin #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
2225c8919adSAlexander Leidinger static int
2235c8919adSAlexander Leidinger stat_copyout(struct stat *buf, void *ubuf)
2245c8919adSAlexander Leidinger {
2255c8919adSAlexander Leidinger 	struct l_stat lbuf;
2265c8919adSAlexander Leidinger 
2275c8919adSAlexander Leidinger 	bzero(&lbuf, sizeof(lbuf));
2285c8919adSAlexander Leidinger 	lbuf.st_dev = buf->st_dev;
2295c8919adSAlexander Leidinger 	lbuf.st_ino = buf->st_ino;
2305c8919adSAlexander Leidinger 	lbuf.st_mode = buf->st_mode;
2315c8919adSAlexander Leidinger 	lbuf.st_nlink = buf->st_nlink;
2325c8919adSAlexander Leidinger 	lbuf.st_uid = buf->st_uid;
2335c8919adSAlexander Leidinger 	lbuf.st_gid = buf->st_gid;
2345c8919adSAlexander Leidinger 	lbuf.st_rdev = buf->st_rdev;
2355c8919adSAlexander Leidinger 	if (buf->st_size < (quad_t)1 << 32)
2365c8919adSAlexander Leidinger 		lbuf.st_size = buf->st_size;
2375c8919adSAlexander Leidinger 	else
2385c8919adSAlexander Leidinger 		lbuf.st_size = -2;
239510ea843SEd Schouten 	lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
240510ea843SEd Schouten 	lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
241510ea843SEd Schouten 	lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
242510ea843SEd Schouten 	lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
243510ea843SEd Schouten 	lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
244510ea843SEd Schouten 	lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
2455c8919adSAlexander Leidinger 	lbuf.st_blksize = buf->st_blksize;
2465c8919adSAlexander Leidinger 	lbuf.st_blocks = buf->st_blocks;
2475c8919adSAlexander Leidinger 	lbuf.st_flags = buf->st_flags;
2485c8919adSAlexander Leidinger 	lbuf.st_gen = buf->st_gen;
2495c8919adSAlexander Leidinger 
2505c8919adSAlexander Leidinger 	return (copyout(&lbuf, ubuf, sizeof(lbuf)));
2515c8919adSAlexander Leidinger }
2525c8919adSAlexander Leidinger 
2535c8919adSAlexander Leidinger int
2545c8919adSAlexander Leidinger linux_stat(struct thread *td, struct linux_stat_args *args)
2555c8919adSAlexander Leidinger {
2565c8919adSAlexander Leidinger 	struct stat buf;
25715b78ac5SKonstantin Belousov 	char *path;
2585c8919adSAlexander Leidinger 	int error;
25915b78ac5SKonstantin Belousov 
26015b78ac5SKonstantin Belousov 	LCONVPATHEXIST(td, args->path, &path);
26115b78ac5SKonstantin Belousov 
2625c8919adSAlexander Leidinger #ifdef DEBUG
2635c8919adSAlexander Leidinger 	if (ldebug(stat))
264d075105dSKonstantin Belousov 		printf(ARGS(stat, "%s, *"), path);
2655c8919adSAlexander Leidinger #endif
2660eee862aSEd Schouten 	error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
267d075105dSKonstantin Belousov 	if (error) {
26815b78ac5SKonstantin Belousov 		LFREEPATH(path);
2695c8919adSAlexander Leidinger 		return (error);
270d075105dSKonstantin Belousov 	}
271d075105dSKonstantin Belousov 	LFREEPATH(path);
2725c8919adSAlexander Leidinger 	return (stat_copyout(&buf, args->up));
2735c8919adSAlexander Leidinger }
2745c8919adSAlexander Leidinger 
2755c8919adSAlexander Leidinger int
2765c8919adSAlexander Leidinger linux_lstat(struct thread *td, struct linux_lstat_args *args)
2775c8919adSAlexander Leidinger {
2785c8919adSAlexander Leidinger 	struct stat buf;
27915b78ac5SKonstantin Belousov 	char *path;
2805c8919adSAlexander Leidinger 	int error;
2815c8919adSAlexander Leidinger 
28215b78ac5SKonstantin Belousov 	LCONVPATHEXIST(td, args->path, &path);
28315b78ac5SKonstantin Belousov 
2845c8919adSAlexander Leidinger #ifdef DEBUG
2855c8919adSAlexander Leidinger 	if (ldebug(lstat))
286d075105dSKonstantin Belousov 		printf(ARGS(lstat, "%s, *"), path);
2875c8919adSAlexander Leidinger #endif
2880eee862aSEd Schouten 	error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf);
289d075105dSKonstantin Belousov 	if (error) {
29015b78ac5SKonstantin Belousov 		LFREEPATH(path);
2915c8919adSAlexander Leidinger 		return (error);
292d075105dSKonstantin Belousov 	}
293d075105dSKonstantin Belousov 	LFREEPATH(path);
2945c8919adSAlexander Leidinger 	return (stat_copyout(&buf, args->up));
2955c8919adSAlexander Leidinger }
2967f8f1d7fSDmitry Chagin #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
2975c8919adSAlexander Leidinger 
2985002a60fSMarcel Moolenaar struct l_statfs {
299297f61ccSDmitry Chagin 	l_long		f_type;
300297f61ccSDmitry Chagin 	l_long		f_bsize;
301297f61ccSDmitry Chagin 	l_long		f_blocks;
302297f61ccSDmitry Chagin 	l_long		f_bfree;
303297f61ccSDmitry Chagin 	l_long		f_bavail;
304297f61ccSDmitry Chagin 	l_long		f_files;
305297f61ccSDmitry Chagin 	l_long		f_ffree;
3065002a60fSMarcel Moolenaar 	l_fsid_t	f_fsid;
307297f61ccSDmitry Chagin 	l_long		f_namelen;
308e801ac78SEdward Tomasz Napierala 	l_long		f_frsize;
309e801ac78SEdward Tomasz Napierala 	l_long		f_flags;
310e801ac78SEdward Tomasz Napierala 	l_long		f_spare[4];
311c21dee17SSøren Schmidt };
312c21dee17SSøren Schmidt 
313dca60efcSMarcel Moolenaar #define	LINUX_CODA_SUPER_MAGIC	0x73757245L
314dca60efcSMarcel Moolenaar #define	LINUX_EXT2_SUPER_MAGIC	0xEF53L
315dca60efcSMarcel Moolenaar #define	LINUX_HPFS_SUPER_MAGIC	0xf995e849L
316dca60efcSMarcel Moolenaar #define	LINUX_ISOFS_SUPER_MAGIC	0x9660L
317dca60efcSMarcel Moolenaar #define	LINUX_MSDOS_SUPER_MAGIC	0x4d44L
318dca60efcSMarcel Moolenaar #define	LINUX_NCP_SUPER_MAGIC	0x564cL
319dca60efcSMarcel Moolenaar #define	LINUX_NFS_SUPER_MAGIC	0x6969L
320dca60efcSMarcel Moolenaar #define	LINUX_NTFS_SUPER_MAGIC	0x5346544EL
321dca60efcSMarcel Moolenaar #define	LINUX_PROC_SUPER_MAGIC	0x9fa0L
322dca60efcSMarcel Moolenaar #define	LINUX_UFS_SUPER_MAGIC	0x00011954L	/* XXX - UFS_MAGIC in Linux */
323dbaa9ebfSEd Maste #define	LINUX_ZFS_SUPER_MAGIC	0x2FC12FC1
324e83d253bSOlivier Houchard #define	LINUX_DEVFS_SUPER_MAGIC	0x1373L
3252166e4e0SDmitry Chagin #define	LINUX_SHMFS_MAGIC	0x01021994
326dca60efcSMarcel Moolenaar 
327dca60efcSMarcel Moolenaar static long
328962cf420SMaxim Sobolev bsd_to_linux_ftype(const char *fstypename)
329dca60efcSMarcel Moolenaar {
330962cf420SMaxim Sobolev 	int i;
331962cf420SMaxim Sobolev 	static struct {const char *bsd_name; long linux_type;} b2l_tbl[] = {
332962cf420SMaxim Sobolev 		{"ufs",     LINUX_UFS_SUPER_MAGIC},
333dbaa9ebfSEd Maste 		{"zfs",     LINUX_ZFS_SUPER_MAGIC},
334962cf420SMaxim Sobolev 		{"cd9660",  LINUX_ISOFS_SUPER_MAGIC},
335962cf420SMaxim Sobolev 		{"nfs",     LINUX_NFS_SUPER_MAGIC},
336962cf420SMaxim Sobolev 		{"ext2fs",  LINUX_EXT2_SUPER_MAGIC},
337962cf420SMaxim Sobolev 		{"procfs",  LINUX_PROC_SUPER_MAGIC},
338962cf420SMaxim Sobolev 		{"msdosfs", LINUX_MSDOS_SUPER_MAGIC},
339962cf420SMaxim Sobolev 		{"ntfs",    LINUX_NTFS_SUPER_MAGIC},
340962cf420SMaxim Sobolev 		{"nwfs",    LINUX_NCP_SUPER_MAGIC},
341962cf420SMaxim Sobolev 		{"hpfs",    LINUX_HPFS_SUPER_MAGIC},
342962cf420SMaxim Sobolev 		{"coda",    LINUX_CODA_SUPER_MAGIC},
343e83d253bSOlivier Houchard 		{"devfs",   LINUX_DEVFS_SUPER_MAGIC},
3442166e4e0SDmitry Chagin 		{"tmpfs",   LINUX_SHMFS_MAGIC},
345962cf420SMaxim Sobolev 		{NULL,      0L}};
346dca60efcSMarcel Moolenaar 
347962cf420SMaxim Sobolev 	for (i = 0; b2l_tbl[i].bsd_name != NULL; i++)
348962cf420SMaxim Sobolev 		if (strcmp(b2l_tbl[i].bsd_name, fstypename) == 0)
349962cf420SMaxim Sobolev 			return (b2l_tbl[i].linux_type);
350dca60efcSMarcel Moolenaar 
351dca60efcSMarcel Moolenaar 	return (0L);
352dca60efcSMarcel Moolenaar }
353dca60efcSMarcel Moolenaar 
354525c9796SDmitry Chagin static int
355d0cad55dSPawel Jakub Dawidek bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs)
356f7a25872SJohn Baldwin {
357525c9796SDmitry Chagin #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
358525c9796SDmitry Chagin 	uint64_t tmp;
359f7a25872SJohn Baldwin 
360525c9796SDmitry Chagin #define	LINUX_HIBITS	0xffffffff00000000ULL
361525c9796SDmitry Chagin 
362525c9796SDmitry Chagin 	tmp = bsd_statfs->f_blocks | bsd_statfs->f_bfree | bsd_statfs->f_files |
363525c9796SDmitry Chagin 	    bsd_statfs->f_bsize;
364525c9796SDmitry Chagin 	if ((bsd_statfs->f_bavail != -1 && (bsd_statfs->f_bavail & LINUX_HIBITS)) ||
365525c9796SDmitry Chagin 	    (bsd_statfs->f_ffree != -1 && (bsd_statfs->f_ffree & LINUX_HIBITS)) ||
366525c9796SDmitry Chagin 	    (tmp & LINUX_HIBITS))
367525c9796SDmitry Chagin 		return (EOVERFLOW);
368525c9796SDmitry Chagin #undef	LINUX_HIBITS
369525c9796SDmitry Chagin #endif
370f7a25872SJohn Baldwin 	linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
371f7a25872SJohn Baldwin 	linux_statfs->f_bsize = bsd_statfs->f_bsize;
372f7a25872SJohn Baldwin 	linux_statfs->f_blocks = bsd_statfs->f_blocks;
373f7a25872SJohn Baldwin 	linux_statfs->f_bfree = bsd_statfs->f_bfree;
374f7a25872SJohn Baldwin 	linux_statfs->f_bavail = bsd_statfs->f_bavail;
375f7a25872SJohn Baldwin 	linux_statfs->f_ffree = bsd_statfs->f_ffree;
376f7a25872SJohn Baldwin 	linux_statfs->f_files = bsd_statfs->f_files;
377f7a25872SJohn Baldwin 	linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
378f7a25872SJohn Baldwin 	linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
379f7a25872SJohn Baldwin 	linux_statfs->f_namelen = MAXNAMLEN;
380e801ac78SEdward Tomasz Napierala 	linux_statfs->f_frsize = bsd_statfs->f_bsize;
381e801ac78SEdward Tomasz Napierala 	linux_statfs->f_flags = 0;
382e801ac78SEdward Tomasz Napierala 	memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
383525c9796SDmitry Chagin 
384525c9796SDmitry Chagin 	return (0);
385f7a25872SJohn Baldwin }
386f7a25872SJohn Baldwin 
387c21dee17SSøren Schmidt int
388b40ce416SJulian Elischer linux_statfs(struct thread *td, struct linux_statfs_args *args)
389c21dee17SSøren Schmidt {
3905002a60fSMarcel Moolenaar 	struct l_statfs linux_statfs;
3912f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
392206a5d3aSIan Dowse 	char *path;
3932166e4e0SDmitry Chagin 	int error;
394d66a5066SPeter Wemm 
395206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->path, &path);
396c21dee17SSøren Schmidt 
397c21dee17SSøren Schmidt #ifdef DEBUG
39824593369SJonathan Lemon 	if (ldebug(statfs))
399206a5d3aSIan Dowse 		printf(ARGS(statfs, "%s, *"), path);
400c21dee17SSøren Schmidt #endif
4012f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4022f304845SKonstantin Belousov 	error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
403206a5d3aSIan Dowse 	LFREEPATH(path);
4042f304845SKonstantin Belousov 	if (error == 0)
4052f304845SKonstantin Belousov 		error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
4062f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
4072f304845SKonstantin Belousov 	if (error != 0)
4082ad02313SDmitry Chagin 		return (error);
4097958a34cSDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
410c21dee17SSøren Schmidt }
411c21dee17SSøren Schmidt 
4127f8f1d7fSDmitry Chagin #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
413835e5061SAlexander Leidinger static void
414835e5061SAlexander Leidinger bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs)
415835e5061SAlexander Leidinger {
416835e5061SAlexander Leidinger 
417835e5061SAlexander Leidinger 	linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
418835e5061SAlexander Leidinger 	linux_statfs->f_bsize = bsd_statfs->f_bsize;
419835e5061SAlexander Leidinger 	linux_statfs->f_blocks = bsd_statfs->f_blocks;
420835e5061SAlexander Leidinger 	linux_statfs->f_bfree = bsd_statfs->f_bfree;
421835e5061SAlexander Leidinger 	linux_statfs->f_bavail = bsd_statfs->f_bavail;
422835e5061SAlexander Leidinger 	linux_statfs->f_ffree = bsd_statfs->f_ffree;
423835e5061SAlexander Leidinger 	linux_statfs->f_files = bsd_statfs->f_files;
424835e5061SAlexander Leidinger 	linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
425835e5061SAlexander Leidinger 	linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
426835e5061SAlexander Leidinger 	linux_statfs->f_namelen = MAXNAMLEN;
427e801ac78SEdward Tomasz Napierala 	linux_statfs->f_frsize = bsd_statfs->f_bsize;
428e801ac78SEdward Tomasz Napierala 	linux_statfs->f_flags = 0;
429e801ac78SEdward Tomasz Napierala 	memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
430835e5061SAlexander Leidinger }
431835e5061SAlexander Leidinger 
432835e5061SAlexander Leidinger int
433835e5061SAlexander Leidinger linux_statfs64(struct thread *td, struct linux_statfs64_args *args)
434835e5061SAlexander Leidinger {
435835e5061SAlexander Leidinger 	struct l_statfs64 linux_statfs;
4362f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
437835e5061SAlexander Leidinger 	char *path;
438835e5061SAlexander Leidinger 	int error;
439835e5061SAlexander Leidinger 
4403ab85269SDavid Malone 	if (args->bufsize != sizeof(struct l_statfs64))
4413ab85269SDavid Malone 		return EINVAL;
4423ab85269SDavid Malone 
443835e5061SAlexander Leidinger 	LCONVPATHEXIST(td, args->path, &path);
444835e5061SAlexander Leidinger 
445835e5061SAlexander Leidinger #ifdef DEBUG
446835e5061SAlexander Leidinger 	if (ldebug(statfs64))
447835e5061SAlexander Leidinger 		printf(ARGS(statfs64, "%s, *"), path);
448835e5061SAlexander Leidinger #endif
4492f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4502f304845SKonstantin Belousov 	error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
451835e5061SAlexander Leidinger 	LFREEPATH(path);
4522f304845SKonstantin Belousov 	if (error == 0)
4532f304845SKonstantin Belousov 		bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
4542f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
4552f304845SKonstantin Belousov 	if (error != 0)
456835e5061SAlexander Leidinger 		return (error);
4577958a34cSDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
458835e5061SAlexander Leidinger }
45999546279SDmitry Chagin 
46099546279SDmitry Chagin int
46199546279SDmitry Chagin linux_fstatfs64(struct thread *td, struct linux_fstatfs64_args *args)
46299546279SDmitry Chagin {
46399546279SDmitry Chagin 	struct l_statfs64 linux_statfs;
4642f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
46599546279SDmitry Chagin 	int error;
46699546279SDmitry Chagin 
46799546279SDmitry Chagin #ifdef DEBUG
46899546279SDmitry Chagin 	if (ldebug(fstatfs64))
46999546279SDmitry Chagin 		printf(ARGS(fstatfs64, "%d, *"), args->fd);
47099546279SDmitry Chagin #endif
47199546279SDmitry Chagin 	if (args->bufsize != sizeof(struct l_statfs64))
47299546279SDmitry Chagin 		return (EINVAL);
47399546279SDmitry Chagin 
4742f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4752f304845SKonstantin Belousov 	error = kern_fstatfs(td, args->fd, bsd_statfs);
4762f304845SKonstantin Belousov 	if (error == 0)
4772f304845SKonstantin Belousov 		bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
4782f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
4792f304845SKonstantin Belousov 	if (error != 0)
4802f304845SKonstantin Belousov 		return (error);
48199546279SDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
48299546279SDmitry Chagin }
4837f8f1d7fSDmitry Chagin #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
484835e5061SAlexander Leidinger 
485c21dee17SSøren Schmidt int
486b40ce416SJulian Elischer linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args)
487c21dee17SSøren Schmidt {
4885002a60fSMarcel Moolenaar 	struct l_statfs linux_statfs;
4892f304845SKonstantin Belousov 	struct statfs *bsd_statfs;
490c21dee17SSøren Schmidt 	int error;
491c21dee17SSøren Schmidt 
492c21dee17SSøren Schmidt #ifdef DEBUG
49324593369SJonathan Lemon 	if (ldebug(fstatfs))
49424593369SJonathan Lemon 		printf(ARGS(fstatfs, "%d, *"), args->fd);
495c21dee17SSøren Schmidt #endif
4962f304845SKonstantin Belousov 	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
4972f304845SKonstantin Belousov 	error = kern_fstatfs(td, args->fd, bsd_statfs);
4982f304845SKonstantin Belousov 	if (error == 0)
4992f304845SKonstantin Belousov 		error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
5002f304845SKonstantin Belousov 	free(bsd_statfs, M_STATFS);
5012f304845SKonstantin Belousov 	if (error != 0)
5022ad02313SDmitry Chagin 		return (error);
5037958a34cSDmitry Chagin 	return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
504c21dee17SSøren Schmidt }
505408da119SMarcel Moolenaar 
5065002a60fSMarcel Moolenaar struct l_ustat
507408da119SMarcel Moolenaar {
5085002a60fSMarcel Moolenaar 	l_daddr_t	f_tfree;
5095002a60fSMarcel Moolenaar 	l_ino_t		f_tinode;
5105002a60fSMarcel Moolenaar 	char		f_fname[6];
5115002a60fSMarcel Moolenaar 	char		f_fpack[6];
5125002a60fSMarcel Moolenaar };
5135002a60fSMarcel Moolenaar 
5145002a60fSMarcel Moolenaar int
515b40ce416SJulian Elischer linux_ustat(struct thread *td, struct linux_ustat_args *args)
5165002a60fSMarcel Moolenaar {
5171e247cc2SPoul-Henning Kamp #ifdef DEBUG
5181e247cc2SPoul-Henning Kamp 	if (ldebug(ustat))
5194ca75bedSDmitry Chagin 		printf(ARGS(ustat, "%ju, *"), (uintmax_t)args->dev);
5201e247cc2SPoul-Henning Kamp #endif
5211e247cc2SPoul-Henning Kamp 
5221e247cc2SPoul-Henning Kamp 	return (EOPNOTSUPP);
523408da119SMarcel Moolenaar }
5245002a60fSMarcel Moolenaar 
5251997c537SDavid E. O'Brien #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
5265002a60fSMarcel Moolenaar 
5275002a60fSMarcel Moolenaar static int
5285002a60fSMarcel Moolenaar stat64_copyout(struct stat *buf, void *ubuf)
5295002a60fSMarcel Moolenaar {
5305002a60fSMarcel Moolenaar 	struct l_stat64 lbuf;
5315002a60fSMarcel Moolenaar 
5325002a60fSMarcel Moolenaar 	bzero(&lbuf, sizeof(lbuf));
533a4611ab6SEd Schouten 	lbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8);
5345002a60fSMarcel Moolenaar 	lbuf.st_ino = buf->st_ino;
5355002a60fSMarcel Moolenaar 	lbuf.st_mode = buf->st_mode;
5365002a60fSMarcel Moolenaar 	lbuf.st_nlink = buf->st_nlink;
5375002a60fSMarcel Moolenaar 	lbuf.st_uid = buf->st_uid;
5385002a60fSMarcel Moolenaar 	lbuf.st_gid = buf->st_gid;
5395002a60fSMarcel Moolenaar 	lbuf.st_rdev = buf->st_rdev;
5405002a60fSMarcel Moolenaar 	lbuf.st_size = buf->st_size;
541510ea843SEd Schouten 	lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
542510ea843SEd Schouten 	lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
543510ea843SEd Schouten 	lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
544510ea843SEd Schouten 	lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
545510ea843SEd Schouten 	lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
546510ea843SEd Schouten 	lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
5475002a60fSMarcel Moolenaar 	lbuf.st_blksize = buf->st_blksize;
5485002a60fSMarcel Moolenaar 	lbuf.st_blocks = buf->st_blocks;
5495002a60fSMarcel Moolenaar 
5505002a60fSMarcel Moolenaar 	/*
5515002a60fSMarcel Moolenaar 	 * The __st_ino field makes all the difference. In the Linux kernel
5525002a60fSMarcel Moolenaar 	 * it is conditionally compiled based on STAT64_HAS_BROKEN_ST_INO,
5535002a60fSMarcel Moolenaar 	 * but without the assignment to __st_ino the runtime linker refuses
5545002a60fSMarcel Moolenaar 	 * to mmap(2) any shared libraries. I guess it's broken alright :-)
5555002a60fSMarcel Moolenaar 	 */
5565002a60fSMarcel Moolenaar 	lbuf.__st_ino = buf->st_ino;
5575002a60fSMarcel Moolenaar 
5585002a60fSMarcel Moolenaar 	return (copyout(&lbuf, ubuf, sizeof(lbuf)));
5595002a60fSMarcel Moolenaar }
5605002a60fSMarcel Moolenaar 
5615002a60fSMarcel Moolenaar int
562b40ce416SJulian Elischer linux_stat64(struct thread *td, struct linux_stat64_args *args)
5635002a60fSMarcel Moolenaar {
5645002a60fSMarcel Moolenaar 	struct stat buf;
565206a5d3aSIan Dowse 	char *filename;
566f7a25872SJohn Baldwin 	int error;
5675002a60fSMarcel Moolenaar 
568206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->filename, &filename);
5695002a60fSMarcel Moolenaar 
5705002a60fSMarcel Moolenaar #ifdef DEBUG
5715002a60fSMarcel Moolenaar 	if (ldebug(stat64))
572206a5d3aSIan Dowse 		printf(ARGS(stat64, "%s, *"), filename);
5735002a60fSMarcel Moolenaar #endif
5745002a60fSMarcel Moolenaar 
5750eee862aSEd Schouten 	error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf);
576206a5d3aSIan Dowse 	LFREEPATH(filename);
5775002a60fSMarcel Moolenaar 	if (error)
5785002a60fSMarcel Moolenaar 		return (error);
5795002a60fSMarcel Moolenaar 	return (stat64_copyout(&buf, args->statbuf));
5805002a60fSMarcel Moolenaar }
5815002a60fSMarcel Moolenaar 
5825002a60fSMarcel Moolenaar int
583b40ce416SJulian Elischer linux_lstat64(struct thread *td, struct linux_lstat64_args *args)
5845002a60fSMarcel Moolenaar {
5855002a60fSMarcel Moolenaar 	struct stat sb;
586206a5d3aSIan Dowse 	char *filename;
587f7a25872SJohn Baldwin 	int error;
5885002a60fSMarcel Moolenaar 
589206a5d3aSIan Dowse 	LCONVPATHEXIST(td, args->filename, &filename);
5905002a60fSMarcel Moolenaar 
5915002a60fSMarcel Moolenaar #ifdef DEBUG
5925002a60fSMarcel Moolenaar 	if (ldebug(lstat64))
5935002a60fSMarcel Moolenaar 		printf(ARGS(lstat64, "%s, *"), args->filename);
5945002a60fSMarcel Moolenaar #endif
5955002a60fSMarcel Moolenaar 
5960eee862aSEd Schouten 	error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb);
597206a5d3aSIan Dowse 	LFREEPATH(filename);
5985002a60fSMarcel Moolenaar 	if (error)
5995002a60fSMarcel Moolenaar 		return (error);
6005002a60fSMarcel Moolenaar 	return (stat64_copyout(&sb, args->statbuf));
6015002a60fSMarcel Moolenaar }
6025002a60fSMarcel Moolenaar 
6035002a60fSMarcel Moolenaar int
604b40ce416SJulian Elischer linux_fstat64(struct thread *td, struct linux_fstat64_args *args)
6055002a60fSMarcel Moolenaar {
6065002a60fSMarcel Moolenaar 	struct stat buf;
6075002a60fSMarcel Moolenaar 	int error;
6085002a60fSMarcel Moolenaar 
6095002a60fSMarcel Moolenaar #ifdef DEBUG
6105002a60fSMarcel Moolenaar 	if (ldebug(fstat64))
6115002a60fSMarcel Moolenaar 		printf(ARGS(fstat64, "%d, *"), args->fd);
6125002a60fSMarcel Moolenaar #endif
6135002a60fSMarcel Moolenaar 
614f7a25872SJohn Baldwin 	error = kern_fstat(td, args->fd, &buf);
615060e4882SDoug Ambrisko 	translate_fd_major_minor(td, args->fd, &buf);
6165002a60fSMarcel Moolenaar 	if (!error)
6175002a60fSMarcel Moolenaar 		error = stat64_copyout(&buf, args->statbuf);
6185002a60fSMarcel Moolenaar 
6195002a60fSMarcel Moolenaar 	return (error);
6205002a60fSMarcel Moolenaar }
6215002a60fSMarcel Moolenaar 
62248b05c3fSKonstantin Belousov int
62348b05c3fSKonstantin Belousov linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args)
62448b05c3fSKonstantin Belousov {
62548b05c3fSKonstantin Belousov 	char *path;
62648b05c3fSKonstantin Belousov 	int error, dfd, flag;
62748b05c3fSKonstantin Belousov 	struct stat buf;
62848b05c3fSKonstantin Belousov 
62948b05c3fSKonstantin Belousov 	if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW)
63048b05c3fSKonstantin Belousov 		return (EINVAL);
63148b05c3fSKonstantin Belousov 	flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
63248b05c3fSKonstantin Belousov 	    AT_SYMLINK_NOFOLLOW : 0;
63348b05c3fSKonstantin Belousov 
63448b05c3fSKonstantin Belousov 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
63548b05c3fSKonstantin Belousov 	LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
63648b05c3fSKonstantin Belousov 
63748b05c3fSKonstantin Belousov #ifdef DEBUG
63848b05c3fSKonstantin Belousov 	if (ldebug(fstatat64))
63948b05c3fSKonstantin Belousov 		printf(ARGS(fstatat64, "%i, %s, %i"), args->dfd, path, args->flag);
64048b05c3fSKonstantin Belousov #endif
64148b05c3fSKonstantin Belousov 
6420eee862aSEd Schouten 	error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
64348b05c3fSKonstantin Belousov 	if (!error)
64448b05c3fSKonstantin Belousov 		error = stat64_copyout(&buf, args->statbuf);
64548b05c3fSKonstantin Belousov 	LFREEPATH(path);
64648b05c3fSKonstantin Belousov 
64748b05c3fSKonstantin Belousov 	return (error);
64848b05c3fSKonstantin Belousov }
64948b05c3fSKonstantin Belousov 
650606bcc17SDmitry Chagin #else /* __amd64__ && !COMPAT_LINUX32 */
651606bcc17SDmitry Chagin 
652606bcc17SDmitry Chagin int
653606bcc17SDmitry Chagin linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args)
654606bcc17SDmitry Chagin {
655606bcc17SDmitry Chagin 	char *path;
656606bcc17SDmitry Chagin 	int error, dfd, flag;
657606bcc17SDmitry Chagin 	struct stat buf;
658606bcc17SDmitry Chagin 
659606bcc17SDmitry Chagin 	if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW)
660606bcc17SDmitry Chagin 		return (EINVAL);
661606bcc17SDmitry Chagin 	flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
662606bcc17SDmitry Chagin 	    AT_SYMLINK_NOFOLLOW : 0;
663606bcc17SDmitry Chagin 
664606bcc17SDmitry Chagin 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
665606bcc17SDmitry Chagin 	LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
666606bcc17SDmitry Chagin 
667606bcc17SDmitry Chagin #ifdef DEBUG
668606bcc17SDmitry Chagin 	if (ldebug(newfstatat))
669606bcc17SDmitry Chagin 		printf(ARGS(newfstatat, "%i, %s, %i"), args->dfd, path, args->flag);
670606bcc17SDmitry Chagin #endif
671606bcc17SDmitry Chagin 
672606bcc17SDmitry Chagin 	error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
673606bcc17SDmitry Chagin 	if (error == 0)
674606bcc17SDmitry Chagin 		error = newstat_copyout(&buf, args->statbuf);
675606bcc17SDmitry Chagin 	LFREEPATH(path);
676606bcc17SDmitry Chagin 
677606bcc17SDmitry Chagin 	return (error);
678606bcc17SDmitry Chagin }
679606bcc17SDmitry Chagin 
6801997c537SDavid E. O'Brien #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
6819802eb9eSDmitry Chagin 
6829802eb9eSDmitry Chagin int
6839802eb9eSDmitry Chagin linux_syncfs(struct thread *td, struct linux_syncfs_args *args)
6849802eb9eSDmitry Chagin {
6859802eb9eSDmitry Chagin 	cap_rights_t rights;
6869802eb9eSDmitry Chagin 	struct mount *mp;
6879802eb9eSDmitry Chagin 	struct vnode *vp;
6889802eb9eSDmitry Chagin 	int error, save;
6899802eb9eSDmitry Chagin 
6909802eb9eSDmitry Chagin 	error = fgetvp(td, args->fd, cap_rights_init(&rights, CAP_FSYNC), &vp);
6919802eb9eSDmitry Chagin 	if (error != 0)
6929802eb9eSDmitry Chagin 		/*
6939802eb9eSDmitry Chagin 		 * Linux syncfs() returns only EBADF, however fgetvp()
6949802eb9eSDmitry Chagin 		 * can return EINVAL in case of file descriptor does
6959802eb9eSDmitry Chagin 		 * not represent a vnode. XXX.
6969802eb9eSDmitry Chagin 		 */
6979802eb9eSDmitry Chagin 		return (error);
6989802eb9eSDmitry Chagin 
6999802eb9eSDmitry Chagin 	mp = vp->v_mount;
7009802eb9eSDmitry Chagin 	mtx_lock(&mountlist_mtx);
7019802eb9eSDmitry Chagin 	error = vfs_busy(mp, MBF_MNTLSTLOCK);
7029802eb9eSDmitry Chagin 	if (error != 0) {
7039802eb9eSDmitry Chagin 		/* See comment above. */
7049802eb9eSDmitry Chagin 		mtx_unlock(&mountlist_mtx);
7059802eb9eSDmitry Chagin 		goto out;
7069802eb9eSDmitry Chagin 	}
7079802eb9eSDmitry Chagin 	if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
7089802eb9eSDmitry Chagin 	    vn_start_write(NULL, &mp, V_NOWAIT) == 0) {
7099802eb9eSDmitry Chagin 		save = curthread_pflags_set(TDP_SYNCIO);
7109802eb9eSDmitry Chagin 		vfs_msync(mp, MNT_NOWAIT);
7119802eb9eSDmitry Chagin 		VFS_SYNC(mp, MNT_NOWAIT);
7129802eb9eSDmitry Chagin 		curthread_pflags_restore(save);
7139802eb9eSDmitry Chagin 		vn_finished_write(mp);
7149802eb9eSDmitry Chagin 	}
7159802eb9eSDmitry Chagin 	vfs_unbusy(mp);
7169802eb9eSDmitry Chagin 
7179802eb9eSDmitry Chagin  out:
7189802eb9eSDmitry Chagin 	vrele(vp);
7199802eb9eSDmitry Chagin 	return (error);
7209802eb9eSDmitry Chagin }
721