xref: /netbsd-src/sys/compat/common/vfs_syscalls_90.c (revision 02cdd248ec8b17634bab40aa4f2e161a756d7fce)
1*02cdd248Schristos /*	$NetBSD: vfs_syscalls_90.c,v 1.1 2019/09/22 22:59:38 christos Exp $	*/
2*02cdd248Schristos 
3*02cdd248Schristos /*-
4*02cdd248Schristos  * Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
5*02cdd248Schristos  * All rights reserved.
6*02cdd248Schristos  *
7*02cdd248Schristos  * This code is derived from software contributed to The NetBSD Foundation
8*02cdd248Schristos  * by Christos Zoulas.
9*02cdd248Schristos  *
10*02cdd248Schristos  * Redistribution and use in source and binary forms, with or without
11*02cdd248Schristos  * modification, are permitted provided that the following conditions
12*02cdd248Schristos  * are met:
13*02cdd248Schristos  * 1. Redistributions of source code must retain the above copyright
14*02cdd248Schristos  *    notice, this list of conditions and the following disclaimer.
15*02cdd248Schristos  * 2. Redistributions in binary form must reproduce the above copyright
16*02cdd248Schristos  *    notice, this list of conditions and the following disclaimer in the
17*02cdd248Schristos  *    documentation and/or other materials provided with the distribution.
18*02cdd248Schristos  *
19*02cdd248Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*02cdd248Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*02cdd248Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*02cdd248Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*02cdd248Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*02cdd248Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*02cdd248Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*02cdd248Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*02cdd248Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*02cdd248Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*02cdd248Schristos  * POSSIBILITY OF SUCH DAMAGE.
30*02cdd248Schristos  */
31*02cdd248Schristos #include <sys/cdefs.h>
32*02cdd248Schristos __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_90.c,v 1.1 2019/09/22 22:59:38 christos Exp $");
33*02cdd248Schristos 
34*02cdd248Schristos #if defined(_KERNEL_OPT)
35*02cdd248Schristos #include "opt_compat_netbsd.h"
36*02cdd248Schristos #endif
37*02cdd248Schristos 
38*02cdd248Schristos #include <sys/param.h>
39*02cdd248Schristos #include <sys/systm.h>
40*02cdd248Schristos #include <sys/namei.h>
41*02cdd248Schristos #include <sys/filedesc.h>
42*02cdd248Schristos #include <sys/kernel.h>
43*02cdd248Schristos #include <sys/file.h>
44*02cdd248Schristos #include <sys/stat.h>
45*02cdd248Schristos #include <sys/socketvar.h>
46*02cdd248Schristos #include <sys/vnode.h>
47*02cdd248Schristos #include <sys/mount.h>
48*02cdd248Schristos #include <sys/proc.h>
49*02cdd248Schristos #include <sys/uio.h>
50*02cdd248Schristos #include <sys/dirent.h>
51*02cdd248Schristos #include <sys/malloc.h>
52*02cdd248Schristos #include <sys/kauth.h>
53*02cdd248Schristos #include <sys/vfs_syscalls.h>
54*02cdd248Schristos #include <sys/syscall.h>
55*02cdd248Schristos #include <sys/syscallvar.h>
56*02cdd248Schristos #include <sys/syscallargs.h>
57*02cdd248Schristos 
58*02cdd248Schristos #include <compat/common/compat_mod.h>
59*02cdd248Schristos #include <compat/common/compat_util.h>
60*02cdd248Schristos #include <compat/sys/statvfs.h>
61*02cdd248Schristos 
62*02cdd248Schristos static const struct syscall_package vfs_syscalls_90_syscalls[] = {
63*02cdd248Schristos 	{ SYS_compat_90_getvfsstat, 0, (sy_call_t *)compat_90_sys_getvfsstat },
64*02cdd248Schristos 	{ SYS_compat_90_statvfs1, 0, (sy_call_t *)compat_90_sys_statvfs1 },
65*02cdd248Schristos 	{ SYS_compat_90_fstatvfs1, 0, (sy_call_t *)compat_90_sys_fstatvfs1 },
66*02cdd248Schristos 	{ SYS_compat_90_fhstatvfs1, 0, (sy_call_t *)compat_90_sys_fhstatvfs1 },
67*02cdd248Schristos 	{ 0,0, NULL }
68*02cdd248Schristos };
69*02cdd248Schristos 
70*02cdd248Schristos 
71*02cdd248Schristos int
compat_90_sys_getvfsstat(struct lwp * l,const struct compat_90_sys_getvfsstat_args * uap,register_t * retval)72*02cdd248Schristos compat_90_sys_getvfsstat(struct lwp *l,
73*02cdd248Schristos     const struct compat_90_sys_getvfsstat_args *uap, register_t *retval)
74*02cdd248Schristos {
75*02cdd248Schristos 	/* {
76*02cdd248Schristos 		syscallarg(struct statvfs90 *) buf;
77*02cdd248Schristos 		syscallarg(size_t) bufsize;
78*02cdd248Schristos 		syscallarg(int)	flags;
79*02cdd248Schristos 	} */
80*02cdd248Schristos 
81*02cdd248Schristos 	return do_sys_getvfsstat(l, SCARG(uap, buf), SCARG(uap, bufsize),
82*02cdd248Schristos 	    SCARG(uap, flags), statvfs_to_statvfs90_copy,
83*02cdd248Schristos 	    sizeof(struct statvfs90), retval);
84*02cdd248Schristos }
85*02cdd248Schristos 
86*02cdd248Schristos int
compat_90_sys_statvfs1(struct lwp * l,const struct compat_90_sys_statvfs1_args * uap,register_t * retval)87*02cdd248Schristos compat_90_sys_statvfs1(struct lwp *l,
88*02cdd248Schristos     const struct compat_90_sys_statvfs1_args *uap, register_t *retval)
89*02cdd248Schristos {
90*02cdd248Schristos 	/* {
91*02cdd248Schristos 		syscallarg(const char *) path;
92*02cdd248Schristos 		syscallarg(struct statvfs90 *) buf;
93*02cdd248Schristos 		syscallarg(int)	flags;
94*02cdd248Schristos 	} */
95*02cdd248Schristos 
96*02cdd248Schristos 	struct statvfs *sb = STATVFSBUF_GET();
97*02cdd248Schristos 	int error = do_sys_pstatvfs(l, SCARG(uap, path), SCARG(uap, flags), sb);
98*02cdd248Schristos 
99*02cdd248Schristos 	if (!error)
100*02cdd248Schristos 		error = statvfs_to_statvfs90_copy(sb, SCARG(uap, buf),
101*02cdd248Schristos 		    sizeof(struct statvfs90));
102*02cdd248Schristos 
103*02cdd248Schristos 	STATVFSBUF_PUT(sb);
104*02cdd248Schristos 	return error;
105*02cdd248Schristos }
106*02cdd248Schristos 
107*02cdd248Schristos int
compat_90_sys_fstatvfs1(struct lwp * l,const struct compat_90_sys_fstatvfs1_args * uap,register_t * retval)108*02cdd248Schristos compat_90_sys_fstatvfs1(struct lwp *l,
109*02cdd248Schristos     const struct compat_90_sys_fstatvfs1_args *uap, register_t *retval)
110*02cdd248Schristos {
111*02cdd248Schristos 	/* {
112*02cdd248Schristos 		syscallarg(int) fd;
113*02cdd248Schristos 		syscallarg(struct statvfs90 *) buf;
114*02cdd248Schristos 		syscallarg(int)	flags;
115*02cdd248Schristos 	} */
116*02cdd248Schristos 
117*02cdd248Schristos 	struct statvfs *sb = STATVFSBUF_GET();
118*02cdd248Schristos 	int error = do_sys_fstatvfs(l, SCARG(uap, fd), SCARG(uap, flags), sb);
119*02cdd248Schristos 
120*02cdd248Schristos 	if (!error)
121*02cdd248Schristos 		error = statvfs_to_statvfs90_copy(sb, SCARG(uap, buf),
122*02cdd248Schristos 		    sizeof(struct statvfs90));
123*02cdd248Schristos 
124*02cdd248Schristos 	STATVFSBUF_PUT(sb);
125*02cdd248Schristos 	return error;
126*02cdd248Schristos }
127*02cdd248Schristos 
128*02cdd248Schristos int
compat_90_sys_fhstatvfs1(struct lwp * l,const struct compat_90_sys_fhstatvfs1_args * uap,register_t * retval)129*02cdd248Schristos compat_90_sys_fhstatvfs1(struct lwp *l,
130*02cdd248Schristos     const struct compat_90_sys_fhstatvfs1_args *uap, register_t *retval)
131*02cdd248Schristos {
132*02cdd248Schristos 	/* {
133*02cdd248Schristos 		syscallarg(const void *) fhp;
134*02cdd248Schristos 		syscallarg(size_t) fh_size;
135*02cdd248Schristos 		syscallarg(struct statvfs90 *) buf;
136*02cdd248Schristos 		syscallarg(int)	flags;
137*02cdd248Schristos 	} */
138*02cdd248Schristos 
139*02cdd248Schristos 	struct statvfs *sb = STATVFSBUF_GET();
140*02cdd248Schristos 	int error = do_fhstatvfs(l, SCARG(uap, fhp), SCARG(uap, fh_size),
141*02cdd248Schristos 	    sb, SCARG(uap, flags));
142*02cdd248Schristos 
143*02cdd248Schristos 	if (!error)
144*02cdd248Schristos 		error = statvfs_to_statvfs90_copy(sb, SCARG(uap, buf),
145*02cdd248Schristos 		    sizeof(struct statvfs90));
146*02cdd248Schristos 
147*02cdd248Schristos 	STATVFSBUF_PUT(sb);
148*02cdd248Schristos 	return error;
149*02cdd248Schristos }
150*02cdd248Schristos 
151*02cdd248Schristos int
vfs_syscalls_90_init(void)152*02cdd248Schristos vfs_syscalls_90_init(void)
153*02cdd248Schristos {
154*02cdd248Schristos 
155*02cdd248Schristos 	return syscall_establish(NULL, vfs_syscalls_90_syscalls);
156*02cdd248Schristos }
157*02cdd248Schristos 
158*02cdd248Schristos int
vfs_syscalls_90_fini(void)159*02cdd248Schristos vfs_syscalls_90_fini(void)
160*02cdd248Schristos {
161*02cdd248Schristos 
162*02cdd248Schristos 	return syscall_disestablish(NULL, vfs_syscalls_90_syscalls);
163*02cdd248Schristos }
164