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