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