Home | History | Annotate | Line # | Download | only in common
compat_sysctl_09_43.c revision 1.3
      1 /*	$NetBSD: compat_sysctl_09_43.c,v 1.3 2019/12/06 08:35:21 maxv 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.3 2019/12/06 08:35:21 maxv 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
     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 static int
    105 compat_sysctl_vfs(struct sysctllog **clog)
    106 {
    107 	int error;
    108 
    109 	error = sysctl_createv(clog, 0, NULL, NULL,
    110 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    111 		       CTLTYPE_INT, "maxtypenum",
    112 		       SYSCTL_DESCR("Highest valid filesystem type number"),
    113 		       NULL, nmountcompatnames, NULL, 0,
    114 		       CTL_VFS, VFS_GENERIC, VFS_MAXTYPENUM, CTL_EOL);
    115 	if (error == EEXIST)
    116 		error = 0;
    117 	if (error != 0)
    118 		return error;
    119 
    120 	error = sysctl_createv(clog, 0, NULL, NULL,
    121 		       CTLFLAG_PERMANENT,
    122 		       CTLTYPE_STRUCT, "conf",
    123 		       SYSCTL_DESCR("Filesystem configuration information"),
    124 		       sysctl_vfs_generic_conf, 0, NULL,
    125 		       sizeof(struct vfsconf),
    126 		       CTL_VFS, VFS_GENERIC, VFS_CONF, CTL_EOL);
    127 
    128 	return error;
    129 }
    130 #endif
    131 
    132 static struct sysctllog *compat_09_43_clog = NULL;
    133 
    134 int
    135 compat_sysctl_09_43_init(void)
    136 {
    137 
    138 	return compat_sysctl_vfs(&compat_09_43_clog);
    139 }
    140 
    141 int
    142 compat_sysctl_09_43_fini(void)
    143 {
    144 
    145 	sysctl_teardown(&compat_09_43_clog);
    146 	return 0;
    147 }
    148 
    149 MODULE (MODULE_CLASS_EXEC, compat_sysctl_09_43, NULL);
    150 
    151 static int
    152 compat_sysctl_09_43_modcmd(modcmd_t cmd, void *arg)
    153 {
    154 
    155 	switch (cmd) {
    156 	case MODULE_CMD_INIT:
    157 		return compat_sysctl_09_43_init();
    158 	case MODULE_CMD_FINI:
    159 		return compat_sysctl_09_43_fini();
    160 	default:
    161 		return ENOTTY;
    162 	}
    163 }
    164