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