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