1*2c2f96dcSApple OSS Distributions /*
2*2c2f96dcSApple OSS Distributions * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
3*2c2f96dcSApple OSS Distributions *
4*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*2c2f96dcSApple OSS Distributions *
6*2c2f96dcSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*2c2f96dcSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*2c2f96dcSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*2c2f96dcSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*2c2f96dcSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*2c2f96dcSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*2c2f96dcSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*2c2f96dcSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*2c2f96dcSApple OSS Distributions *
15*2c2f96dcSApple OSS Distributions * Please obtain a copy of the License at
16*2c2f96dcSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*2c2f96dcSApple OSS Distributions *
18*2c2f96dcSApple OSS Distributions * The Original Code and all software distributed under the License are
19*2c2f96dcSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*2c2f96dcSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*2c2f96dcSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*2c2f96dcSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*2c2f96dcSApple OSS Distributions * Please see the License for the specific language governing rights and
24*2c2f96dcSApple OSS Distributions * limitations under the License.
25*2c2f96dcSApple OSS Distributions *
26*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*2c2f96dcSApple OSS Distributions */
28*2c2f96dcSApple OSS Distributions /*-
29*2c2f96dcSApple OSS Distributions * Copyright 1997,1998 Julian Elischer. All rights reserved.
30*2c2f96dcSApple OSS Distributions * [email protected]
31*2c2f96dcSApple OSS Distributions *
32*2c2f96dcSApple OSS Distributions * Redistribution and use in source and binary forms, with or without
33*2c2f96dcSApple OSS Distributions * modification, are permitted provided that the following conditions are
34*2c2f96dcSApple OSS Distributions * met:
35*2c2f96dcSApple OSS Distributions * 1. Redistributions of source code must retain the above copyright
36*2c2f96dcSApple OSS Distributions * notice, this list of conditions and the following disclaimer.
37*2c2f96dcSApple OSS Distributions * 2. Redistributions in binary form must reproduce the above copyright notice,
38*2c2f96dcSApple OSS Distributions * this list of conditions and the following disclaimer in the documentation
39*2c2f96dcSApple OSS Distributions * and/or other materials provided with the distribution.
40*2c2f96dcSApple OSS Distributions *
41*2c2f96dcSApple OSS Distributions * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
42*2c2f96dcSApple OSS Distributions * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43*2c2f96dcSApple OSS Distributions * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44*2c2f96dcSApple OSS Distributions * DISCLAIMED. IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
45*2c2f96dcSApple OSS Distributions * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46*2c2f96dcSApple OSS Distributions * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47*2c2f96dcSApple OSS Distributions * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48*2c2f96dcSApple OSS Distributions * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49*2c2f96dcSApple OSS Distributions * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50*2c2f96dcSApple OSS Distributions * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51*2c2f96dcSApple OSS Distributions * SUCH DAMAGE.
52*2c2f96dcSApple OSS Distributions *
53*2c2f96dcSApple OSS Distributions * devfs_vfsops.c
54*2c2f96dcSApple OSS Distributions *
55*2c2f96dcSApple OSS Distributions */
56*2c2f96dcSApple OSS Distributions /*
57*2c2f96dcSApple OSS Distributions * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
58*2c2f96dcSApple OSS Distributions * support for mandatory and extensible security protections. This notice
59*2c2f96dcSApple OSS Distributions * is included in support of clause 2.2 (b) of the Apple Public License,
60*2c2f96dcSApple OSS Distributions * Version 2.0.
61*2c2f96dcSApple OSS Distributions */
62*2c2f96dcSApple OSS Distributions /*
63*2c2f96dcSApple OSS Distributions * HISTORY
64*2c2f96dcSApple OSS Distributions * Dieter Siegmund ([email protected]) Wed Jul 14 13:37:59 PDT 1999
65*2c2f96dcSApple OSS Distributions * - modified devfs_statfs() to use devfs_stats to calculate the
66*2c2f96dcSApple OSS Distributions * amount of memory used by devfs
67*2c2f96dcSApple OSS Distributions */
68*2c2f96dcSApple OSS Distributions
69*2c2f96dcSApple OSS Distributions
70*2c2f96dcSApple OSS Distributions #include <sys/param.h>
71*2c2f96dcSApple OSS Distributions #include <sys/systm.h>
72*2c2f96dcSApple OSS Distributions #include <sys/kernel.h>
73*2c2f96dcSApple OSS Distributions #include <sys/vnode_internal.h>
74*2c2f96dcSApple OSS Distributions #include <sys/proc.h>
75*2c2f96dcSApple OSS Distributions #include <sys/kauth.h>
76*2c2f96dcSApple OSS Distributions #include <sys/mount_internal.h>
77*2c2f96dcSApple OSS Distributions #include <sys/malloc.h>
78*2c2f96dcSApple OSS Distributions #include <sys/conf.h>
79*2c2f96dcSApple OSS Distributions #include <libkern/OSAtomic.h>
80*2c2f96dcSApple OSS Distributions #include <atm/atm_internal.h>
81*2c2f96dcSApple OSS Distributions
82*2c2f96dcSApple OSS Distributions #if CONFIG_MACF
83*2c2f96dcSApple OSS Distributions #include <security/mac_framework.h>
84*2c2f96dcSApple OSS Distributions #endif
85*2c2f96dcSApple OSS Distributions
86*2c2f96dcSApple OSS Distributions #include "devfs.h"
87*2c2f96dcSApple OSS Distributions #include "devfsdefs.h"
88*2c2f96dcSApple OSS Distributions
89*2c2f96dcSApple OSS Distributions #if FDESC
90*2c2f96dcSApple OSS Distributions #include "fdesc.h"
91*2c2f96dcSApple OSS Distributions #endif /* FDESC */
92*2c2f96dcSApple OSS Distributions
93*2c2f96dcSApple OSS Distributions
94*2c2f96dcSApple OSS Distributions static int devfs_statfs( struct mount *mp, struct vfsstatfs *sbp, vfs_context_t ctx);
95*2c2f96dcSApple OSS Distributions static int devfs_vfs_getattr(mount_t mp, struct vfs_attr *fsap, vfs_context_t ctx);
96*2c2f96dcSApple OSS Distributions
97*2c2f96dcSApple OSS Distributions #if CONFIG_DEV_KMEM
98*2c2f96dcSApple OSS Distributions extern boolean_t dev_kmem_enabled;
99*2c2f96dcSApple OSS Distributions #endif
100*2c2f96dcSApple OSS Distributions
101*2c2f96dcSApple OSS Distributions /*-
102*2c2f96dcSApple OSS Distributions * Called from the generic VFS startups.
103*2c2f96dcSApple OSS Distributions * This is the second stage of DEVFS initialisation.
104*2c2f96dcSApple OSS Distributions * The probed devices have already been loaded and the
105*2c2f96dcSApple OSS Distributions * basic structure of the DEVFS created.
106*2c2f96dcSApple OSS Distributions * We take the oportunity to mount the hidden DEVFS layer, so that
107*2c2f96dcSApple OSS Distributions * devices from devfs get sync'd.
108*2c2f96dcSApple OSS Distributions */
109*2c2f96dcSApple OSS Distributions static int
devfs_init(__unused struct vfsconf * vfsp)110*2c2f96dcSApple OSS Distributions devfs_init(__unused struct vfsconf *vfsp)
111*2c2f96dcSApple OSS Distributions {
112*2c2f96dcSApple OSS Distributions if (devfs_sinit()) {
113*2c2f96dcSApple OSS Distributions return ENOTSUP;
114*2c2f96dcSApple OSS Distributions }
115*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(0, 0), DEVFS_CHAR,
116*2c2f96dcSApple OSS Distributions UID_ROOT, GID_WHEEL, 0622, "console");
117*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(2, 0), DEVFS_CHAR,
118*2c2f96dcSApple OSS Distributions UID_ROOT, GID_WHEEL, 0666, "tty");
119*2c2f96dcSApple OSS Distributions #if CONFIG_DEV_KMEM
120*2c2f96dcSApple OSS Distributions if (dev_kmem_enabled) {
121*2c2f96dcSApple OSS Distributions /* (3,0) reserved for /dev/mem physical memory */
122*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(3, 1), DEVFS_CHAR,
123*2c2f96dcSApple OSS Distributions UID_ROOT, GID_KMEM, 0640, "kmem");
124*2c2f96dcSApple OSS Distributions }
125*2c2f96dcSApple OSS Distributions #endif
126*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(3, 2), DEVFS_CHAR,
127*2c2f96dcSApple OSS Distributions UID_ROOT, GID_WHEEL, 0666, "null");
128*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(3, 3), DEVFS_CHAR,
129*2c2f96dcSApple OSS Distributions UID_ROOT, GID_WHEEL, 0666, "zero");
130*2c2f96dcSApple OSS Distributions uint32_t logging_config = atm_get_diagnostic_config();
131*2c2f96dcSApple OSS Distributions
132*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(6, 0), DEVFS_CHAR,
133*2c2f96dcSApple OSS Distributions UID_ROOT, GID_WHEEL, 0600, "klog");
134*2c2f96dcSApple OSS Distributions
135*2c2f96dcSApple OSS Distributions if (!(logging_config & ATM_TRACE_DISABLE)) {
136*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(7, 0), DEVFS_CHAR,
137*2c2f96dcSApple OSS Distributions UID_LOGD, GID_LOGD, 0600, "oslog");
138*2c2f96dcSApple OSS Distributions if (cdevsw_setkqueueok(7, (&(cdevsw[7])), 0) == -1) {
139*2c2f96dcSApple OSS Distributions return ENOTSUP;
140*2c2f96dcSApple OSS Distributions }
141*2c2f96dcSApple OSS Distributions
142*2c2f96dcSApple OSS Distributions devfs_make_node(makedev(8, 0), DEVFS_CHAR,
143*2c2f96dcSApple OSS Distributions UID_ROOT, GID_WHEEL, 0600, "oslog_stream");
144*2c2f96dcSApple OSS Distributions if (cdevsw_setkqueueok(8, (&(cdevsw[8])), 0) == -1) {
145*2c2f96dcSApple OSS Distributions return ENOTSUP;
146*2c2f96dcSApple OSS Distributions }
147*2c2f96dcSApple OSS Distributions }
148*2c2f96dcSApple OSS Distributions
149*2c2f96dcSApple OSS Distributions
150*2c2f96dcSApple OSS Distributions #if FDESC
151*2c2f96dcSApple OSS Distributions devfs_fdesc_init();
152*2c2f96dcSApple OSS Distributions #endif
153*2c2f96dcSApple OSS Distributions
154*2c2f96dcSApple OSS Distributions return 0;
155*2c2f96dcSApple OSS Distributions }
156*2c2f96dcSApple OSS Distributions
157*2c2f96dcSApple OSS Distributions /*-
158*2c2f96dcSApple OSS Distributions * mp - pointer to 'mount' structure
159*2c2f96dcSApple OSS Distributions * path - addr in user space of mount point (ie /usr or whatever)
160*2c2f96dcSApple OSS Distributions * data - addr in user space of mount params including the
161*2c2f96dcSApple OSS Distributions * name of the block special file to treat as a filesystem.
162*2c2f96dcSApple OSS Distributions * (NOT USED)
163*2c2f96dcSApple OSS Distributions * ndp - namei data pointer (NOT USED)
164*2c2f96dcSApple OSS Distributions * p - proc pointer
165*2c2f96dcSApple OSS Distributions * devfs is special in that it doesn't require any device to be mounted..
166*2c2f96dcSApple OSS Distributions * It makes up its data as it goes along.
167*2c2f96dcSApple OSS Distributions * it must be mounted during single user.. until it is, only std{in/out/err}
168*2c2f96dcSApple OSS Distributions * and the root filesystem are available.
169*2c2f96dcSApple OSS Distributions */
170*2c2f96dcSApple OSS Distributions /*proto*/
171*2c2f96dcSApple OSS Distributions int
devfs_mount(struct mount * mp,__unused vnode_t devvp,__unused user_addr_t data,vfs_context_t ctx)172*2c2f96dcSApple OSS Distributions devfs_mount(struct mount *mp, __unused vnode_t devvp, __unused user_addr_t data, vfs_context_t ctx)
173*2c2f96dcSApple OSS Distributions {
174*2c2f96dcSApple OSS Distributions struct devfsmount *devfs_mp_p; /* devfs specific mount info */
175*2c2f96dcSApple OSS Distributions int error;
176*2c2f96dcSApple OSS Distributions
177*2c2f96dcSApple OSS Distributions /*-
178*2c2f96dcSApple OSS Distributions * If they just want to update, we don't need to do anything.
179*2c2f96dcSApple OSS Distributions */
180*2c2f96dcSApple OSS Distributions if (mp->mnt_flag & MNT_UPDATE) {
181*2c2f96dcSApple OSS Distributions return 0;
182*2c2f96dcSApple OSS Distributions }
183*2c2f96dcSApple OSS Distributions
184*2c2f96dcSApple OSS Distributions /* Advisory locking should be handled at the VFS layer */
185*2c2f96dcSApple OSS Distributions vfs_setlocklocal(mp);
186*2c2f96dcSApple OSS Distributions
187*2c2f96dcSApple OSS Distributions /*-
188*2c2f96dcSApple OSS Distributions * Well, it's not an update, it's a real mount request.
189*2c2f96dcSApple OSS Distributions * Time to get dirty.
190*2c2f96dcSApple OSS Distributions * HERE we should check to see if we are already mounted here.
191*2c2f96dcSApple OSS Distributions */
192*2c2f96dcSApple OSS Distributions
193*2c2f96dcSApple OSS Distributions devfs_mp_p = kalloc_type(struct devfsmount,
194*2c2f96dcSApple OSS Distributions Z_WAITOK | Z_ZERO | Z_NOFAIL);
195*2c2f96dcSApple OSS Distributions devfs_mp_p->mount = mp;
196*2c2f96dcSApple OSS Distributions
197*2c2f96dcSApple OSS Distributions /*-
198*2c2f96dcSApple OSS Distributions * Fill out some fields
199*2c2f96dcSApple OSS Distributions */
200*2c2f96dcSApple OSS Distributions __IGNORE_WCASTALIGN(mp->mnt_data = (qaddr_t)devfs_mp_p);
201*2c2f96dcSApple OSS Distributions mp->mnt_vfsstat.f_fsid.val[0] = (int32_t)VM_KERNEL_ADDRHASH(devfs_mp_p);
202*2c2f96dcSApple OSS Distributions mp->mnt_vfsstat.f_fsid.val[1] = vfs_typenum(mp);
203*2c2f96dcSApple OSS Distributions mp->mnt_flag |= MNT_LOCAL;
204*2c2f96dcSApple OSS Distributions
205*2c2f96dcSApple OSS Distributions DEVFS_LOCK();
206*2c2f96dcSApple OSS Distributions error = dev_dup_plane(devfs_mp_p);
207*2c2f96dcSApple OSS Distributions DEVFS_UNLOCK();
208*2c2f96dcSApple OSS Distributions
209*2c2f96dcSApple OSS Distributions if (error) {
210*2c2f96dcSApple OSS Distributions mp->mnt_data = (qaddr_t)0;
211*2c2f96dcSApple OSS Distributions kfree_type(struct devfsmount, devfs_mp_p);
212*2c2f96dcSApple OSS Distributions return error;
213*2c2f96dcSApple OSS Distributions } else {
214*2c2f96dcSApple OSS Distributions DEVFS_INCR_MOUNTS();
215*2c2f96dcSApple OSS Distributions }
216*2c2f96dcSApple OSS Distributions
217*2c2f96dcSApple OSS Distributions /*-
218*2c2f96dcSApple OSS Distributions * Copy in the name of the directory the filesystem
219*2c2f96dcSApple OSS Distributions * is to be mounted on.
220*2c2f96dcSApple OSS Distributions * And we clear the remainder of the character strings
221*2c2f96dcSApple OSS Distributions * to be tidy.
222*2c2f96dcSApple OSS Distributions */
223*2c2f96dcSApple OSS Distributions
224*2c2f96dcSApple OSS Distributions bzero(mp->mnt_vfsstat.f_mntfromname, MAXPATHLEN);
225*2c2f96dcSApple OSS Distributions bcopy("devfs", mp->mnt_vfsstat.f_mntfromname, 5);
226*2c2f96dcSApple OSS Distributions (void)devfs_statfs(mp, &mp->mnt_vfsstat, ctx);
227*2c2f96dcSApple OSS Distributions
228*2c2f96dcSApple OSS Distributions return 0;
229*2c2f96dcSApple OSS Distributions }
230*2c2f96dcSApple OSS Distributions
231*2c2f96dcSApple OSS Distributions
232*2c2f96dcSApple OSS Distributions static int
devfs_start(__unused struct mount * mp,__unused int flags,__unused vfs_context_t ctx)233*2c2f96dcSApple OSS Distributions devfs_start(__unused struct mount *mp, __unused int flags, __unused vfs_context_t ctx)
234*2c2f96dcSApple OSS Distributions {
235*2c2f96dcSApple OSS Distributions return 0;
236*2c2f96dcSApple OSS Distributions }
237*2c2f96dcSApple OSS Distributions
238*2c2f96dcSApple OSS Distributions /*-
239*2c2f96dcSApple OSS Distributions * Unmount the filesystem described by mp.
240*2c2f96dcSApple OSS Distributions */
241*2c2f96dcSApple OSS Distributions static int
devfs_unmount(struct mount * mp,int mntflags,__unused vfs_context_t ctx)242*2c2f96dcSApple OSS Distributions devfs_unmount( struct mount *mp, int mntflags, __unused vfs_context_t ctx)
243*2c2f96dcSApple OSS Distributions {
244*2c2f96dcSApple OSS Distributions struct devfsmount *devfs_mp_p = (struct devfsmount *)mp->mnt_data;
245*2c2f96dcSApple OSS Distributions int flags = 0;
246*2c2f96dcSApple OSS Distributions int force = 0;
247*2c2f96dcSApple OSS Distributions int error;
248*2c2f96dcSApple OSS Distributions
249*2c2f96dcSApple OSS Distributions if (mntflags & MNT_FORCE) {
250*2c2f96dcSApple OSS Distributions flags |= FORCECLOSE;
251*2c2f96dcSApple OSS Distributions force = 1;
252*2c2f96dcSApple OSS Distributions }
253*2c2f96dcSApple OSS Distributions error = vflush(mp, NULLVP, flags);
254*2c2f96dcSApple OSS Distributions if (error && !force) {
255*2c2f96dcSApple OSS Distributions return error;
256*2c2f96dcSApple OSS Distributions }
257*2c2f96dcSApple OSS Distributions
258*2c2f96dcSApple OSS Distributions DEVFS_LOCK();
259*2c2f96dcSApple OSS Distributions devfs_free_plane(devfs_mp_p);
260*2c2f96dcSApple OSS Distributions DEVFS_UNLOCK();
261*2c2f96dcSApple OSS Distributions
262*2c2f96dcSApple OSS Distributions DEVFS_DECR_MOUNTS();
263*2c2f96dcSApple OSS Distributions
264*2c2f96dcSApple OSS Distributions kfree_type(struct devfsmount, devfs_mp_p);
265*2c2f96dcSApple OSS Distributions mp->mnt_data = (qaddr_t)0;
266*2c2f96dcSApple OSS Distributions mp->mnt_flag &= ~MNT_LOCAL;
267*2c2f96dcSApple OSS Distributions
268*2c2f96dcSApple OSS Distributions return 0;
269*2c2f96dcSApple OSS Distributions }
270*2c2f96dcSApple OSS Distributions
271*2c2f96dcSApple OSS Distributions /* return the address of the root vnode in *vpp */
272*2c2f96dcSApple OSS Distributions static int
devfs_root(struct mount * mp,struct vnode ** vpp,__unused vfs_context_t ctx)273*2c2f96dcSApple OSS Distributions devfs_root(struct mount *mp, struct vnode **vpp, __unused vfs_context_t ctx)
274*2c2f96dcSApple OSS Distributions {
275*2c2f96dcSApple OSS Distributions struct devfsmount *devfs_mp_p = (struct devfsmount *)(mp->mnt_data);
276*2c2f96dcSApple OSS Distributions int error;
277*2c2f96dcSApple OSS Distributions
278*2c2f96dcSApple OSS Distributions DEVFS_LOCK();
279*2c2f96dcSApple OSS Distributions /* last parameter to devfs_dntovn() is ignored */
280*2c2f96dcSApple OSS Distributions error = devfs_dntovn(devfs_mp_p->plane_root->de_dnp, vpp, NULL);
281*2c2f96dcSApple OSS Distributions DEVFS_UNLOCK();
282*2c2f96dcSApple OSS Distributions
283*2c2f96dcSApple OSS Distributions return error;
284*2c2f96dcSApple OSS Distributions }
285*2c2f96dcSApple OSS Distributions
286*2c2f96dcSApple OSS Distributions static int
devfs_statfs(struct mount * mp,struct vfsstatfs * sbp,__unused vfs_context_t ctx)287*2c2f96dcSApple OSS Distributions devfs_statfs( struct mount *mp, struct vfsstatfs *sbp, __unused vfs_context_t ctx)
288*2c2f96dcSApple OSS Distributions {
289*2c2f96dcSApple OSS Distributions struct devfsmount *devfs_mp_p = (struct devfsmount *)mp->mnt_data;
290*2c2f96dcSApple OSS Distributions
291*2c2f96dcSApple OSS Distributions /*-
292*2c2f96dcSApple OSS Distributions * Fill in the stat block.
293*2c2f96dcSApple OSS Distributions */
294*2c2f96dcSApple OSS Distributions //sbp->f_type = mp->mnt_vfsstat.f_type;
295*2c2f96dcSApple OSS Distributions sbp->f_flags = 0; /* XXX */
296*2c2f96dcSApple OSS Distributions sbp->f_bsize = 512;
297*2c2f96dcSApple OSS Distributions sbp->f_iosize = 512;
298*2c2f96dcSApple OSS Distributions sbp->f_blocks = (devfs_stats.mounts * sizeof(struct devfsmount)
299*2c2f96dcSApple OSS Distributions + devfs_stats.nodes * sizeof(devnode_t)
300*2c2f96dcSApple OSS Distributions + devfs_stats.entries * sizeof(devdirent_t)
301*2c2f96dcSApple OSS Distributions + devfs_stats.stringspace
302*2c2f96dcSApple OSS Distributions ) / sbp->f_bsize;
303*2c2f96dcSApple OSS Distributions sbp->f_bfree = 0;
304*2c2f96dcSApple OSS Distributions sbp->f_bavail = 0;
305*2c2f96dcSApple OSS Distributions sbp->f_files = devfs_stats.nodes;
306*2c2f96dcSApple OSS Distributions sbp->f_ffree = 0;
307*2c2f96dcSApple OSS Distributions sbp->f_fsid.val[0] = (int32_t)VM_KERNEL_ADDRHASH(devfs_mp_p);
308*2c2f96dcSApple OSS Distributions sbp->f_fsid.val[1] = vfs_typenum(mp);
309*2c2f96dcSApple OSS Distributions
310*2c2f96dcSApple OSS Distributions return 0;
311*2c2f96dcSApple OSS Distributions }
312*2c2f96dcSApple OSS Distributions
313*2c2f96dcSApple OSS Distributions static int
devfs_vfs_getattr(__unused mount_t mp,struct vfs_attr * fsap,__unused vfs_context_t ctx)314*2c2f96dcSApple OSS Distributions devfs_vfs_getattr(__unused mount_t mp, struct vfs_attr *fsap, __unused vfs_context_t ctx)
315*2c2f96dcSApple OSS Distributions {
316*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_objcount, devfs_stats.nodes);
317*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_maxobjcount, devfs_stats.nodes);
318*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_bsize, 512);
319*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_iosize, 512);
320*2c2f96dcSApple OSS Distributions if (VFSATTR_IS_ACTIVE(fsap, f_blocks) || VFSATTR_IS_ACTIVE(fsap, f_bused)) {
321*2c2f96dcSApple OSS Distributions fsap->f_blocks = (devfs_stats.mounts * sizeof(struct devfsmount)
322*2c2f96dcSApple OSS Distributions + devfs_stats.nodes * sizeof(devnode_t)
323*2c2f96dcSApple OSS Distributions + devfs_stats.entries * sizeof(devdirent_t)
324*2c2f96dcSApple OSS Distributions + devfs_stats.stringspace
325*2c2f96dcSApple OSS Distributions ) / fsap->f_bsize;
326*2c2f96dcSApple OSS Distributions fsap->f_bused = fsap->f_blocks;
327*2c2f96dcSApple OSS Distributions VFSATTR_SET_SUPPORTED(fsap, f_blocks);
328*2c2f96dcSApple OSS Distributions VFSATTR_SET_SUPPORTED(fsap, f_bused);
329*2c2f96dcSApple OSS Distributions }
330*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_bfree, 0);
331*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_bavail, 0);
332*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_files, devfs_stats.nodes);
333*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_ffree, 0);
334*2c2f96dcSApple OSS Distributions VFSATTR_RETURN(fsap, f_fssubtype, 0);
335*2c2f96dcSApple OSS Distributions
336*2c2f96dcSApple OSS Distributions if (VFSATTR_IS_ACTIVE(fsap, f_capabilities)) {
337*2c2f96dcSApple OSS Distributions fsap->f_capabilities.capabilities[VOL_CAPABILITIES_FORMAT] =
338*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_SYMBOLICLINKS |
339*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_HARDLINKS |
340*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_NO_ROOT_TIMES |
341*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_CASE_SENSITIVE |
342*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_CASE_PRESERVING |
343*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_FAST_STATFS |
344*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_2TB_FILESIZE |
345*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_HIDDEN_FILES;
346*2c2f96dcSApple OSS Distributions fsap->f_capabilities.capabilities[VOL_CAPABILITIES_INTERFACES] =
347*2c2f96dcSApple OSS Distributions VOL_CAP_INT_ATTRLIST;
348*2c2f96dcSApple OSS Distributions fsap->f_capabilities.capabilities[VOL_CAPABILITIES_RESERVED1] = 0;
349*2c2f96dcSApple OSS Distributions fsap->f_capabilities.capabilities[VOL_CAPABILITIES_RESERVED2] = 0;
350*2c2f96dcSApple OSS Distributions
351*2c2f96dcSApple OSS Distributions fsap->f_capabilities.valid[VOL_CAPABILITIES_FORMAT] =
352*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_PERSISTENTOBJECTIDS |
353*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_SYMBOLICLINKS |
354*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_HARDLINKS |
355*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_JOURNAL |
356*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_JOURNAL_ACTIVE |
357*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_NO_ROOT_TIMES |
358*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_SPARSE_FILES |
359*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_ZERO_RUNS |
360*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_CASE_SENSITIVE |
361*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_CASE_PRESERVING |
362*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_FAST_STATFS |
363*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_2TB_FILESIZE |
364*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_OPENDENYMODES |
365*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_HIDDEN_FILES |
366*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_PATH_FROM_ID |
367*2c2f96dcSApple OSS Distributions VOL_CAP_FMT_NO_VOLUME_SIZES;
368*2c2f96dcSApple OSS Distributions fsap->f_capabilities.valid[VOL_CAPABILITIES_INTERFACES] =
369*2c2f96dcSApple OSS Distributions VOL_CAP_INT_SEARCHFS |
370*2c2f96dcSApple OSS Distributions VOL_CAP_INT_ATTRLIST |
371*2c2f96dcSApple OSS Distributions VOL_CAP_INT_NFSEXPORT |
372*2c2f96dcSApple OSS Distributions VOL_CAP_INT_READDIRATTR |
373*2c2f96dcSApple OSS Distributions VOL_CAP_INT_EXCHANGEDATA |
374*2c2f96dcSApple OSS Distributions VOL_CAP_INT_COPYFILE |
375*2c2f96dcSApple OSS Distributions VOL_CAP_INT_ALLOCATE |
376*2c2f96dcSApple OSS Distributions VOL_CAP_INT_VOL_RENAME |
377*2c2f96dcSApple OSS Distributions VOL_CAP_INT_ADVLOCK |
378*2c2f96dcSApple OSS Distributions VOL_CAP_INT_FLOCK |
379*2c2f96dcSApple OSS Distributions VOL_CAP_INT_EXTENDED_SECURITY |
380*2c2f96dcSApple OSS Distributions VOL_CAP_INT_USERACCESS |
381*2c2f96dcSApple OSS Distributions VOL_CAP_INT_MANLOCK |
382*2c2f96dcSApple OSS Distributions VOL_CAP_INT_EXTENDED_ATTR |
383*2c2f96dcSApple OSS Distributions VOL_CAP_INT_NAMEDSTREAMS;
384*2c2f96dcSApple OSS Distributions fsap->f_capabilities.valid[VOL_CAPABILITIES_RESERVED1] = 0;
385*2c2f96dcSApple OSS Distributions fsap->f_capabilities.valid[VOL_CAPABILITIES_RESERVED2] = 0;
386*2c2f96dcSApple OSS Distributions
387*2c2f96dcSApple OSS Distributions VFSATTR_SET_SUPPORTED(fsap, f_capabilities);
388*2c2f96dcSApple OSS Distributions }
389*2c2f96dcSApple OSS Distributions
390*2c2f96dcSApple OSS Distributions if (VFSATTR_IS_ACTIVE(fsap, f_attributes)) {
391*2c2f96dcSApple OSS Distributions fsap->f_attributes.validattr.commonattr =
392*2c2f96dcSApple OSS Distributions ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID |
393*2c2f96dcSApple OSS Distributions ATTR_CMN_OBJTYPE | ATTR_CMN_OBJTAG | ATTR_CMN_OBJID |
394*2c2f96dcSApple OSS Distributions ATTR_CMN_PAROBJID |
395*2c2f96dcSApple OSS Distributions ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | ATTR_CMN_ACCTIME |
396*2c2f96dcSApple OSS Distributions ATTR_CMN_OWNERID | ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK |
397*2c2f96dcSApple OSS Distributions ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS | ATTR_CMN_FILEID;
398*2c2f96dcSApple OSS Distributions fsap->f_attributes.validattr.volattr =
399*2c2f96dcSApple OSS Distributions ATTR_VOL_FSTYPE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE |
400*2c2f96dcSApple OSS Distributions ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION |
401*2c2f96dcSApple OSS Distributions ATTR_VOL_OBJCOUNT | ATTR_VOL_MAXOBJCOUNT |
402*2c2f96dcSApple OSS Distributions ATTR_VOL_MOUNTPOINT | ATTR_VOL_MOUNTFLAGS |
403*2c2f96dcSApple OSS Distributions ATTR_VOL_MOUNTEDDEVICE | ATTR_VOL_CAPABILITIES |
404*2c2f96dcSApple OSS Distributions ATTR_VOL_ATTRIBUTES;
405*2c2f96dcSApple OSS Distributions fsap->f_attributes.validattr.dirattr =
406*2c2f96dcSApple OSS Distributions ATTR_DIR_LINKCOUNT | ATTR_DIR_MOUNTSTATUS;
407*2c2f96dcSApple OSS Distributions fsap->f_attributes.validattr.fileattr =
408*2c2f96dcSApple OSS Distributions ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE |
409*2c2f96dcSApple OSS Distributions ATTR_FILE_IOBLOCKSIZE | ATTR_FILE_DEVTYPE |
410*2c2f96dcSApple OSS Distributions ATTR_FILE_DATALENGTH;
411*2c2f96dcSApple OSS Distributions fsap->f_attributes.validattr.forkattr = 0;
412*2c2f96dcSApple OSS Distributions
413*2c2f96dcSApple OSS Distributions fsap->f_attributes.nativeattr.commonattr =
414*2c2f96dcSApple OSS Distributions ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID |
415*2c2f96dcSApple OSS Distributions ATTR_CMN_OBJTYPE | ATTR_CMN_OBJTAG | ATTR_CMN_OBJID |
416*2c2f96dcSApple OSS Distributions ATTR_CMN_PAROBJID |
417*2c2f96dcSApple OSS Distributions ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | ATTR_CMN_ACCTIME |
418*2c2f96dcSApple OSS Distributions ATTR_CMN_OWNERID | ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK |
419*2c2f96dcSApple OSS Distributions ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS | ATTR_CMN_FILEID;
420*2c2f96dcSApple OSS Distributions fsap->f_attributes.nativeattr.volattr =
421*2c2f96dcSApple OSS Distributions ATTR_VOL_FSTYPE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE |
422*2c2f96dcSApple OSS Distributions ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION |
423*2c2f96dcSApple OSS Distributions ATTR_VOL_OBJCOUNT | ATTR_VOL_MAXOBJCOUNT |
424*2c2f96dcSApple OSS Distributions ATTR_VOL_MOUNTPOINT | ATTR_VOL_MOUNTFLAGS |
425*2c2f96dcSApple OSS Distributions ATTR_VOL_MOUNTEDDEVICE | ATTR_VOL_CAPABILITIES |
426*2c2f96dcSApple OSS Distributions ATTR_VOL_ATTRIBUTES;
427*2c2f96dcSApple OSS Distributions fsap->f_attributes.nativeattr.dirattr =
428*2c2f96dcSApple OSS Distributions ATTR_DIR_MOUNTSTATUS;
429*2c2f96dcSApple OSS Distributions fsap->f_attributes.nativeattr.fileattr =
430*2c2f96dcSApple OSS Distributions ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE |
431*2c2f96dcSApple OSS Distributions ATTR_FILE_IOBLOCKSIZE | ATTR_FILE_DEVTYPE |
432*2c2f96dcSApple OSS Distributions ATTR_FILE_DATALENGTH;
433*2c2f96dcSApple OSS Distributions fsap->f_attributes.nativeattr.forkattr = 0;
434*2c2f96dcSApple OSS Distributions
435*2c2f96dcSApple OSS Distributions VFSATTR_SET_SUPPORTED(fsap, f_attributes);
436*2c2f96dcSApple OSS Distributions }
437*2c2f96dcSApple OSS Distributions
438*2c2f96dcSApple OSS Distributions return 0;
439*2c2f96dcSApple OSS Distributions }
440*2c2f96dcSApple OSS Distributions
441*2c2f96dcSApple OSS Distributions static int
devfs_sync(__unused struct mount * mp,__unused int waitfor,__unused vfs_context_t ctx)442*2c2f96dcSApple OSS Distributions devfs_sync(__unused struct mount *mp, __unused int waitfor, __unused vfs_context_t ctx)
443*2c2f96dcSApple OSS Distributions {
444*2c2f96dcSApple OSS Distributions return 0;
445*2c2f96dcSApple OSS Distributions }
446*2c2f96dcSApple OSS Distributions
447*2c2f96dcSApple OSS Distributions
448*2c2f96dcSApple OSS Distributions static int
devfs_vget(__unused struct mount * mp,__unused ino64_t ino,__unused struct vnode ** vpp,__unused vfs_context_t ctx)449*2c2f96dcSApple OSS Distributions devfs_vget(__unused struct mount *mp, __unused ino64_t ino, __unused struct vnode **vpp, __unused vfs_context_t ctx)
450*2c2f96dcSApple OSS Distributions {
451*2c2f96dcSApple OSS Distributions return ENOTSUP;
452*2c2f96dcSApple OSS Distributions }
453*2c2f96dcSApple OSS Distributions
454*2c2f96dcSApple OSS Distributions /*************************************************************
455*2c2f96dcSApple OSS Distributions * The concept of exporting a kernel generated devfs is stupid
456*2c2f96dcSApple OSS Distributions * So don't handle filehandles
457*2c2f96dcSApple OSS Distributions */
458*2c2f96dcSApple OSS Distributions
459*2c2f96dcSApple OSS Distributions static int
devfs_fhtovp(__unused struct mount * mp,__unused int fhlen,__unused unsigned char * fhp,__unused struct vnode ** vpp,__unused vfs_context_t ctx)460*2c2f96dcSApple OSS Distributions devfs_fhtovp(__unused struct mount *mp, __unused int fhlen, __unused unsigned char *fhp, __unused struct vnode **vpp, __unused vfs_context_t ctx)
461*2c2f96dcSApple OSS Distributions {
462*2c2f96dcSApple OSS Distributions return EINVAL;
463*2c2f96dcSApple OSS Distributions }
464*2c2f96dcSApple OSS Distributions
465*2c2f96dcSApple OSS Distributions
466*2c2f96dcSApple OSS Distributions static int
devfs_vptofh(__unused struct vnode * vp,__unused int * fhlenp,__unused unsigned char * fhp,__unused vfs_context_t ctx)467*2c2f96dcSApple OSS Distributions devfs_vptofh(__unused struct vnode *vp, __unused int *fhlenp, __unused unsigned char *fhp, __unused vfs_context_t ctx)
468*2c2f96dcSApple OSS Distributions {
469*2c2f96dcSApple OSS Distributions return EINVAL;
470*2c2f96dcSApple OSS Distributions }
471*2c2f96dcSApple OSS Distributions
472*2c2f96dcSApple OSS Distributions static int
devfs_sysctl(__unused int * name,__unused u_int namelen,__unused user_addr_t oldp,__unused size_t * oldlenp,__unused user_addr_t newp,__unused size_t newlen,__unused vfs_context_t ctx)473*2c2f96dcSApple OSS Distributions devfs_sysctl(__unused int *name, __unused u_int namelen, __unused user_addr_t oldp,
474*2c2f96dcSApple OSS Distributions __unused size_t *oldlenp, __unused user_addr_t newp,
475*2c2f96dcSApple OSS Distributions __unused size_t newlen, __unused vfs_context_t ctx)
476*2c2f96dcSApple OSS Distributions {
477*2c2f96dcSApple OSS Distributions return ENOTSUP;
478*2c2f96dcSApple OSS Distributions }
479*2c2f96dcSApple OSS Distributions
480*2c2f96dcSApple OSS Distributions #include <sys/namei.h>
481*2c2f96dcSApple OSS Distributions
482*2c2f96dcSApple OSS Distributions /*
483*2c2f96dcSApple OSS Distributions * Function: devfs_kernel_mount
484*2c2f96dcSApple OSS Distributions * Purpose:
485*2c2f96dcSApple OSS Distributions * Mount devfs at the given mount point from within the kernel.
486*2c2f96dcSApple OSS Distributions */
487*2c2f96dcSApple OSS Distributions int
devfs_kernel_mount(char * mntname)488*2c2f96dcSApple OSS Distributions devfs_kernel_mount(char * mntname)
489*2c2f96dcSApple OSS Distributions {
490*2c2f96dcSApple OSS Distributions int error;
491*2c2f96dcSApple OSS Distributions vfs_context_t ctx = vfs_context_kernel();
492*2c2f96dcSApple OSS Distributions char fsname[] = "devfs";
493*2c2f96dcSApple OSS Distributions
494*2c2f96dcSApple OSS Distributions error = kernel_mount(fsname, NULLVP, NULLVP, mntname, NULL, 0, MNT_DONTBROWSE, KERNEL_MOUNT_NOAUTH | KERNEL_MOUNT_DEVFS, ctx);
495*2c2f96dcSApple OSS Distributions if (error) {
496*2c2f96dcSApple OSS Distributions printf("devfs_kernel_mount: kernel_mount failed: %d\n", error);
497*2c2f96dcSApple OSS Distributions return error;
498*2c2f96dcSApple OSS Distributions }
499*2c2f96dcSApple OSS Distributions
500*2c2f96dcSApple OSS Distributions return 0;
501*2c2f96dcSApple OSS Distributions }
502*2c2f96dcSApple OSS Distributions
503*2c2f96dcSApple OSS Distributions const struct vfsops devfs_vfsops = {
504*2c2f96dcSApple OSS Distributions .vfs_mount = devfs_mount,
505*2c2f96dcSApple OSS Distributions .vfs_start = devfs_start,
506*2c2f96dcSApple OSS Distributions .vfs_unmount = devfs_unmount,
507*2c2f96dcSApple OSS Distributions .vfs_root = devfs_root,
508*2c2f96dcSApple OSS Distributions .vfs_getattr = devfs_vfs_getattr,
509*2c2f96dcSApple OSS Distributions .vfs_sync = devfs_sync,
510*2c2f96dcSApple OSS Distributions .vfs_vget = devfs_vget,
511*2c2f96dcSApple OSS Distributions .vfs_fhtovp = devfs_fhtovp,
512*2c2f96dcSApple OSS Distributions .vfs_vptofh = devfs_vptofh,
513*2c2f96dcSApple OSS Distributions .vfs_init = devfs_init,
514*2c2f96dcSApple OSS Distributions .vfs_sysctl = devfs_sysctl,
515*2c2f96dcSApple OSS Distributions // There are other VFS ops that we do not support
516*2c2f96dcSApple OSS Distributions };
517