pax: avoid implicit function declaration warnings
[unleashed.git] / kernel / syscall / sysfs.c
blob58b760bf298fbb6b7c06a6eed9f812850a2ca175
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/types.h>
38 #include <sys/t_lock.h>
39 #include <sys/param.h>
40 #include <sys/errno.h>
41 #include <sys/fstyp.h>
42 #include <sys/systm.h>
43 #include <sys/mount.h>
44 #include <sys/vfs.h>
45 #include <sys/vnode.h>
46 #include <sys/cmn_err.h>
47 #include <sys/buf.h>
48 #include <sys/debug.h>
49 #include <sys/pathname.h>
52 * System call to map fstype numbers to names, and vice versa.
55 static int sysfsind(char *);
56 static int sysfstyp(int, char *);
58 int
59 sysfs(int opcode, long a1, long a2)
61 int error;
63 switch (opcode) {
64 case GETFSIND:
65 error = sysfsind((char *)a1);
66 break;
67 case GETFSTYP:
68 error = sysfstyp((int)a1, (char *)a2);
69 break;
70 case GETNFSTYP:
72 * Return number of fstypes configured in the system.
74 return (nfstype - 1);
75 default:
76 error = set_errno(EINVAL);
79 return (error);
82 static int
83 sysfsind(char *fsname)
86 * Translate fs identifier to an index into the vfssw structure.
88 struct vfssw *vswp;
89 char fsbuf[FSTYPSZ];
90 int retval;
91 size_t len = 0;
93 retval = copyinstr(fsname, fsbuf, FSTYPSZ, &len);
94 if (retval == ENOENT) /* XXX */
95 retval = EINVAL; /* XXX */
96 if (len == 1) /* Includes null byte */
97 retval = EINVAL;
98 if (retval)
99 return (set_errno(retval));
101 * Search the vfssw table for the fs identifier
102 * and return the index.
104 if ((vswp = vfs_getvfssw(fsbuf)) != NULL) {
105 retval = vswp - vfssw;
106 vfs_unrefvfssw(vswp);
107 return (retval);
110 return (set_errno(EINVAL));
113 static int
114 sysfstyp(int index, char *cbuf)
117 * Translate fstype index into an fs identifier.
119 char *src;
120 struct vfssw *vswp;
121 char *osrc;
122 int error = 0;
124 if (index <= 0 || index >= nfstype)
125 return (set_errno(EINVAL));
126 RLOCK_VFSSW();
127 vswp = &vfssw[index];
129 osrc = src = vswp->vsw_name;
130 while (*src++)
133 if (copyout(osrc, cbuf, src - osrc))
134 error = set_errno(EFAULT);
135 RUNLOCK_VFSSW();
136 return (error);