xref: /titanic_50/usr/src/uts/common/syscall/sysfs.c (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
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>
50 
51 /*
52  * System call to map fstype numbers to names, and vice versa.
53  */
54 
55 static int sysfsind(char *);
56 static int sysfstyp(int, char *);
57 
58 int
59 sysfs(int opcode, long a1, long a2)
60 {
61 	int error;
62 
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:
71 		/*
72 		 * Return number of fstypes configured in the system.
73 		 */
74 		return (nfstype - 1);
75 	default:
76 		error = set_errno(EINVAL);
77 	}
78 
79 	return (error);
80 }
81 
82 static int
83 sysfsind(char *fsname)
84 {
85 	/*
86 	 * Translate fs identifier to an index into the vfssw structure.
87 	 */
88 	struct vfssw *vswp;
89 	char fsbuf[FSTYPSZ];
90 	int retval;
91 	size_t len = 0;
92 
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));
100 	/*
101 	 * Search the vfssw table for the fs identifier
102 	 * and return the index.
103 	 */
104 	if ((vswp = vfs_getvfssw(fsbuf)) != NULL) {
105 		retval = vswp - vfssw;
106 		vfs_unrefvfssw(vswp);
107 		return (retval);
108 	}
109 
110 	return (set_errno(EINVAL));
111 }
112 
113 static int
114 sysfstyp(int index, char *cbuf)
115 {
116 	/*
117 	 * Translate fstype index into an fs identifier.
118 	 */
119 	char *src;
120 	struct vfssw *vswp;
121 	char *osrc;
122 	int error = 0;
123 
124 	if (index <= 0 || index >= nfstype)
125 		return (set_errno(EINVAL));
126 	RLOCK_VFSSW();
127 	vswp = &vfssw[index];
128 
129 	osrc = src = vswp->vsw_name;
130 	while (*src++)
131 		;
132 
133 	if (copyout(osrc, cbuf, src - osrc))
134 		error = set_errno(EFAULT);
135 	RUNLOCK_VFSSW();
136 	return (error);
137 }
138