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