xref: /illumos-gate/usr/src/uts/common/syscall/mount.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 2004 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/user.h>
40 #include <sys/fstyp.h>
41 #include <sys/kmem.h>
42 #include <sys/systm.h>
43 #include <sys/mount.h>
44 #include <sys/vfs.h>
45 #include <sys/cred.h>
46 #include <sys/vnode.h>
47 #include <sys/dnlc.h>
48 #include <sys/file.h>
49 #include <sys/time.h>
50 #include <sys/cmn_err.h>
51 #include <sys/swap.h>
52 #include <sys/debug.h>
53 #include <sys/pathname.h>
54 #include <sys/cladm.h>
55 
56 /*
57  * System calls.
58  */
59 
60 /*
61  * "struct mounta" defined in sys/vfs.h.
62  */
63 
64 /* ARGSUSED */
65 int
mount(long * lp,rval_t * rp)66 mount(long *lp, rval_t *rp)
67 {
68 	vnode_t *vp = NULL;
69 	struct vfs *vfsp;	/* dummy argument */
70 	int error;
71 	struct mounta *uap;
72 #if defined(_LP64)
73 	struct mounta native;
74 
75 	/*
76 	 * Make a struct mounta if we are DATAMODEL_LP64
77 	 */
78 	uap = &native;
79 	uap->spec = (char *)*lp++;
80 	uap->dir = (char *)*lp++;
81 	uap->flags = (int)*lp++;
82 	uap->fstype = (char *)*lp++;
83 	uap->dataptr = (char *)*lp++;
84 	uap->datalen = (int)*lp++;
85 	uap->optptr = (char *)*lp++;
86 	uap->optlen = (int)*lp++;
87 #else	/* !defined(_LP64) */
88 	/*
89 	 * 32 bit kernels can take a shortcut and just cast
90 	 * the args array to the structure.
91 	 */
92 	uap = (struct mounta *)lp;
93 #endif	/* _LP64 */
94 	/*
95 	 * Resolve second path name (mount point).
96 	 */
97 	if (error = lookupname(uap->dir, UIO_USERSPACE, FOLLOW, NULLVPP, &vp))
98 		return (set_errno(error));
99 
100 	/*
101 	 * Some mount flags are disallowed through the system call interface.
102 	 */
103 	uap->flags &= MS_MASK;
104 
105 	if ((vp->v_flag & VPXFS) && ((uap->flags & MS_GLOBAL) != MS_GLOBAL)) {
106 		/*
107 		 * Clustering: if we're doing a mount onto the global
108 		 * namespace, and the mount is not a global mount, return
109 		 * an error.
110 		 */
111 		error = ENOTSUP;
112 	} else if (uap->flags & MS_GLOBAL) {
113 		/*
114 		 * Clustering: global mount specified.
115 		 */
116 		if ((cluster_bootflags & CLUSTER_BOOTED) == 0) {
117 			/*
118 			 * If we're not booted as a cluster,
119 			 * global mounts are not allowed.
120 			 */
121 			error = ENOTSUP;
122 		} else {
123 			error = domount("pxfs", uap, vp, CRED(), &vfsp);
124 			if (!error)
125 				VFS_RELE(vfsp);
126 		}
127 	} else {
128 		error = domount(NULL, uap, vp, CRED(), &vfsp);
129 		if (!error)
130 			VFS_RELE(vfsp);
131 	}
132 	VN_RELE(vp);
133 	rp->r_val2 = error;
134 	return (error ? set_errno(error) : 0);
135 }
136