vfs_mount.c revision 219925
1/*- 2 * Copyright (c) 1999-2004 Poul-Henning Kamp 3 * Copyright (c) 1999 Michael Smith 4 * Copyright (c) 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD: head/sys/kern/vfs_mount.c 219925 2011-03-23 17:56:38Z jh $"); 39 40#include <sys/param.h> 41#include <sys/conf.h> 42#include <sys/fcntl.h> 43#include <sys/jail.h> 44#include <sys/kernel.h> 45#include <sys/libkern.h> 46#include <sys/malloc.h> 47#include <sys/mount.h> 48#include <sys/mutex.h> 49#include <sys/namei.h> 50#include <sys/priv.h> 51#include <sys/proc.h> 52#include <sys/filedesc.h> 53#include <sys/reboot.h> 54#include <sys/syscallsubr.h> 55#include <sys/sysproto.h> 56#include <sys/sx.h> 57#include <sys/sysctl.h> 58#include <sys/sysent.h> 59#include <sys/systm.h> 60#include <sys/vnode.h> 61#include <vm/uma.h> 62 63#include <geom/geom.h> 64 65#include <machine/stdarg.h> 66 67#include <security/audit/audit.h> 68#include <security/mac/mac_framework.h> 69 70#define VFS_MOUNTARG_SIZE_MAX (1024 * 64) 71 72static int vfs_domount(struct thread *td, const char *fstype, 73 char *fspath, int fsflags, struct vfsoptlist **optlist); 74static void free_mntarg(struct mntarg *ma); 75 76static int usermount = 0; 77SYSCTL_INT(_vfs, OID_AUTO, usermount, CTLFLAG_RW, &usermount, 0, 78 "Unprivileged users may mount and unmount file systems"); 79 80MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount structure"); 81MALLOC_DEFINE(M_VNODE_MARKER, "vnodemarker", "vnode marker"); 82static uma_zone_t mount_zone; 83 84/* List of mounted filesystems. */ 85struct mntlist mountlist = TAILQ_HEAD_INITIALIZER(mountlist); 86 87/* For any iteration/modification of mountlist */ 88struct mtx mountlist_mtx; 89MTX_SYSINIT(mountlist, &mountlist_mtx, "mountlist", MTX_DEF); 90 91/* 92 * Global opts, taken by all filesystems 93 */ 94static const char *global_opts[] = { 95 "errmsg", 96 "fstype", 97 "fspath", 98 "ro", 99 "rw", 100 "nosuid", 101 "noexec", 102 NULL 103}; 104 105static int 106mount_init(void *mem, int size, int flags) 107{ 108 struct mount *mp; 109 110 mp = (struct mount *)mem; 111 mtx_init(&mp->mnt_mtx, "struct mount mtx", NULL, MTX_DEF); 112 lockinit(&mp->mnt_explock, PVFS, "explock", 0, 0); 113 return (0); 114} 115 116static void 117mount_fini(void *mem, int size) 118{ 119 struct mount *mp; 120 121 mp = (struct mount *)mem; 122 lockdestroy(&mp->mnt_explock); 123 mtx_destroy(&mp->mnt_mtx); 124} 125 126static void 127vfs_mount_init(void *dummy __unused) 128{ 129 130 mount_zone = uma_zcreate("Mountpoints", sizeof(struct mount), NULL, 131 NULL, mount_init, mount_fini, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); 132} 133SYSINIT(vfs_mount, SI_SUB_VFS, SI_ORDER_ANY, vfs_mount_init, NULL); 134 135/* 136 * --------------------------------------------------------------------- 137 * Functions for building and sanitizing the mount options 138 */ 139 140/* Remove one mount option. */ 141static void 142vfs_freeopt(struct vfsoptlist *opts, struct vfsopt *opt) 143{ 144 145 TAILQ_REMOVE(opts, opt, link); 146 free(opt->name, M_MOUNT); 147 if (opt->value != NULL) 148 free(opt->value, M_MOUNT); 149 free(opt, M_MOUNT); 150} 151 152/* Release all resources related to the mount options. */ 153void 154vfs_freeopts(struct vfsoptlist *opts) 155{ 156 struct vfsopt *opt; 157 158 while (!TAILQ_EMPTY(opts)) { 159 opt = TAILQ_FIRST(opts); 160 vfs_freeopt(opts, opt); 161 } 162 free(opts, M_MOUNT); 163} 164 165void 166vfs_deleteopt(struct vfsoptlist *opts, const char *name) 167{ 168 struct vfsopt *opt, *temp; 169 170 if (opts == NULL) 171 return; 172 TAILQ_FOREACH_SAFE(opt, opts, link, temp) { 173 if (strcmp(opt->name, name) == 0) 174 vfs_freeopt(opts, opt); 175 } 176} 177 178static int 179vfs_isopt_ro(const char *opt) 180{ 181 182 if (strcmp(opt, "ro") == 0 || strcmp(opt, "rdonly") == 0 || 183 strcmp(opt, "norw") == 0) 184 return (1); 185 else 186 return (0); 187} 188 189static int 190vfs_isopt_rw(const char *opt) 191{ 192 193 if (strcmp(opt, "rw") == 0 || strcmp(opt, "noro") == 0) 194 return (1); 195 else 196 return (0); 197} 198 199/* 200 * Check if options are equal (with or without the "no" prefix). 201 */ 202static int 203vfs_equalopts(const char *opt1, const char *opt2) 204{ 205 char *p; 206 207 /* "opt" vs. "opt" or "noopt" vs. "noopt" */ 208 if (strcmp(opt1, opt2) == 0) 209 return (1); 210 /* "noopt" vs. "opt" */ 211 if (strncmp(opt1, "no", 2) == 0 && strcmp(opt1 + 2, opt2) == 0) 212 return (1); 213 /* "opt" vs. "noopt" */ 214 if (strncmp(opt2, "no", 2) == 0 && strcmp(opt1, opt2 + 2) == 0) 215 return (1); 216 while ((p = strchr(opt1, '.')) != NULL && 217 !strncmp(opt1, opt2, ++p - opt1)) { 218 opt2 += p - opt1; 219 opt1 = p; 220 /* "foo.noopt" vs. "foo.opt" */ 221 if (strncmp(opt1, "no", 2) == 0 && strcmp(opt1 + 2, opt2) == 0) 222 return (1); 223 /* "foo.opt" vs. "foo.noopt" */ 224 if (strncmp(opt2, "no", 2) == 0 && strcmp(opt1, opt2 + 2) == 0) 225 return (1); 226 } 227 /* "ro" / "rdonly" / "norw" / "rw" / "noro" */ 228 if ((vfs_isopt_ro(opt1) || vfs_isopt_rw(opt1)) && 229 (vfs_isopt_ro(opt2) || vfs_isopt_rw(opt2))) 230 return (1); 231 232 return (0); 233} 234 235/* 236 * If a mount option is specified several times, 237 * (with or without the "no" prefix) only keep 238 * the last occurence of it. 239 */ 240static void 241vfs_sanitizeopts(struct vfsoptlist *opts) 242{ 243 struct vfsopt *opt, *opt2, *tmp; 244 245 TAILQ_FOREACH_REVERSE(opt, opts, vfsoptlist, link) { 246 opt2 = TAILQ_PREV(opt, vfsoptlist, link); 247 while (opt2 != NULL) { 248 if (vfs_equalopts(opt->name, opt2->name)) { 249 tmp = TAILQ_PREV(opt2, vfsoptlist, link); 250 vfs_freeopt(opts, opt2); 251 opt2 = tmp; 252 } else { 253 opt2 = TAILQ_PREV(opt2, vfsoptlist, link); 254 } 255 } 256 } 257} 258 259/* 260 * Build a linked list of mount options from a struct uio. 261 */ 262int 263vfs_buildopts(struct uio *auio, struct vfsoptlist **options) 264{ 265 struct vfsoptlist *opts; 266 struct vfsopt *opt; 267 size_t memused, namelen, optlen; 268 unsigned int i, iovcnt; 269 int error; 270 271 opts = malloc(sizeof(struct vfsoptlist), M_MOUNT, M_WAITOK); 272 TAILQ_INIT(opts); 273 memused = 0; 274 iovcnt = auio->uio_iovcnt; 275 for (i = 0; i < iovcnt; i += 2) { 276 namelen = auio->uio_iov[i].iov_len; 277 optlen = auio->uio_iov[i + 1].iov_len; 278 memused += sizeof(struct vfsopt) + optlen + namelen; 279 /* 280 * Avoid consuming too much memory, and attempts to overflow 281 * memused. 282 */ 283 if (memused > VFS_MOUNTARG_SIZE_MAX || 284 optlen > VFS_MOUNTARG_SIZE_MAX || 285 namelen > VFS_MOUNTARG_SIZE_MAX) { 286 error = EINVAL; 287 goto bad; 288 } 289 290 opt = malloc(sizeof(struct vfsopt), M_MOUNT, M_WAITOK); 291 opt->name = malloc(namelen, M_MOUNT, M_WAITOK); 292 opt->value = NULL; 293 opt->len = 0; 294 opt->pos = i / 2; 295 opt->seen = 0; 296 297 /* 298 * Do this early, so jumps to "bad" will free the current 299 * option. 300 */ 301 TAILQ_INSERT_TAIL(opts, opt, link); 302 303 if (auio->uio_segflg == UIO_SYSSPACE) { 304 bcopy(auio->uio_iov[i].iov_base, opt->name, namelen); 305 } else { 306 error = copyin(auio->uio_iov[i].iov_base, opt->name, 307 namelen); 308 if (error) 309 goto bad; 310 } 311 /* Ensure names are null-terminated strings. */ 312 if (namelen == 0 || opt->name[namelen - 1] != '\0') { 313 error = EINVAL; 314 goto bad; 315 } 316 if (optlen != 0) { 317 opt->len = optlen; 318 opt->value = malloc(optlen, M_MOUNT, M_WAITOK); 319 if (auio->uio_segflg == UIO_SYSSPACE) { 320 bcopy(auio->uio_iov[i + 1].iov_base, opt->value, 321 optlen); 322 } else { 323 error = copyin(auio->uio_iov[i + 1].iov_base, 324 opt->value, optlen); 325 if (error) 326 goto bad; 327 } 328 } 329 } 330 vfs_sanitizeopts(opts); 331 *options = opts; 332 return (0); 333bad: 334 vfs_freeopts(opts); 335 return (error); 336} 337 338/* 339 * Merge the old mount options with the new ones passed 340 * in the MNT_UPDATE case. 341 * 342 * XXX This function will keep a "nofoo" option in the 343 * new options if there is no matching "foo" option 344 * to be cancelled in the old options. This is a bug 345 * if the option's canonical name is "foo". E.g., "noro" 346 * shouldn't end up in the mount point's active options, 347 * but it can. 348 */ 349static void 350vfs_mergeopts(struct vfsoptlist *toopts, struct vfsoptlist *opts) 351{ 352 struct vfsopt *opt, *opt2, *new; 353 354 TAILQ_FOREACH(opt, opts, link) { 355 /* 356 * Check that this option hasn't been redefined 357 * nor cancelled with a "no" mount option. 358 */ 359 opt2 = TAILQ_FIRST(toopts); 360 while (opt2 != NULL) { 361 if (strcmp(opt2->name, opt->name) == 0) 362 goto next; 363 if (strncmp(opt2->name, "no", 2) == 0 && 364 strcmp(opt2->name + 2, opt->name) == 0) { 365 vfs_freeopt(toopts, opt2); 366 goto next; 367 } 368 opt2 = TAILQ_NEXT(opt2, link); 369 } 370 /* We want this option, duplicate it. */ 371 new = malloc(sizeof(struct vfsopt), M_MOUNT, M_WAITOK); 372 new->name = malloc(strlen(opt->name) + 1, M_MOUNT, M_WAITOK); 373 strcpy(new->name, opt->name); 374 if (opt->len != 0) { 375 new->value = malloc(opt->len, M_MOUNT, M_WAITOK); 376 bcopy(opt->value, new->value, opt->len); 377 } else { 378 new->value = NULL; 379 } 380 new->len = opt->len; 381 new->seen = opt->seen; 382 TAILQ_INSERT_TAIL(toopts, new, link); 383next: 384 continue; 385 } 386} 387 388/* 389 * Mount a filesystem. 390 */ 391int 392nmount(td, uap) 393 struct thread *td; 394 struct nmount_args /* { 395 struct iovec *iovp; 396 unsigned int iovcnt; 397 int flags; 398 } */ *uap; 399{ 400 struct uio *auio; 401 int error; 402 u_int iovcnt; 403 404 AUDIT_ARG_FFLAGS(uap->flags); 405 CTR4(KTR_VFS, "%s: iovp %p with iovcnt %d and flags %d", __func__, 406 uap->iovp, uap->iovcnt, uap->flags); 407 408 /* 409 * Filter out MNT_ROOTFS. We do not want clients of nmount() in 410 * userspace to set this flag, but we must filter it out if we want 411 * MNT_UPDATE on the root file system to work. 412 * MNT_ROOTFS should only be set by the kernel when mounting its 413 * root file system. 414 */ 415 uap->flags &= ~MNT_ROOTFS; 416 417 iovcnt = uap->iovcnt; 418 /* 419 * Check that we have an even number of iovec's 420 * and that we have at least two options. 421 */ 422 if ((iovcnt & 1) || (iovcnt < 4)) { 423 CTR2(KTR_VFS, "%s: failed for invalid iovcnt %d", __func__, 424 uap->iovcnt); 425 return (EINVAL); 426 } 427 428 error = copyinuio(uap->iovp, iovcnt, &auio); 429 if (error) { 430 CTR2(KTR_VFS, "%s: failed for invalid uio op with %d errno", 431 __func__, error); 432 return (error); 433 } 434 error = vfs_donmount(td, uap->flags, auio); 435 436 free(auio, M_IOV); 437 return (error); 438} 439 440/* 441 * --------------------------------------------------------------------- 442 * Various utility functions 443 */ 444 445void 446vfs_ref(struct mount *mp) 447{ 448 449 CTR2(KTR_VFS, "%s: mp %p", __func__, mp); 450 MNT_ILOCK(mp); 451 MNT_REF(mp); 452 MNT_IUNLOCK(mp); 453} 454 455void 456vfs_rel(struct mount *mp) 457{ 458 459 CTR2(KTR_VFS, "%s: mp %p", __func__, mp); 460 MNT_ILOCK(mp); 461 MNT_REL(mp); 462 MNT_IUNLOCK(mp); 463} 464 465/* 466 * Allocate and initialize the mount point struct. 467 */ 468struct mount * 469vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp, const char *fspath, 470 struct ucred *cred) 471{ 472 struct mount *mp; 473 474 mp = uma_zalloc(mount_zone, M_WAITOK); 475 bzero(&mp->mnt_startzero, 476 __rangeof(struct mount, mnt_startzero, mnt_endzero)); 477 TAILQ_INIT(&mp->mnt_nvnodelist); 478 mp->mnt_nvnodelistsize = 0; 479 mp->mnt_ref = 0; 480 (void) vfs_busy(mp, MBF_NOWAIT); 481 mp->mnt_op = vfsp->vfc_vfsops; 482 mp->mnt_vfc = vfsp; 483 vfsp->vfc_refcount++; /* XXX Unlocked */ 484 mp->mnt_stat.f_type = vfsp->vfc_typenum; 485 mp->mnt_gen++; 486 strlcpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN); 487 mp->mnt_vnodecovered = vp; 488 mp->mnt_cred = crdup(cred); 489 mp->mnt_stat.f_owner = cred->cr_uid; 490 strlcpy(mp->mnt_stat.f_mntonname, fspath, MNAMELEN); 491 mp->mnt_iosize_max = DFLTPHYS; 492#ifdef MAC 493 mac_mount_init(mp); 494 mac_mount_create(cred, mp); 495#endif 496 arc4rand(&mp->mnt_hashseed, sizeof mp->mnt_hashseed, 0); 497 return (mp); 498} 499 500/* 501 * Destroy the mount struct previously allocated by vfs_mount_alloc(). 502 */ 503void 504vfs_mount_destroy(struct mount *mp) 505{ 506 507 MNT_ILOCK(mp); 508 mp->mnt_kern_flag |= MNTK_REFEXPIRE; 509 if (mp->mnt_kern_flag & MNTK_MWAIT) { 510 mp->mnt_kern_flag &= ~MNTK_MWAIT; 511 wakeup(mp); 512 } 513 while (mp->mnt_ref) 514 msleep(mp, MNT_MTX(mp), PVFS, "mntref", 0); 515 KASSERT(mp->mnt_ref == 0, 516 ("%s: invalid refcount in the drain path @ %s:%d", __func__, 517 __FILE__, __LINE__)); 518 if (mp->mnt_writeopcount != 0) 519 panic("vfs_mount_destroy: nonzero writeopcount"); 520 if (mp->mnt_secondary_writes != 0) 521 panic("vfs_mount_destroy: nonzero secondary_writes"); 522 mp->mnt_vfc->vfc_refcount--; 523 if (!TAILQ_EMPTY(&mp->mnt_nvnodelist)) { 524 struct vnode *vp; 525 526 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) 527 vprint("", vp); 528 panic("unmount: dangling vnode"); 529 } 530 if (mp->mnt_nvnodelistsize != 0) 531 panic("vfs_mount_destroy: nonzero nvnodelistsize"); 532 if (mp->mnt_lockref != 0) 533 panic("vfs_mount_destroy: nonzero lock refcount"); 534 MNT_IUNLOCK(mp); 535#ifdef MAC 536 mac_mount_destroy(mp); 537#endif 538 if (mp->mnt_opt != NULL) 539 vfs_freeopts(mp->mnt_opt); 540 crfree(mp->mnt_cred); 541 uma_zfree(mount_zone, mp); 542} 543 544int 545vfs_donmount(struct thread *td, int fsflags, struct uio *fsoptions) 546{ 547 struct vfsoptlist *optlist; 548 struct vfsopt *opt, *noro_opt, *tmp_opt; 549 char *fstype, *fspath, *errmsg; 550 int error, fstypelen, fspathlen, errmsg_len, errmsg_pos; 551 int has_rw, has_noro; 552 553 errmsg = fspath = NULL; 554 errmsg_len = has_noro = has_rw = fspathlen = 0; 555 errmsg_pos = -1; 556 557 error = vfs_buildopts(fsoptions, &optlist); 558 if (error) 559 return (error); 560 561 if (vfs_getopt(optlist, "errmsg", (void **)&errmsg, &errmsg_len) == 0) 562 errmsg_pos = vfs_getopt_pos(optlist, "errmsg"); 563 564 /* 565 * We need these two options before the others, 566 * and they are mandatory for any filesystem. 567 * Ensure they are NUL terminated as well. 568 */ 569 fstypelen = 0; 570 error = vfs_getopt(optlist, "fstype", (void **)&fstype, &fstypelen); 571 if (error || fstype[fstypelen - 1] != '\0') { 572 error = EINVAL; 573 if (errmsg != NULL) 574 strncpy(errmsg, "Invalid fstype", errmsg_len); 575 goto bail; 576 } 577 fspathlen = 0; 578 error = vfs_getopt(optlist, "fspath", (void **)&fspath, &fspathlen); 579 if (error || fspath[fspathlen - 1] != '\0') { 580 error = EINVAL; 581 if (errmsg != NULL) 582 strncpy(errmsg, "Invalid fspath", errmsg_len); 583 goto bail; 584 } 585 586 /* 587 * We need to see if we have the "update" option 588 * before we call vfs_domount(), since vfs_domount() has special 589 * logic based on MNT_UPDATE. This is very important 590 * when we want to update the root filesystem. 591 */ 592 TAILQ_FOREACH_SAFE(opt, optlist, link, tmp_opt) { 593 if (strcmp(opt->name, "update") == 0) { 594 fsflags |= MNT_UPDATE; 595 vfs_freeopt(optlist, opt); 596 } 597 else if (strcmp(opt->name, "async") == 0) 598 fsflags |= MNT_ASYNC; 599 else if (strcmp(opt->name, "force") == 0) { 600 fsflags |= MNT_FORCE; 601 vfs_freeopt(optlist, opt); 602 } 603 else if (strcmp(opt->name, "reload") == 0) { 604 fsflags |= MNT_RELOAD; 605 vfs_freeopt(optlist, opt); 606 } 607 else if (strcmp(opt->name, "multilabel") == 0) 608 fsflags |= MNT_MULTILABEL; 609 else if (strcmp(opt->name, "noasync") == 0) 610 fsflags &= ~MNT_ASYNC; 611 else if (strcmp(opt->name, "noatime") == 0) 612 fsflags |= MNT_NOATIME; 613 else if (strcmp(opt->name, "atime") == 0) { 614 free(opt->name, M_MOUNT); 615 opt->name = strdup("nonoatime", M_MOUNT); 616 } 617 else if (strcmp(opt->name, "noclusterr") == 0) 618 fsflags |= MNT_NOCLUSTERR; 619 else if (strcmp(opt->name, "clusterr") == 0) { 620 free(opt->name, M_MOUNT); 621 opt->name = strdup("nonoclusterr", M_MOUNT); 622 } 623 else if (strcmp(opt->name, "noclusterw") == 0) 624 fsflags |= MNT_NOCLUSTERW; 625 else if (strcmp(opt->name, "clusterw") == 0) { 626 free(opt->name, M_MOUNT); 627 opt->name = strdup("nonoclusterw", M_MOUNT); 628 } 629 else if (strcmp(opt->name, "noexec") == 0) 630 fsflags |= MNT_NOEXEC; 631 else if (strcmp(opt->name, "exec") == 0) { 632 free(opt->name, M_MOUNT); 633 opt->name = strdup("nonoexec", M_MOUNT); 634 } 635 else if (strcmp(opt->name, "nosuid") == 0) 636 fsflags |= MNT_NOSUID; 637 else if (strcmp(opt->name, "suid") == 0) { 638 free(opt->name, M_MOUNT); 639 opt->name = strdup("nonosuid", M_MOUNT); 640 } 641 else if (strcmp(opt->name, "nosymfollow") == 0) 642 fsflags |= MNT_NOSYMFOLLOW; 643 else if (strcmp(opt->name, "symfollow") == 0) { 644 free(opt->name, M_MOUNT); 645 opt->name = strdup("nonosymfollow", M_MOUNT); 646 } 647 else if (strcmp(opt->name, "noro") == 0) { 648 fsflags &= ~MNT_RDONLY; 649 has_noro = 1; 650 } 651 else if (strcmp(opt->name, "rw") == 0) { 652 fsflags &= ~MNT_RDONLY; 653 has_rw = 1; 654 } 655 else if (strcmp(opt->name, "ro") == 0) 656 fsflags |= MNT_RDONLY; 657 else if (strcmp(opt->name, "rdonly") == 0) { 658 free(opt->name, M_MOUNT); 659 opt->name = strdup("ro", M_MOUNT); 660 fsflags |= MNT_RDONLY; 661 } 662 else if (strcmp(opt->name, "suiddir") == 0) 663 fsflags |= MNT_SUIDDIR; 664 else if (strcmp(opt->name, "sync") == 0) 665 fsflags |= MNT_SYNCHRONOUS; 666 else if (strcmp(opt->name, "union") == 0) 667 fsflags |= MNT_UNION; 668 } 669 670 /* 671 * If "rw" was specified as a mount option, and we 672 * are trying to update a mount-point from "ro" to "rw", 673 * we need a mount option "noro", since in vfs_mergeopts(), 674 * "noro" will cancel "ro", but "rw" will not do anything. 675 */ 676 if (has_rw && !has_noro) { 677 noro_opt = malloc(sizeof(struct vfsopt), M_MOUNT, M_WAITOK); 678 noro_opt->name = strdup("noro", M_MOUNT); 679 noro_opt->value = NULL; 680 noro_opt->len = 0; 681 noro_opt->pos = -1; 682 noro_opt->seen = 1; 683 TAILQ_INSERT_TAIL(optlist, noro_opt, link); 684 } 685 686 /* 687 * Be ultra-paranoid about making sure the type and fspath 688 * variables will fit in our mp buffers, including the 689 * terminating NUL. 690 */ 691 if (fstypelen >= MFSNAMELEN - 1 || fspathlen >= MNAMELEN - 1) { 692 error = ENAMETOOLONG; 693 goto bail; 694 } 695 696 error = vfs_domount(td, fstype, fspath, fsflags, &optlist); 697bail: 698 /* copyout the errmsg */ 699 if (errmsg_pos != -1 && ((2 * errmsg_pos + 1) < fsoptions->uio_iovcnt) 700 && errmsg_len > 0 && errmsg != NULL) { 701 if (fsoptions->uio_segflg == UIO_SYSSPACE) { 702 bcopy(errmsg, 703 fsoptions->uio_iov[2 * errmsg_pos + 1].iov_base, 704 fsoptions->uio_iov[2 * errmsg_pos + 1].iov_len); 705 } else { 706 copyout(errmsg, 707 fsoptions->uio_iov[2 * errmsg_pos + 1].iov_base, 708 fsoptions->uio_iov[2 * errmsg_pos + 1].iov_len); 709 } 710 } 711 712 if (optlist != NULL) 713 vfs_freeopts(optlist); 714 return (error); 715} 716 717/* 718 * Old mount API. 719 */ 720#ifndef _SYS_SYSPROTO_H_ 721struct mount_args { 722 char *type; 723 char *path; 724 int flags; 725 caddr_t data; 726}; 727#endif 728/* ARGSUSED */ 729int 730mount(td, uap) 731 struct thread *td; 732 struct mount_args /* { 733 char *type; 734 char *path; 735 int flags; 736 caddr_t data; 737 } */ *uap; 738{ 739 char *fstype; 740 struct vfsconf *vfsp = NULL; 741 struct mntarg *ma = NULL; 742 int error; 743 744 AUDIT_ARG_FFLAGS(uap->flags); 745 746 /* 747 * Filter out MNT_ROOTFS. We do not want clients of mount() in 748 * userspace to set this flag, but we must filter it out if we want 749 * MNT_UPDATE on the root file system to work. 750 * MNT_ROOTFS should only be set by the kernel when mounting its 751 * root file system. 752 */ 753 uap->flags &= ~MNT_ROOTFS; 754 755 fstype = malloc(MFSNAMELEN, M_TEMP, M_WAITOK); 756 error = copyinstr(uap->type, fstype, MFSNAMELEN, NULL); 757 if (error) { 758 free(fstype, M_TEMP); 759 return (error); 760 } 761 762 AUDIT_ARG_TEXT(fstype); 763 mtx_lock(&Giant); 764 vfsp = vfs_byname_kld(fstype, td, &error); 765 free(fstype, M_TEMP); 766 if (vfsp == NULL) { 767 mtx_unlock(&Giant); 768 return (ENOENT); 769 } 770 if (vfsp->vfc_vfsops->vfs_cmount == NULL) { 771 mtx_unlock(&Giant); 772 return (EOPNOTSUPP); 773 } 774 775 ma = mount_argsu(ma, "fstype", uap->type, MNAMELEN); 776 ma = mount_argsu(ma, "fspath", uap->path, MNAMELEN); 777 ma = mount_argb(ma, uap->flags & MNT_RDONLY, "noro"); 778 ma = mount_argb(ma, !(uap->flags & MNT_NOSUID), "nosuid"); 779 ma = mount_argb(ma, !(uap->flags & MNT_NOEXEC), "noexec"); 780 781 error = vfsp->vfc_vfsops->vfs_cmount(ma, uap->data, uap->flags); 782 mtx_unlock(&Giant); 783 return (error); 784} 785 786/* 787 * vfs_domount_first(): first file system mount (not update) 788 */ 789static int 790vfs_domount_first( 791 struct thread *td, /* Calling thread. */ 792 struct vfsconf *vfsp, /* File system type. */ 793 char *fspath, /* Mount path. */ 794 struct vnode *vp, /* Vnode to be covered. */ 795 int fsflags, /* Flags common to all filesystems. */ 796 struct vfsoptlist **optlist /* Options local to the filesystem. */ 797 ) 798{ 799 struct vattr va; 800 struct mount *mp; 801 struct vnode *newdp; 802 int error; 803 804 mtx_assert(&Giant, MA_OWNED); 805 ASSERT_VOP_ELOCKED(vp, __func__); 806 KASSERT((fsflags & MNT_UPDATE) == 0, ("MNT_UPDATE shouldn't be here")); 807 808 /* 809 * If the user is not root, ensure that they own the directory 810 * onto which we are attempting to mount. 811 */ 812 error = VOP_GETATTR(vp, &va, td->td_ucred); 813 if (error == 0 && va.va_uid != td->td_ucred->cr_uid) 814 error = priv_check_cred(td->td_ucred, PRIV_VFS_ADMIN, 0); 815 if (error == 0) 816 error = vinvalbuf(vp, V_SAVE, 0, 0); 817 if (error == 0 && vp->v_type != VDIR) 818 error = ENOTDIR; 819 if (error == 0) { 820 VI_LOCK(vp); 821 if ((vp->v_iflag & VI_MOUNT) == 0 && vp->v_mountedhere == NULL) 822 vp->v_iflag |= VI_MOUNT; 823 else 824 error = EBUSY; 825 VI_UNLOCK(vp); 826 } 827 if (error != 0) { 828 vput(vp); 829 return (error); 830 } 831 VOP_UNLOCK(vp, 0); 832 833 /* Allocate and initialize the filesystem. */ 834 mp = vfs_mount_alloc(vp, vfsp, fspath, td->td_ucred); 835 /* XXXMAC: pass to vfs_mount_alloc? */ 836 mp->mnt_optnew = *optlist; 837 /* Set the mount level flags. */ 838 mp->mnt_flag = (fsflags & (MNT_UPDATEMASK | MNT_ROOTFS | MNT_RDONLY)); 839 840 /* 841 * Mount the filesystem. 842 * XXX The final recipients of VFS_MOUNT just overwrite the ndp they 843 * get. No freeing of cn_pnbuf. 844 */ 845 error = VFS_MOUNT(mp); 846 if (error != 0) { 847 vfs_unbusy(mp); 848 vfs_mount_destroy(mp); 849 VI_LOCK(vp); 850 vp->v_iflag &= ~VI_MOUNT; 851 VI_UNLOCK(vp); 852 vrele(vp); 853 return (error); 854 } 855 856 if (mp->mnt_opt != NULL) 857 vfs_freeopts(mp->mnt_opt); 858 mp->mnt_opt = mp->mnt_optnew; 859 *optlist = NULL; 860 (void)VFS_STATFS(mp, &mp->mnt_stat); 861 862 /* 863 * Prevent external consumers of mount options from reading mnt_optnew. 864 */ 865 mp->mnt_optnew = NULL; 866 867 MNT_ILOCK(mp); 868 if ((mp->mnt_flag & MNT_ASYNC) != 0 && mp->mnt_noasync == 0) 869 mp->mnt_kern_flag |= MNTK_ASYNC; 870 else 871 mp->mnt_kern_flag &= ~MNTK_ASYNC; 872 MNT_IUNLOCK(mp); 873 874 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 875 cache_purge(vp); 876 VI_LOCK(vp); 877 vp->v_iflag &= ~VI_MOUNT; 878 VI_UNLOCK(vp); 879 vp->v_mountedhere = mp; 880 /* Place the new filesystem at the end of the mount list. */ 881 mtx_lock(&mountlist_mtx); 882 TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list); 883 mtx_unlock(&mountlist_mtx); 884 vfs_event_signal(NULL, VQ_MOUNT, 0); 885 if (VFS_ROOT(mp, LK_EXCLUSIVE, &newdp)) 886 panic("mount: lost mount"); 887 VOP_UNLOCK(newdp, 0); 888 VOP_UNLOCK(vp, 0); 889 mountcheckdirs(vp, newdp); 890 vrele(newdp); 891 if ((mp->mnt_flag & MNT_RDONLY) == 0) 892 vfs_allocate_syncvnode(mp); 893 vfs_unbusy(mp); 894 return (0); 895} 896 897/* 898 * vfs_domount_update(): update of mounted file system 899 */ 900static int 901vfs_domount_update( 902 struct thread *td, /* Calling thread. */ 903 struct vnode *vp, /* Mount point vnode. */ 904 int fsflags, /* Flags common to all filesystems. */ 905 struct vfsoptlist **optlist /* Options local to the filesystem. */ 906 ) 907{ 908 struct oexport_args oexport; 909 struct export_args export; 910 struct mount *mp; 911 int error, export_error, flag; 912 913 mtx_assert(&Giant, MA_OWNED); 914 ASSERT_VOP_ELOCKED(vp, __func__); 915 KASSERT((fsflags & MNT_UPDATE) != 0, ("MNT_UPDATE should be here")); 916 917 if ((vp->v_vflag & VV_ROOT) == 0) { 918 vput(vp); 919 return (EINVAL); 920 } 921 mp = vp->v_mount; 922 /* 923 * We only allow the filesystem to be reloaded if it 924 * is currently mounted read-only. 925 */ 926 flag = mp->mnt_flag; 927 if ((fsflags & MNT_RELOAD) != 0 && (flag & MNT_RDONLY) == 0) { 928 vput(vp); 929 return (EOPNOTSUPP); /* Needs translation */ 930 } 931 /* 932 * Only privileged root, or (if MNT_USER is set) the user that 933 * did the original mount is permitted to update it. 934 */ 935 error = vfs_suser(mp, td); 936 if (error != 0) { 937 vput(vp); 938 return (error); 939 } 940 if (vfs_busy(mp, MBF_NOWAIT)) { 941 vput(vp); 942 return (EBUSY); 943 } 944 VI_LOCK(vp); 945 if ((vp->v_iflag & VI_MOUNT) != 0 || vp->v_mountedhere != NULL) { 946 VI_UNLOCK(vp); 947 vfs_unbusy(mp); 948 vput(vp); 949 return (EBUSY); 950 } 951 vp->v_iflag |= VI_MOUNT; 952 VI_UNLOCK(vp); 953 VOP_UNLOCK(vp, 0); 954 955 MNT_ILOCK(mp); 956 mp->mnt_flag &= ~MNT_UPDATEMASK; 957 mp->mnt_flag |= fsflags & (MNT_RELOAD | MNT_FORCE | MNT_UPDATE | 958 MNT_SNAPSHOT | MNT_ROOTFS | MNT_UPDATEMASK | MNT_RDONLY); 959 if ((mp->mnt_flag & MNT_ASYNC) == 0) 960 mp->mnt_kern_flag &= ~MNTK_ASYNC; 961 MNT_IUNLOCK(mp); 962 mp->mnt_optnew = *optlist; 963 vfs_mergeopts(mp->mnt_optnew, mp->mnt_opt); 964 965 /* 966 * Mount the filesystem. 967 * XXX The final recipients of VFS_MOUNT just overwrite the ndp they 968 * get. No freeing of cn_pnbuf. 969 */ 970 error = VFS_MOUNT(mp); 971 972 export_error = 0; 973 if (error == 0) { 974 /* Process the export option. */ 975 if (vfs_copyopt(mp->mnt_optnew, "export", &export, 976 sizeof(export)) == 0) { 977 export_error = vfs_export(mp, &export); 978 } else if (vfs_copyopt(mp->mnt_optnew, "export", &oexport, 979 sizeof(oexport)) == 0) { 980 export.ex_flags = oexport.ex_flags; 981 export.ex_root = oexport.ex_root; 982 export.ex_anon = oexport.ex_anon; 983 export.ex_addr = oexport.ex_addr; 984 export.ex_addrlen = oexport.ex_addrlen; 985 export.ex_mask = oexport.ex_mask; 986 export.ex_masklen = oexport.ex_masklen; 987 export.ex_indexfile = oexport.ex_indexfile; 988 export.ex_numsecflavors = 0; 989 export_error = vfs_export(mp, &export); 990 } 991 } 992 993 MNT_ILOCK(mp); 994 if (error == 0) { 995 mp->mnt_flag &= ~(MNT_UPDATE | MNT_RELOAD | MNT_FORCE | 996 MNT_SNAPSHOT); 997 } else { 998 /* 999 * If we fail, restore old mount flags. MNT_QUOTA is special, 1000 * because it is not part of MNT_UPDATEMASK, but it could have 1001 * changed in the meantime if quotactl(2) was called. 1002 * All in all we want current value of MNT_QUOTA, not the old 1003 * one. 1004 */ 1005 mp->mnt_flag = (mp->mnt_flag & MNT_QUOTA) | (flag & ~MNT_QUOTA); 1006 } 1007 if ((mp->mnt_flag & MNT_ASYNC) != 0 && mp->mnt_noasync == 0) 1008 mp->mnt_kern_flag |= MNTK_ASYNC; 1009 else 1010 mp->mnt_kern_flag &= ~MNTK_ASYNC; 1011 MNT_IUNLOCK(mp); 1012 1013 if (error != 0) 1014 goto end; 1015 1016 if (mp->mnt_opt != NULL) 1017 vfs_freeopts(mp->mnt_opt); 1018 mp->mnt_opt = mp->mnt_optnew; 1019 *optlist = NULL; 1020 (void)VFS_STATFS(mp, &mp->mnt_stat); 1021 /* 1022 * Prevent external consumers of mount options from reading 1023 * mnt_optnew. 1024 */ 1025 mp->mnt_optnew = NULL; 1026 1027 if ((mp->mnt_flag & MNT_RDONLY) == 0) 1028 vfs_allocate_syncvnode(mp); 1029 else 1030 vfs_deallocate_syncvnode(mp); 1031end: 1032 vfs_unbusy(mp); 1033 VI_LOCK(vp); 1034 vp->v_iflag &= ~VI_MOUNT; 1035 VI_UNLOCK(vp); 1036 vrele(vp); 1037 return (error != 0 ? error : export_error); 1038} 1039 1040/* 1041 * vfs_domount(): actually attempt a filesystem mount. 1042 */ 1043static int 1044vfs_domount( 1045 struct thread *td, /* Calling thread. */ 1046 const char *fstype, /* Filesystem type. */ 1047 char *fspath, /* Mount path. */ 1048 int fsflags, /* Flags common to all filesystems. */ 1049 struct vfsoptlist **optlist /* Options local to the filesystem. */ 1050 ) 1051{ 1052 struct vfsconf *vfsp; 1053 struct nameidata nd; 1054 struct vnode *vp; 1055 int error; 1056 1057 /* 1058 * Be ultra-paranoid about making sure the type and fspath 1059 * variables will fit in our mp buffers, including the 1060 * terminating NUL. 1061 */ 1062 if (strlen(fstype) >= MFSNAMELEN || strlen(fspath) >= MNAMELEN) 1063 return (ENAMETOOLONG); 1064 1065 if (jailed(td->td_ucred) || usermount == 0) { 1066 if ((error = priv_check(td, PRIV_VFS_MOUNT)) != 0) 1067 return (error); 1068 } 1069 1070 /* 1071 * Do not allow NFS export or MNT_SUIDDIR by unprivileged users. 1072 */ 1073 if (fsflags & MNT_EXPORTED) { 1074 error = priv_check(td, PRIV_VFS_MOUNT_EXPORTED); 1075 if (error) 1076 return (error); 1077 } 1078 if (fsflags & MNT_SUIDDIR) { 1079 error = priv_check(td, PRIV_VFS_MOUNT_SUIDDIR); 1080 if (error) 1081 return (error); 1082 } 1083 /* 1084 * Silently enforce MNT_NOSUID and MNT_USER for unprivileged users. 1085 */ 1086 if ((fsflags & (MNT_NOSUID | MNT_USER)) != (MNT_NOSUID | MNT_USER)) { 1087 if (priv_check(td, PRIV_VFS_MOUNT_NONUSER) != 0) 1088 fsflags |= MNT_NOSUID | MNT_USER; 1089 } 1090 1091 /* Load KLDs before we lock the covered vnode to avoid reversals. */ 1092 vfsp = NULL; 1093 if ((fsflags & MNT_UPDATE) == 0) { 1094 /* Don't try to load KLDs if we're mounting the root. */ 1095 if (fsflags & MNT_ROOTFS) 1096 vfsp = vfs_byname(fstype); 1097 else 1098 vfsp = vfs_byname_kld(fstype, td, &error); 1099 if (vfsp == NULL) 1100 return (ENODEV); 1101 if (jailed(td->td_ucred) && !(vfsp->vfc_flags & VFCF_JAIL)) 1102 return (EPERM); 1103 } 1104 1105 /* 1106 * Get vnode to be covered or mount point's vnode in case of MNT_UPDATE. 1107 */ 1108 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1, 1109 UIO_SYSSPACE, fspath, td); 1110 error = namei(&nd); 1111 if (error != 0) 1112 return (error); 1113 if (!NDHASGIANT(&nd)) 1114 mtx_lock(&Giant); 1115 NDFREE(&nd, NDF_ONLY_PNBUF); 1116 vp = nd.ni_vp; 1117 if ((fsflags & MNT_UPDATE) == 0) { 1118 error = vfs_domount_first(td, vfsp, fspath, vp, fsflags, 1119 optlist); 1120 } else { 1121 error = vfs_domount_update(td, vp, fsflags, optlist); 1122 } 1123 mtx_unlock(&Giant); 1124 1125 ASSERT_VI_UNLOCKED(vp, __func__); 1126 ASSERT_VOP_UNLOCKED(vp, __func__); 1127 1128 return (error); 1129} 1130 1131/* 1132 * Unmount a filesystem. 1133 * 1134 * Note: unmount takes a path to the vnode mounted on as argument, not 1135 * special file (as before). 1136 */ 1137#ifndef _SYS_SYSPROTO_H_ 1138struct unmount_args { 1139 char *path; 1140 int flags; 1141}; 1142#endif 1143/* ARGSUSED */ 1144int 1145unmount(td, uap) 1146 struct thread *td; 1147 register struct unmount_args /* { 1148 char *path; 1149 int flags; 1150 } */ *uap; 1151{ 1152 struct mount *mp; 1153 char *pathbuf; 1154 int error, id0, id1; 1155 1156 AUDIT_ARG_VALUE(uap->flags); 1157 if (jailed(td->td_ucred) || usermount == 0) { 1158 error = priv_check(td, PRIV_VFS_UNMOUNT); 1159 if (error) 1160 return (error); 1161 } 1162 1163 pathbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK); 1164 error = copyinstr(uap->path, pathbuf, MNAMELEN, NULL); 1165 if (error) { 1166 free(pathbuf, M_TEMP); 1167 return (error); 1168 } 1169 mtx_lock(&Giant); 1170 if (uap->flags & MNT_BYFSID) { 1171 AUDIT_ARG_TEXT(pathbuf); 1172 /* Decode the filesystem ID. */ 1173 if (sscanf(pathbuf, "FSID:%d:%d", &id0, &id1) != 2) { 1174 mtx_unlock(&Giant); 1175 free(pathbuf, M_TEMP); 1176 return (EINVAL); 1177 } 1178 1179 mtx_lock(&mountlist_mtx); 1180 TAILQ_FOREACH_REVERSE(mp, &mountlist, mntlist, mnt_list) { 1181 if (mp->mnt_stat.f_fsid.val[0] == id0 && 1182 mp->mnt_stat.f_fsid.val[1] == id1) 1183 break; 1184 } 1185 mtx_unlock(&mountlist_mtx); 1186 } else { 1187 AUDIT_ARG_UPATH1(td, pathbuf); 1188 mtx_lock(&mountlist_mtx); 1189 TAILQ_FOREACH_REVERSE(mp, &mountlist, mntlist, mnt_list) { 1190 if (strcmp(mp->mnt_stat.f_mntonname, pathbuf) == 0) 1191 break; 1192 } 1193 mtx_unlock(&mountlist_mtx); 1194 } 1195 free(pathbuf, M_TEMP); 1196 if (mp == NULL) { 1197 /* 1198 * Previously we returned ENOENT for a nonexistent path and 1199 * EINVAL for a non-mountpoint. We cannot tell these apart 1200 * now, so in the !MNT_BYFSID case return the more likely 1201 * EINVAL for compatibility. 1202 */ 1203 mtx_unlock(&Giant); 1204 return ((uap->flags & MNT_BYFSID) ? ENOENT : EINVAL); 1205 } 1206 1207 /* 1208 * Don't allow unmounting the root filesystem. 1209 */ 1210 if (mp->mnt_flag & MNT_ROOTFS) { 1211 mtx_unlock(&Giant); 1212 return (EINVAL); 1213 } 1214 error = dounmount(mp, uap->flags, td); 1215 mtx_unlock(&Giant); 1216 return (error); 1217} 1218 1219/* 1220 * Do the actual filesystem unmount. 1221 */ 1222int 1223dounmount(mp, flags, td) 1224 struct mount *mp; 1225 int flags; 1226 struct thread *td; 1227{ 1228 struct vnode *coveredvp, *fsrootvp; 1229 int error; 1230 int async_flag; 1231 int mnt_gen_r; 1232 1233 mtx_assert(&Giant, MA_OWNED); 1234 1235 if ((coveredvp = mp->mnt_vnodecovered) != NULL) { 1236 mnt_gen_r = mp->mnt_gen; 1237 VI_LOCK(coveredvp); 1238 vholdl(coveredvp); 1239 vn_lock(coveredvp, LK_EXCLUSIVE | LK_INTERLOCK | LK_RETRY); 1240 vdrop(coveredvp); 1241 /* 1242 * Check for mp being unmounted while waiting for the 1243 * covered vnode lock. 1244 */ 1245 if (coveredvp->v_mountedhere != mp || 1246 coveredvp->v_mountedhere->mnt_gen != mnt_gen_r) { 1247 VOP_UNLOCK(coveredvp, 0); 1248 return (EBUSY); 1249 } 1250 } 1251 /* 1252 * Only privileged root, or (if MNT_USER is set) the user that did the 1253 * original mount is permitted to unmount this filesystem. 1254 */ 1255 error = vfs_suser(mp, td); 1256 if (error) { 1257 if (coveredvp) 1258 VOP_UNLOCK(coveredvp, 0); 1259 return (error); 1260 } 1261 1262 MNT_ILOCK(mp); 1263 if (mp->mnt_kern_flag & MNTK_UNMOUNT) { 1264 MNT_IUNLOCK(mp); 1265 if (coveredvp) 1266 VOP_UNLOCK(coveredvp, 0); 1267 return (EBUSY); 1268 } 1269 mp->mnt_kern_flag |= MNTK_UNMOUNT | MNTK_NOINSMNTQ; 1270 /* Allow filesystems to detect that a forced unmount is in progress. */ 1271 if (flags & MNT_FORCE) 1272 mp->mnt_kern_flag |= MNTK_UNMOUNTF; 1273 error = 0; 1274 if (mp->mnt_lockref) { 1275 if ((flags & MNT_FORCE) == 0) { 1276 mp->mnt_kern_flag &= ~(MNTK_UNMOUNT | MNTK_NOINSMNTQ | 1277 MNTK_UNMOUNTF); 1278 if (mp->mnt_kern_flag & MNTK_MWAIT) { 1279 mp->mnt_kern_flag &= ~MNTK_MWAIT; 1280 wakeup(mp); 1281 } 1282 MNT_IUNLOCK(mp); 1283 if (coveredvp) 1284 VOP_UNLOCK(coveredvp, 0); 1285 return (EBUSY); 1286 } 1287 mp->mnt_kern_flag |= MNTK_DRAINING; 1288 error = msleep(&mp->mnt_lockref, MNT_MTX(mp), PVFS, 1289 "mount drain", 0); 1290 } 1291 MNT_IUNLOCK(mp); 1292 KASSERT(mp->mnt_lockref == 0, 1293 ("%s: invalid lock refcount in the drain path @ %s:%d", 1294 __func__, __FILE__, __LINE__)); 1295 KASSERT(error == 0, 1296 ("%s: invalid return value for msleep in the drain path @ %s:%d", 1297 __func__, __FILE__, __LINE__)); 1298 vn_start_write(NULL, &mp, V_WAIT); 1299 1300 if (mp->mnt_flag & MNT_EXPUBLIC) 1301 vfs_setpublicfs(NULL, NULL, NULL); 1302 1303 vfs_msync(mp, MNT_WAIT); 1304 MNT_ILOCK(mp); 1305 async_flag = mp->mnt_flag & MNT_ASYNC; 1306 mp->mnt_flag &= ~MNT_ASYNC; 1307 mp->mnt_kern_flag &= ~MNTK_ASYNC; 1308 MNT_IUNLOCK(mp); 1309 cache_purgevfs(mp); /* remove cache entries for this file sys */ 1310 vfs_deallocate_syncvnode(mp); 1311 /* 1312 * For forced unmounts, move process cdir/rdir refs on the fs root 1313 * vnode to the covered vnode. For non-forced unmounts we want 1314 * such references to cause an EBUSY error. 1315 */ 1316 if ((flags & MNT_FORCE) && 1317 VFS_ROOT(mp, LK_EXCLUSIVE, &fsrootvp) == 0) { 1318 if (mp->mnt_vnodecovered != NULL) 1319 mountcheckdirs(fsrootvp, mp->mnt_vnodecovered); 1320 if (fsrootvp == rootvnode) { 1321 vrele(rootvnode); 1322 rootvnode = NULL; 1323 } 1324 vput(fsrootvp); 1325 } 1326 if (((mp->mnt_flag & MNT_RDONLY) || 1327 (error = VFS_SYNC(mp, MNT_WAIT)) == 0) || (flags & MNT_FORCE) != 0) 1328 error = VFS_UNMOUNT(mp, flags); 1329 vn_finished_write(mp); 1330 /* 1331 * If we failed to flush the dirty blocks for this mount point, 1332 * undo all the cdir/rdir and rootvnode changes we made above. 1333 * Unless we failed to do so because the device is reporting that 1334 * it doesn't exist anymore. 1335 */ 1336 if (error && error != ENXIO) { 1337 if ((flags & MNT_FORCE) && 1338 VFS_ROOT(mp, LK_EXCLUSIVE, &fsrootvp) == 0) { 1339 if (mp->mnt_vnodecovered != NULL) 1340 mountcheckdirs(mp->mnt_vnodecovered, fsrootvp); 1341 if (rootvnode == NULL) { 1342 rootvnode = fsrootvp; 1343 vref(rootvnode); 1344 } 1345 vput(fsrootvp); 1346 } 1347 MNT_ILOCK(mp); 1348 mp->mnt_kern_flag &= ~MNTK_NOINSMNTQ; 1349 if ((mp->mnt_flag & MNT_RDONLY) == 0) { 1350 MNT_IUNLOCK(mp); 1351 vfs_allocate_syncvnode(mp); 1352 MNT_ILOCK(mp); 1353 } 1354 mp->mnt_kern_flag &= ~(MNTK_UNMOUNT | MNTK_UNMOUNTF); 1355 mp->mnt_flag |= async_flag; 1356 if ((mp->mnt_flag & MNT_ASYNC) != 0 && mp->mnt_noasync == 0) 1357 mp->mnt_kern_flag |= MNTK_ASYNC; 1358 if (mp->mnt_kern_flag & MNTK_MWAIT) { 1359 mp->mnt_kern_flag &= ~MNTK_MWAIT; 1360 wakeup(mp); 1361 } 1362 MNT_IUNLOCK(mp); 1363 if (coveredvp) 1364 VOP_UNLOCK(coveredvp, 0); 1365 return (error); 1366 } 1367 mtx_lock(&mountlist_mtx); 1368 TAILQ_REMOVE(&mountlist, mp, mnt_list); 1369 mtx_unlock(&mountlist_mtx); 1370 if (coveredvp != NULL) { 1371 coveredvp->v_mountedhere = NULL; 1372 vput(coveredvp); 1373 } 1374 vfs_event_signal(NULL, VQ_UNMOUNT, 0); 1375 vfs_mount_destroy(mp); 1376 return (0); 1377} 1378 1379/* 1380 * Report errors during filesystem mounting. 1381 */ 1382void 1383vfs_mount_error(struct mount *mp, const char *fmt, ...) 1384{ 1385 struct vfsoptlist *moptlist = mp->mnt_optnew; 1386 va_list ap; 1387 int error, len; 1388 char *errmsg; 1389 1390 error = vfs_getopt(moptlist, "errmsg", (void **)&errmsg, &len); 1391 if (error || errmsg == NULL || len <= 0) 1392 return; 1393 1394 va_start(ap, fmt); 1395 vsnprintf(errmsg, (size_t)len, fmt, ap); 1396 va_end(ap); 1397} 1398 1399void 1400vfs_opterror(struct vfsoptlist *opts, const char *fmt, ...) 1401{ 1402 va_list ap; 1403 int error, len; 1404 char *errmsg; 1405 1406 error = vfs_getopt(opts, "errmsg", (void **)&errmsg, &len); 1407 if (error || errmsg == NULL || len <= 0) 1408 return; 1409 1410 va_start(ap, fmt); 1411 vsnprintf(errmsg, (size_t)len, fmt, ap); 1412 va_end(ap); 1413} 1414 1415/* 1416 * --------------------------------------------------------------------- 1417 * Functions for querying mount options/arguments from filesystems. 1418 */ 1419 1420/* 1421 * Check that no unknown options are given 1422 */ 1423int 1424vfs_filteropt(struct vfsoptlist *opts, const char **legal) 1425{ 1426 struct vfsopt *opt; 1427 char errmsg[255]; 1428 const char **t, *p, *q; 1429 int ret = 0; 1430 1431 TAILQ_FOREACH(opt, opts, link) { 1432 p = opt->name; 1433 q = NULL; 1434 if (p[0] == 'n' && p[1] == 'o') 1435 q = p + 2; 1436 for(t = global_opts; *t != NULL; t++) { 1437 if (strcmp(*t, p) == 0) 1438 break; 1439 if (q != NULL) { 1440 if (strcmp(*t, q) == 0) 1441 break; 1442 } 1443 } 1444 if (*t != NULL) 1445 continue; 1446 for(t = legal; *t != NULL; t++) { 1447 if (strcmp(*t, p) == 0) 1448 break; 1449 if (q != NULL) { 1450 if (strcmp(*t, q) == 0) 1451 break; 1452 } 1453 } 1454 if (*t != NULL) 1455 continue; 1456 snprintf(errmsg, sizeof(errmsg), 1457 "mount option <%s> is unknown", p); 1458 ret = EINVAL; 1459 } 1460 if (ret != 0) { 1461 TAILQ_FOREACH(opt, opts, link) { 1462 if (strcmp(opt->name, "errmsg") == 0) { 1463 strncpy((char *)opt->value, errmsg, opt->len); 1464 break; 1465 } 1466 } 1467 if (opt == NULL) 1468 printf("%s\n", errmsg); 1469 } 1470 return (ret); 1471} 1472 1473/* 1474 * Get a mount option by its name. 1475 * 1476 * Return 0 if the option was found, ENOENT otherwise. 1477 * If len is non-NULL it will be filled with the length 1478 * of the option. If buf is non-NULL, it will be filled 1479 * with the address of the option. 1480 */ 1481int 1482vfs_getopt(opts, name, buf, len) 1483 struct vfsoptlist *opts; 1484 const char *name; 1485 void **buf; 1486 int *len; 1487{ 1488 struct vfsopt *opt; 1489 1490 KASSERT(opts != NULL, ("vfs_getopt: caller passed 'opts' as NULL")); 1491 1492 TAILQ_FOREACH(opt, opts, link) { 1493 if (strcmp(name, opt->name) == 0) { 1494 opt->seen = 1; 1495 if (len != NULL) 1496 *len = opt->len; 1497 if (buf != NULL) 1498 *buf = opt->value; 1499 return (0); 1500 } 1501 } 1502 return (ENOENT); 1503} 1504 1505int 1506vfs_getopt_pos(struct vfsoptlist *opts, const char *name) 1507{ 1508 struct vfsopt *opt; 1509 1510 if (opts == NULL) 1511 return (-1); 1512 1513 TAILQ_FOREACH(opt, opts, link) { 1514 if (strcmp(name, opt->name) == 0) { 1515 opt->seen = 1; 1516 return (opt->pos); 1517 } 1518 } 1519 return (-1); 1520} 1521 1522char * 1523vfs_getopts(struct vfsoptlist *opts, const char *name, int *error) 1524{ 1525 struct vfsopt *opt; 1526 1527 *error = 0; 1528 TAILQ_FOREACH(opt, opts, link) { 1529 if (strcmp(name, opt->name) != 0) 1530 continue; 1531 opt->seen = 1; 1532 if (opt->len == 0 || 1533 ((char *)opt->value)[opt->len - 1] != '\0') { 1534 *error = EINVAL; 1535 return (NULL); 1536 } 1537 return (opt->value); 1538 } 1539 *error = ENOENT; 1540 return (NULL); 1541} 1542 1543int 1544vfs_flagopt(struct vfsoptlist *opts, const char *name, u_int *w, u_int val) 1545{ 1546 struct vfsopt *opt; 1547 1548 TAILQ_FOREACH(opt, opts, link) { 1549 if (strcmp(name, opt->name) == 0) { 1550 opt->seen = 1; 1551 if (w != NULL) 1552 *w |= val; 1553 return (1); 1554 } 1555 } 1556 if (w != NULL) 1557 *w &= ~val; 1558 return (0); 1559} 1560 1561int 1562vfs_scanopt(struct vfsoptlist *opts, const char *name, const char *fmt, ...) 1563{ 1564 va_list ap; 1565 struct vfsopt *opt; 1566 int ret; 1567 1568 KASSERT(opts != NULL, ("vfs_getopt: caller passed 'opts' as NULL")); 1569 1570 TAILQ_FOREACH(opt, opts, link) { 1571 if (strcmp(name, opt->name) != 0) 1572 continue; 1573 opt->seen = 1; 1574 if (opt->len == 0 || opt->value == NULL) 1575 return (0); 1576 if (((char *)opt->value)[opt->len - 1] != '\0') 1577 return (0); 1578 va_start(ap, fmt); 1579 ret = vsscanf(opt->value, fmt, ap); 1580 va_end(ap); 1581 return (ret); 1582 } 1583 return (0); 1584} 1585 1586int 1587vfs_setopt(struct vfsoptlist *opts, const char *name, void *value, int len) 1588{ 1589 struct vfsopt *opt; 1590 1591 TAILQ_FOREACH(opt, opts, link) { 1592 if (strcmp(name, opt->name) != 0) 1593 continue; 1594 opt->seen = 1; 1595 if (opt->value == NULL) 1596 opt->len = len; 1597 else { 1598 if (opt->len != len) 1599 return (EINVAL); 1600 bcopy(value, opt->value, len); 1601 } 1602 return (0); 1603 } 1604 return (ENOENT); 1605} 1606 1607int 1608vfs_setopt_part(struct vfsoptlist *opts, const char *name, void *value, int len) 1609{ 1610 struct vfsopt *opt; 1611 1612 TAILQ_FOREACH(opt, opts, link) { 1613 if (strcmp(name, opt->name) != 0) 1614 continue; 1615 opt->seen = 1; 1616 if (opt->value == NULL) 1617 opt->len = len; 1618 else { 1619 if (opt->len < len) 1620 return (EINVAL); 1621 opt->len = len; 1622 bcopy(value, opt->value, len); 1623 } 1624 return (0); 1625 } 1626 return (ENOENT); 1627} 1628 1629int 1630vfs_setopts(struct vfsoptlist *opts, const char *name, const char *value) 1631{ 1632 struct vfsopt *opt; 1633 1634 TAILQ_FOREACH(opt, opts, link) { 1635 if (strcmp(name, opt->name) != 0) 1636 continue; 1637 opt->seen = 1; 1638 if (opt->value == NULL) 1639 opt->len = strlen(value) + 1; 1640 else if (strlcpy(opt->value, value, opt->len) >= opt->len) 1641 return (EINVAL); 1642 return (0); 1643 } 1644 return (ENOENT); 1645} 1646 1647/* 1648 * Find and copy a mount option. 1649 * 1650 * The size of the buffer has to be specified 1651 * in len, if it is not the same length as the 1652 * mount option, EINVAL is returned. 1653 * Returns ENOENT if the option is not found. 1654 */ 1655int 1656vfs_copyopt(opts, name, dest, len) 1657 struct vfsoptlist *opts; 1658 const char *name; 1659 void *dest; 1660 int len; 1661{ 1662 struct vfsopt *opt; 1663 1664 KASSERT(opts != NULL, ("vfs_copyopt: caller passed 'opts' as NULL")); 1665 1666 TAILQ_FOREACH(opt, opts, link) { 1667 if (strcmp(name, opt->name) == 0) { 1668 opt->seen = 1; 1669 if (len != opt->len) 1670 return (EINVAL); 1671 bcopy(opt->value, dest, opt->len); 1672 return (0); 1673 } 1674 } 1675 return (ENOENT); 1676} 1677 1678/* 1679 * This is a helper function for filesystems to traverse their 1680 * vnodes. See MNT_VNODE_FOREACH() in sys/mount.h 1681 */ 1682 1683struct vnode * 1684__mnt_vnode_next(struct vnode **mvp, struct mount *mp) 1685{ 1686 struct vnode *vp; 1687 1688 mtx_assert(MNT_MTX(mp), MA_OWNED); 1689 1690 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch")); 1691 if (should_yield()) { 1692 MNT_IUNLOCK(mp); 1693 kern_yield(-1); 1694 MNT_ILOCK(mp); 1695 } 1696 vp = TAILQ_NEXT(*mvp, v_nmntvnodes); 1697 while (vp != NULL && vp->v_type == VMARKER) 1698 vp = TAILQ_NEXT(vp, v_nmntvnodes); 1699 1700 /* Check if we are done */ 1701 if (vp == NULL) { 1702 __mnt_vnode_markerfree(mvp, mp); 1703 return (NULL); 1704 } 1705 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes); 1706 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes); 1707 return (vp); 1708} 1709 1710struct vnode * 1711__mnt_vnode_first(struct vnode **mvp, struct mount *mp) 1712{ 1713 struct vnode *vp; 1714 1715 mtx_assert(MNT_MTX(mp), MA_OWNED); 1716 1717 vp = TAILQ_FIRST(&mp->mnt_nvnodelist); 1718 while (vp != NULL && vp->v_type == VMARKER) 1719 vp = TAILQ_NEXT(vp, v_nmntvnodes); 1720 1721 /* Check if we are done */ 1722 if (vp == NULL) { 1723 *mvp = NULL; 1724 return (NULL); 1725 } 1726 MNT_REF(mp); 1727 MNT_IUNLOCK(mp); 1728 *mvp = (struct vnode *) malloc(sizeof(struct vnode), 1729 M_VNODE_MARKER, 1730 M_WAITOK | M_ZERO); 1731 MNT_ILOCK(mp); 1732 (*mvp)->v_type = VMARKER; 1733 1734 vp = TAILQ_FIRST(&mp->mnt_nvnodelist); 1735 while (vp != NULL && vp->v_type == VMARKER) 1736 vp = TAILQ_NEXT(vp, v_nmntvnodes); 1737 1738 /* Check if we are done */ 1739 if (vp == NULL) { 1740 MNT_IUNLOCK(mp); 1741 free(*mvp, M_VNODE_MARKER); 1742 MNT_ILOCK(mp); 1743 *mvp = NULL; 1744 MNT_REL(mp); 1745 return (NULL); 1746 } 1747 (*mvp)->v_mount = mp; 1748 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes); 1749 return (vp); 1750} 1751 1752 1753void 1754__mnt_vnode_markerfree(struct vnode **mvp, struct mount *mp) 1755{ 1756 1757 if (*mvp == NULL) 1758 return; 1759 1760 mtx_assert(MNT_MTX(mp), MA_OWNED); 1761 1762 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch")); 1763 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes); 1764 MNT_IUNLOCK(mp); 1765 free(*mvp, M_VNODE_MARKER); 1766 MNT_ILOCK(mp); 1767 *mvp = NULL; 1768 MNT_REL(mp); 1769} 1770 1771 1772int 1773__vfs_statfs(struct mount *mp, struct statfs *sbp) 1774{ 1775 int error; 1776 1777 error = mp->mnt_op->vfs_statfs(mp, &mp->mnt_stat); 1778 if (sbp != &mp->mnt_stat) 1779 *sbp = mp->mnt_stat; 1780 return (error); 1781} 1782 1783void 1784vfs_mountedfrom(struct mount *mp, const char *from) 1785{ 1786 1787 bzero(mp->mnt_stat.f_mntfromname, sizeof mp->mnt_stat.f_mntfromname); 1788 strlcpy(mp->mnt_stat.f_mntfromname, from, 1789 sizeof mp->mnt_stat.f_mntfromname); 1790} 1791 1792/* 1793 * --------------------------------------------------------------------- 1794 * This is the api for building mount args and mounting filesystems from 1795 * inside the kernel. 1796 * 1797 * The API works by accumulation of individual args. First error is 1798 * latched. 1799 * 1800 * XXX: should be documented in new manpage kernel_mount(9) 1801 */ 1802 1803/* A memory allocation which must be freed when we are done */ 1804struct mntaarg { 1805 SLIST_ENTRY(mntaarg) next; 1806}; 1807 1808/* The header for the mount arguments */ 1809struct mntarg { 1810 struct iovec *v; 1811 int len; 1812 int error; 1813 SLIST_HEAD(, mntaarg) list; 1814}; 1815 1816/* 1817 * Add a boolean argument. 1818 * 1819 * flag is the boolean value. 1820 * name must start with "no". 1821 */ 1822struct mntarg * 1823mount_argb(struct mntarg *ma, int flag, const char *name) 1824{ 1825 1826 KASSERT(name[0] == 'n' && name[1] == 'o', 1827 ("mount_argb(...,%s): name must start with 'no'", name)); 1828 1829 return (mount_arg(ma, name + (flag ? 2 : 0), NULL, 0)); 1830} 1831 1832/* 1833 * Add an argument printf style 1834 */ 1835struct mntarg * 1836mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...) 1837{ 1838 va_list ap; 1839 struct mntaarg *maa; 1840 struct sbuf *sb; 1841 int len; 1842 1843 if (ma == NULL) { 1844 ma = malloc(sizeof *ma, M_MOUNT, M_WAITOK | M_ZERO); 1845 SLIST_INIT(&ma->list); 1846 } 1847 if (ma->error) 1848 return (ma); 1849 1850 ma->v = realloc(ma->v, sizeof *ma->v * (ma->len + 2), 1851 M_MOUNT, M_WAITOK); 1852 ma->v[ma->len].iov_base = (void *)(uintptr_t)name; 1853 ma->v[ma->len].iov_len = strlen(name) + 1; 1854 ma->len++; 1855 1856 sb = sbuf_new_auto(); 1857 va_start(ap, fmt); 1858 sbuf_vprintf(sb, fmt, ap); 1859 va_end(ap); 1860 sbuf_finish(sb); 1861 len = sbuf_len(sb) + 1; 1862 maa = malloc(sizeof *maa + len, M_MOUNT, M_WAITOK | M_ZERO); 1863 SLIST_INSERT_HEAD(&ma->list, maa, next); 1864 bcopy(sbuf_data(sb), maa + 1, len); 1865 sbuf_delete(sb); 1866 1867 ma->v[ma->len].iov_base = maa + 1; 1868 ma->v[ma->len].iov_len = len; 1869 ma->len++; 1870 1871 return (ma); 1872} 1873 1874/* 1875 * Add an argument which is a userland string. 1876 */ 1877struct mntarg * 1878mount_argsu(struct mntarg *ma, const char *name, const void *val, int len) 1879{ 1880 struct mntaarg *maa; 1881 char *tbuf; 1882 1883 if (val == NULL) 1884 return (ma); 1885 if (ma == NULL) { 1886 ma = malloc(sizeof *ma, M_MOUNT, M_WAITOK | M_ZERO); 1887 SLIST_INIT(&ma->list); 1888 } 1889 if (ma->error) 1890 return (ma); 1891 maa = malloc(sizeof *maa + len, M_MOUNT, M_WAITOK | M_ZERO); 1892 SLIST_INSERT_HEAD(&ma->list, maa, next); 1893 tbuf = (void *)(maa + 1); 1894 ma->error = copyinstr(val, tbuf, len, NULL); 1895 return (mount_arg(ma, name, tbuf, -1)); 1896} 1897 1898/* 1899 * Plain argument. 1900 * 1901 * If length is -1, treat value as a C string. 1902 */ 1903struct mntarg * 1904mount_arg(struct mntarg *ma, const char *name, const void *val, int len) 1905{ 1906 1907 if (ma == NULL) { 1908 ma = malloc(sizeof *ma, M_MOUNT, M_WAITOK | M_ZERO); 1909 SLIST_INIT(&ma->list); 1910 } 1911 if (ma->error) 1912 return (ma); 1913 1914 ma->v = realloc(ma->v, sizeof *ma->v * (ma->len + 2), 1915 M_MOUNT, M_WAITOK); 1916 ma->v[ma->len].iov_base = (void *)(uintptr_t)name; 1917 ma->v[ma->len].iov_len = strlen(name) + 1; 1918 ma->len++; 1919 1920 ma->v[ma->len].iov_base = (void *)(uintptr_t)val; 1921 if (len < 0) 1922 ma->v[ma->len].iov_len = strlen(val) + 1; 1923 else 1924 ma->v[ma->len].iov_len = len; 1925 ma->len++; 1926 return (ma); 1927} 1928 1929/* 1930 * Free a mntarg structure 1931 */ 1932static void 1933free_mntarg(struct mntarg *ma) 1934{ 1935 struct mntaarg *maa; 1936 1937 while (!SLIST_EMPTY(&ma->list)) { 1938 maa = SLIST_FIRST(&ma->list); 1939 SLIST_REMOVE_HEAD(&ma->list, next); 1940 free(maa, M_MOUNT); 1941 } 1942 free(ma->v, M_MOUNT); 1943 free(ma, M_MOUNT); 1944} 1945 1946/* 1947 * Mount a filesystem 1948 */ 1949int 1950kernel_mount(struct mntarg *ma, int flags) 1951{ 1952 struct uio auio; 1953 int error; 1954 1955 KASSERT(ma != NULL, ("kernel_mount NULL ma")); 1956 KASSERT(ma->v != NULL, ("kernel_mount NULL ma->v")); 1957 KASSERT(!(ma->len & 1), ("kernel_mount odd ma->len (%d)", ma->len)); 1958 1959 auio.uio_iov = ma->v; 1960 auio.uio_iovcnt = ma->len; 1961 auio.uio_segflg = UIO_SYSSPACE; 1962 1963 error = ma->error; 1964 if (!error) 1965 error = vfs_donmount(curthread, flags, &auio); 1966 free_mntarg(ma); 1967 return (error); 1968} 1969 1970/* 1971 * A printflike function to mount a filesystem. 1972 */ 1973int 1974kernel_vmount(int flags, ...) 1975{ 1976 struct mntarg *ma = NULL; 1977 va_list ap; 1978 const char *cp; 1979 const void *vp; 1980 int error; 1981 1982 va_start(ap, flags); 1983 for (;;) { 1984 cp = va_arg(ap, const char *); 1985 if (cp == NULL) 1986 break; 1987 vp = va_arg(ap, const void *); 1988 ma = mount_arg(ma, cp, vp, (vp != NULL ? -1 : 0)); 1989 } 1990 va_end(ap); 1991 1992 error = kernel_mount(ma, flags); 1993 return (error); 1994} 1995 1996void 1997vfs_oexport_conv(const struct oexport_args *oexp, struct export_args *exp) 1998{ 1999 2000 bcopy(oexp, exp, sizeof(*oexp)); 2001 exp->ex_numsecflavors = 0; 2002} 2003