xref: /illumos-gate/usr/src/uts/common/syscall/sysfs.c (revision 2d6eb4a5)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 #include <sys/types.h>
36 #include <sys/t_lock.h>
37 #include <sys/param.h>
38 #include <sys/errno.h>
39 #include <sys/fstyp.h>
40 #include <sys/systm.h>
41 #include <sys/mount.h>
42 #include <sys/vfs.h>
43 #include <sys/vnode.h>
44 #include <sys/cmn_err.h>
45 #include <sys/buf.h>
46 #include <sys/debug.h>
47 #include <sys/pathname.h>
48 
49 /*
50  * System call to map fstype numbers to names, and vice versa.
51  */
52 
53 static int sysfsind(char *);
54 static int sysfstyp(int, char *);
55 
56 int
sysfs(int opcode,long a1,long a2)57 sysfs(int opcode, long a1, long a2)
58 {
59 	int error;
60 
61 	switch (opcode) {
62 	case GETFSIND:
63 		error = sysfsind((char *)a1);
64 		break;
65 	case GETFSTYP:
66 		error = sysfstyp((int)a1, (char *)a2);
67 		break;
68 	case GETNFSTYP:
69 		/*
70 		 * Return number of fstypes configured in the system.
71 		 */
72 		return (nfstype - 1);
73 	default:
74 		error = set_errno(EINVAL);
75 	}
76 
77 	return (error);
78 }
79 
80 static int
sysfsind(char * fsname)81 sysfsind(char *fsname)
82 {
83 	/*
84 	 * Translate fs identifier to an index into the vfssw structure.
85 	 */
86 	struct vfssw *vswp;
87 	char fsbuf[FSTYPSZ];
88 	int retval;
89 	size_t len = 0;
90 
91 	retval = copyinstr(fsname, fsbuf, FSTYPSZ, &len);
92 	if (retval == ENOENT)			/* XXX */
93 		retval = EINVAL;		/* XXX */
94 	if (len == 1)			/* Includes null byte */
95 		retval = EINVAL;
96 	if (retval)
97 		return (set_errno(retval));
98 	/*
99 	 * Search the vfssw table for the fs identifier
100 	 * and return the index.
101 	 */
102 	if ((vswp = vfs_getvfssw(fsbuf)) != NULL) {
103 		retval = vswp - vfssw;
104 		vfs_unrefvfssw(vswp);
105 		return (retval);
106 	}
107 
108 	return (set_errno(EINVAL));
109 }
110 
111 static int
sysfstyp(int index,char * cbuf)112 sysfstyp(int index, char *cbuf)
113 {
114 	/*
115 	 * Translate fstype index into an fs identifier.
116 	 */
117 	char *src;
118 	struct vfssw *vswp;
119 	char *osrc;
120 	int error = 0;
121 
122 	if (index <= 0 || index >= nfstype)
123 		return (set_errno(EINVAL));
124 	RLOCK_VFSSW();
125 	vswp = &vfssw[index];
126 
127 	osrc = src = vswp->vsw_name;
128 	while (*src++)
129 		;
130 
131 	if (copyout(osrc, cbuf, src - osrc))
132 		error = set_errno(EFAULT);
133 	RUNLOCK_VFSSW();
134 	return (error);
135 }
136