xref: /netbsd-src/sys/compat/common/compat_sysctl_09_43.c (revision 799a3b19cf93b9f07e4c7d1919fbd5415a973f6d)
1 /*	$NetBSD: compat_sysctl_09_43.c,v 1.6 2020/03/26 13:39:29 pgoyette Exp $	*/
2 
3 /*
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)vfs_syscalls.c	8.28 (Berkeley) 12/10/94
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: compat_sysctl_09_43.c,v 1.6 2020/03/26 13:39:29 pgoyette Exp $");
41 
42 #if defined(_KERNEL_OPT)
43 #include "opt_compat_netbsd.h"
44 #endif
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/filedesc.h>
49 #include <sys/kernel.h>
50 #include <sys/proc.h>
51 #include <sys/malloc.h>
52 #include <sys/sysctl.h>
53 #include <sys/module.h>
54 
55 #include <sys/mount.h>
56 #include <sys/syscall.h>
57 #include <sys/syscallvar.h>
58 #include <sys/syscallargs.h>
59 #include <sys/vfs_syscalls.h>
60 
61 #include <compat/sys/mount.h>
62 #include <compat/common/compat_mod.h>
63 
64 /*
65  * sysctl helper routine for vfs.generic.conf lookups.
66  */
67 #if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_44)
68 
69 static int
sysctl_vfs_generic_conf(SYSCTLFN_ARGS)70 sysctl_vfs_generic_conf(SYSCTLFN_ARGS)
71 {
72         struct vfsconf vfc;
73 	struct sysctlnode node;
74 	struct vfsops *vfsp;
75 	u_int vfsnum;
76 
77 	if (namelen != 1)
78 		return (ENOTDIR);
79 	vfsnum = name[0];
80 	if (vfsnum >= nmountcompatnames ||
81 	    mountcompatnames[vfsnum] == NULL)
82 		return (EOPNOTSUPP);
83 	vfsp = vfs_getopsbyname(mountcompatnames[vfsnum]);
84 	if (vfsp == NULL)
85 		return (EOPNOTSUPP);
86 
87 	vfc.vfc_vfsops = vfsp;
88 	strncpy(vfc.vfc_name, vfsp->vfs_name, sizeof(vfc.vfc_name));
89 	vfc.vfc_typenum = vfsnum;
90 	vfc.vfc_refcount = vfsp->vfs_refcount;
91 	vfc.vfc_flags = 0;
92 	vfc.vfc_mountroot = vfsp->vfs_mountroot;
93 	vfc.vfc_next = NULL;
94 	vfs_delref(vfsp);
95 
96 	node = *rnode;
97 	node.sysctl_data = &vfc;
98 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
99 }
100 
101 /*
102  * Top level filesystem related information gathering.
103  */
104 SYSCTL_SETUP(compat_sysctl_vfs, "Top-level filesystem info")
105 {
106 	int error;
107 
108 	error = sysctl_createv(clog, 0, NULL, NULL,
109 			CTLFLAG_PERMANENT,
110 			CTLTYPE_NODE, "generic",
111 			SYSCTL_DESCR("Non-specific vfs related information"),
112 			NULL, 0, NULL, 0,
113 			CTL_VFS, VFS_GENERIC, CTL_EOL);
114 	if (error == EEXIST)
115 		error = 0;
116 	if (error != 0)
117 		return;
118 
119 	error = sysctl_createv(clog, 0, NULL, NULL,
120 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
121 		       CTLTYPE_INT, "maxtypenum",
122 		       SYSCTL_DESCR("Highest valid filesystem type number"),
123 		       NULL, nmountcompatnames, NULL, 0,
124 		       CTL_VFS, VFS_GENERIC, VFS_MAXTYPENUM, CTL_EOL);
125 	if (error == EEXIST)
126 		error = 0;
127 	if (error != 0)
128 		return;
129 
130 	error = sysctl_createv(clog, 0, NULL, NULL,
131 		       CTLFLAG_PERMANENT,
132 		       CTLTYPE_STRUCT, "conf",
133 		       SYSCTL_DESCR("Filesystem configuration information"),
134 		       sysctl_vfs_generic_conf, 0, NULL,
135 		       sizeof(struct vfsconf),
136 		       CTL_VFS, VFS_GENERIC, VFS_CONF, CTL_EOL);
137 }
138 #endif
139 
140 int
compat_sysctl_09_43_init(void)141 compat_sysctl_09_43_init(void)
142 {
143 
144 	return 0;
145 }
146 
147 int
compat_sysctl_09_43_fini(void)148 compat_sysctl_09_43_fini(void)
149 {
150 
151 	return 0;
152 }
153 
154 MODULE (MODULE_CLASS_EXEC, compat_sysctl_09_43, NULL);
155 
156 static int
compat_sysctl_09_43_modcmd(modcmd_t cmd,void * arg)157 compat_sysctl_09_43_modcmd(modcmd_t cmd, void *arg)
158 {
159 
160 	switch (cmd) {
161 	case MODULE_CMD_INIT:
162 		return compat_sysctl_09_43_init();
163 	case MODULE_CMD_FINI:
164 		return compat_sysctl_09_43_fini();
165 	default:
166 		return ENOTTY;
167 	}
168 }
169