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