2 * Copyright (c) 2010 Marcel Moolenaar
3 * Copyright (c) 1999-2004 Poul-Henning Kamp
4 * Copyright (c) 1999 Michael Smith
5 * Copyright (c) 1989, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "opt_rootdevname.h"
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <sys/param.h>
46 #include <sys/fcntl.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/mdioctl.h>
51 #include <sys/mount.h>
52 #include <sys/mutex.h>
53 #include <sys/namei.h>
56 #include <sys/filedesc.h>
57 #include <sys/reboot.h>
60 #include <sys/syscallsubr.h>
61 #include <sys/sysproto.h>
63 #include <sys/sysctl.h>
64 #include <sys/sysent.h>
65 #include <sys/systm.h>
66 #include <sys/vnode.h>
68 #include <geom/geom.h>
71 * The root filesystem is detailed in the kernel environment variable
72 * vfs.root.mountfrom, which is expected to be in the general format
74 * <vfsname>:[<path>][ <vfsname>:[<path>] ...]
75 * vfsname := the name of a VFS known to the kernel and capable
76 * of being mounted as root
77 * path := disk device name or other data used by the filesystem
78 * to locate its physical store
80 * If the environment variable vfs.root.mountfrom is a space separated list,
81 * each list element is tried in turn and the root filesystem will be mounted
82 * from the first one that suceeds.
84 * The environment variable vfs.root.mountfrom.options is a comma delimited
85 * set of string mount options. These mount options must be parseable
86 * by nmount() in the kernel.
89 static int parse_mount(char **);
90 static struct mntarg *parse_mountroot_options(struct mntarg *, const char *);
93 * The vnode of the system's root (/ in the filesystem, without chroot
96 struct vnode *rootvnode;
99 * Mount of the system's /dev.
101 struct mount *rootdevmp;
103 char *rootdevnames[2] = {NULL, NULL};
105 struct mtx root_holds_mtx;
106 MTX_SYSINIT(root_holds, &root_holds_mtx, "root_holds", MTX_DEF);
108 struct root_hold_token {
110 LIST_ENTRY(root_hold_token) list;
113 static LIST_HEAD(, root_hold_token) root_holds =
114 LIST_HEAD_INITIALIZER(root_holds);
123 static enum action root_mount_onfail = A_CONTINUE;
125 static int root_mount_mddev;
126 static int root_mount_complete;
128 /* By default wait up to 3 seconds for devices to appear. */
129 static int root_mount_timeout = 3;
130 TUNABLE_INT("vfs.mountroot.timeout", &root_mount_timeout);
132 struct root_hold_token *
133 root_mount_hold(const char *identifier)
135 struct root_hold_token *h;
140 h = malloc(sizeof *h, M_DEVBUF, M_ZERO | M_WAITOK);
142 mtx_lock(&root_holds_mtx);
143 LIST_INSERT_HEAD(&root_holds, h, list);
144 mtx_unlock(&root_holds_mtx);
149 root_mount_rel(struct root_hold_token *h)
154 mtx_lock(&root_holds_mtx);
155 LIST_REMOVE(h, list);
157 mtx_unlock(&root_holds_mtx);
165 /* No mutex is acquired here because int stores are atomic. */
166 return (root_mount_complete);
170 root_mount_wait(void)
174 * Panic on an obvious deadlock - the function can't be called from
175 * a thread which is doing the whole SYSINIT stuff.
177 KASSERT(curthread->td_proc->p_pid != 0,
178 ("root_mount_wait: cannot be called from the swapper thread"));
179 mtx_lock(&root_holds_mtx);
180 while (!root_mount_complete) {
181 msleep(&root_mount_complete, &root_holds_mtx, PZERO, "rootwait",
184 mtx_unlock(&root_holds_mtx);
192 if (VFS_ROOT(TAILQ_FIRST(&mountlist), LK_EXCLUSIVE, &rootvnode))
193 panic("Cannot find root vnode");
195 VOP_UNLOCK(rootvnode, 0);
197 p = curthread->td_proc;
198 FILEDESC_XLOCK(p->p_fd);
200 if (p->p_fd->fd_cdir != NULL)
201 vrele(p->p_fd->fd_cdir);
202 p->p_fd->fd_cdir = rootvnode;
205 if (p->p_fd->fd_rdir != NULL)
206 vrele(p->p_fd->fd_rdir);
207 p->p_fd->fd_rdir = rootvnode;
210 FILEDESC_XUNLOCK(p->p_fd);
214 vfs_mountroot_devfs(struct thread *td, struct mount **mpp)
216 struct vfsoptlist *opts;
217 struct vfsconf *vfsp;
223 if (rootdevmp != NULL) {
225 * Already have /dev; this happens during rerooting.
227 error = vfs_busy(rootdevmp, 0);
232 vfsp = vfs_byname("devfs");
233 KASSERT(vfsp != NULL, ("Could not find devfs by name"));
237 mp = vfs_mount_alloc(NULLVP, vfsp, "/dev", td->td_ucred);
239 error = VFS_MOUNT(mp);
240 KASSERT(error == 0, ("VFS_MOUNT(devfs) failed %d", error));
244 opts = malloc(sizeof(struct vfsoptlist), M_MOUNT, M_WAITOK);
248 mtx_lock(&mountlist_mtx);
249 TAILQ_INSERT_HEAD(&mountlist, mp, mnt_list);
250 mtx_unlock(&mountlist_mtx);
258 error = kern_symlinkat(td, "/", AT_FDCWD, "dev", UIO_SYSSPACE);
260 printf("kern_symlink /dev -> / returns %d\n", error);
266 vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs)
269 struct mount *mporoot, *mpnroot;
270 struct vnode *vp, *vporoot, *vpdevfs;
274 mpnroot = TAILQ_NEXT(mpdevfs, mnt_list);
276 /* Shuffle the mountlist. */
277 mtx_lock(&mountlist_mtx);
278 mporoot = TAILQ_FIRST(&mountlist);
279 TAILQ_REMOVE(&mountlist, mpdevfs, mnt_list);
280 if (mporoot != mpdevfs) {
281 TAILQ_REMOVE(&mountlist, mpnroot, mnt_list);
282 TAILQ_INSERT_HEAD(&mountlist, mpnroot, mnt_list);
284 TAILQ_INSERT_TAIL(&mountlist, mpdevfs, mnt_list);
285 mtx_unlock(&mountlist_mtx);
287 cache_purgevfs(mporoot);
288 if (mporoot != mpdevfs)
289 cache_purgevfs(mpdevfs);
291 VFS_ROOT(mporoot, LK_EXCLUSIVE, &vporoot);
294 vporoot->v_iflag &= ~VI_MOUNT;
296 vporoot->v_mountedhere = NULL;
297 mporoot->mnt_flag &= ~MNT_ROOTFS;
298 mporoot->mnt_vnodecovered = NULL;
301 /* Set up the new rootvnode, and purge the cache */
302 mpnroot->mnt_vnodecovered = NULL;
304 cache_purgevfs(rootvnode->v_mount);
306 if (mporoot != mpdevfs) {
307 /* Remount old root under /.mount or /mnt */
309 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
313 NDFREE(&nd, NDF_ONLY_PNBUF);
315 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
321 error = (vp->v_type == VDIR) ? 0 : ENOTDIR;
323 error = vinvalbuf(vp, V_SAVE, 0, 0);
326 mporoot->mnt_vnodecovered = vp;
327 vp->v_mountedhere = mporoot;
328 strlcpy(mporoot->mnt_stat.f_mntonname,
334 NDFREE(&nd, NDF_ONLY_PNBUF);
336 if (error && bootverbose)
337 printf("mountroot: unable to remount previous root "
338 "under /.mount or /mnt (error %d).\n", error);
341 /* Remount devfs under /dev */
342 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, "/dev", td);
346 error = (vp->v_type == VDIR) ? 0 : ENOTDIR;
348 error = vinvalbuf(vp, V_SAVE, 0, 0);
350 vpdevfs = mpdevfs->mnt_vnodecovered;
351 if (vpdevfs != NULL) {
352 cache_purge(vpdevfs);
353 vpdevfs->v_mountedhere = NULL;
356 mpdevfs->mnt_vnodecovered = vp;
357 vp->v_mountedhere = mpdevfs;
362 if (error && bootverbose)
363 printf("mountroot: unable to remount devfs under /dev "
364 "(error %d).\n", error);
365 NDFREE(&nd, NDF_ONLY_PNBUF);
367 if (mporoot == mpdevfs) {
369 /* Unlink the no longer needed /dev/dev -> / symlink */
370 error = kern_unlinkat(td, AT_FDCWD, "/dev/dev",
372 if (error && bootverbose)
373 printf("mountroot: unable to unlink /dev/dev "
374 "(error %d)\n", error);
379 * Configuration parser.
382 /* Parser character classes. */
383 #define CC_WHITESPACE -1
384 #define CC_NONWHITESPACE -2
391 parse_peek(char **conf)
398 parse_poke(char **conf, int c)
405 parse_advance(char **conf)
412 parse_skipto(char **conf, int mc)
417 c = parse_peek(conf);
422 match = (c == ' ' || c == '\t' || c == '\n') ? 1 : 0;
424 case CC_NONWHITESPACE:
427 match = (c != ' ' && c != '\t') ? 1 : 0;
430 match = (c == mc) ? 1 : 0;
441 parse_token(char **conf, char **tok)
448 error = parse_skipto(conf, CC_NONWHITESPACE);
452 error = parse_skipto(conf, CC_WHITESPACE);
454 *tok = malloc(len + 1, M_TEMP, M_WAITOK | M_ZERO);
460 parse_dir_ask_printenv(const char *var)
464 val = kern_getenv(var);
466 printf(" %s=%s\n", var, val);
472 parse_dir_ask(char **conf)
478 printf("\nLoader variables:\n");
479 parse_dir_ask_printenv("vfs.root.mountfrom");
480 parse_dir_ask_printenv("vfs.root.mountfrom.options");
482 printf("\nManual root filesystem specification:\n");
483 printf(" <fstype>:<device> [options]\n");
484 printf(" Mount <device> using filesystem <fstype>\n");
485 printf(" and with the specified (optional) option list.\n");
487 printf(" eg. ufs:/dev/da0s1a\n");
488 printf(" zfs:tank\n");
489 printf(" cd9660:/dev/acd0 ro\n");
490 printf(" (which is equivalent to: ");
491 printf("mount -t cd9660 -o ro /dev/acd0 /)\n");
493 printf(" ? List valid disk boot devices\n");
494 printf(" . Yield 1 second (for background tasks)\n");
495 printf(" <empty line> Abort manual input\n");
499 printf("\nmountroot> ");
500 cngets(name, sizeof(name), GETS_ECHO);
503 if (name[0] == '?' && name[1] == '\0') {
504 printf("\nList of GEOM managed disk devices:\n ");
508 if (name[0] == '.' && name[1] == '\0') {
513 error = parse_mount(&mnt);
515 printf("Invalid file system specification.\n");
516 } while (error != 0);
522 parse_dir_md(char **conf)
526 struct md_ioctl *mdio;
532 error = parse_token(conf, &tok);
537 mdio = malloc(sizeof(*mdio) + len + 1, M_TEMP, M_WAITOK | M_ZERO);
538 path = (void *)(mdio + 1);
539 bcopy(tok, path, len);
542 /* Get file status. */
543 error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &sb, NULL);
547 /* Open /dev/mdctl so that we can attach/detach. */
548 error = kern_openat(td, AT_FDCWD, "/dev/" MDCTL_NAME, UIO_SYSSPACE,
553 fd = td->td_retval[0];
554 mdio->md_version = MDIOVERSION;
555 mdio->md_type = MD_VNODE;
557 if (root_mount_mddev != -1) {
558 mdio->md_unit = root_mount_mddev;
560 error = kern_ioctl(td, fd, MDIOCDETACH, (void *)mdio);
562 /* Ignore errors. We don't care. */
563 root_mount_mddev = -1;
566 mdio->md_file = (void *)(mdio + 1);
567 mdio->md_options = MD_AUTOUNIT | MD_READONLY;
568 mdio->md_mediasize = sb.st_size;
571 error = kern_ioctl(td, fd, MDIOCATTACH, (void *)mdio);
576 if (mdio->md_unit > 9) {
577 printf("rootmount: too many md units\n");
578 mdio->md_file = NULL;
579 mdio->md_options = 0;
580 mdio->md_mediasize = 0;
582 error = kern_ioctl(td, fd, MDIOCDETACH, (void *)mdio);
584 /* Ignore errors. We don't care. */
589 root_mount_mddev = mdio->md_unit;
590 printf(MD_NAME "%u attached to %s\n", root_mount_mddev, mdio->md_file);
592 error = kern_close(td, fd);
600 parse_dir_onfail(char **conf)
605 error = parse_token(conf, &action);
609 if (!strcmp(action, "continue"))
610 root_mount_onfail = A_CONTINUE;
611 else if (!strcmp(action, "panic"))
612 root_mount_onfail = A_PANIC;
613 else if (!strcmp(action, "reboot"))
614 root_mount_onfail = A_REBOOT;
615 else if (!strcmp(action, "retry"))
616 root_mount_onfail = A_RETRY;
618 printf("rootmount: %s: unknown action\n", action);
622 free(action, M_TEMP);
627 parse_dir_timeout(char **conf)
633 error = parse_token(conf, &tok);
637 secs = strtol(tok, &endtok, 0);
638 error = (secs < 0 || *endtok != '\0') ? EINVAL : 0;
640 root_mount_timeout = secs;
646 parse_directive(char **conf)
651 error = parse_token(conf, &dir);
655 if (strcmp(dir, ".ask") == 0)
656 error = parse_dir_ask(conf);
657 else if (strcmp(dir, ".md") == 0)
658 error = parse_dir_md(conf);
659 else if (strcmp(dir, ".onfail") == 0)
660 error = parse_dir_onfail(conf);
661 else if (strcmp(dir, ".timeout") == 0)
662 error = parse_dir_timeout(conf);
664 printf("mountroot: invalid directive `%s'\n", dir);
665 /* Ignore the rest of the line. */
666 (void)parse_skipto(conf, '\n');
674 parse_mount_dev_present(const char *dev)
679 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, dev, curthread);
683 NDFREE(&nd, NDF_ONLY_PNBUF);
684 return (error != 0) ? 0 : 1;
689 parse_mount(char **conf)
693 char *dev, *fs, *opts, *tok;
694 int delay, error, timeout;
696 error = parse_token(conf, &tok);
700 error = parse_skipto(&tok, ':');
705 parse_poke(&tok, '\0');
709 if (root_mount_mddev != -1) {
710 /* Handle substitution for the md unit number. */
711 tok = strstr(dev, "md#");
713 tok[2] = '0' + root_mount_mddev;
717 error = parse_token(conf, &tok);
718 opts = (error == 0) ? tok : NULL;
720 printf("Trying to mount root from %s:%s [%s]...\n", fs, dev,
721 (opts != NULL) ? opts : "");
723 errmsg = malloc(ERRMSGL, M_TEMP, M_WAITOK | M_ZERO);
725 if (vfs_byname(fs) == NULL) {
726 strlcpy(errmsg, "unknown file system", ERRMSGL);
731 if (strcmp(fs, "zfs") != 0 && strstr(fs, "nfs") == NULL &&
732 dev[0] != '\0' && !parse_mount_dev_present(dev)) {
733 printf("mountroot: waiting for device %s ...\n", dev);
735 timeout = root_mount_timeout * hz;
737 pause("rmdev", delay);
739 } while (timeout > 0 && !parse_mount_dev_present(dev));
747 ma = mount_arg(ma, "fstype", fs, -1);
748 ma = mount_arg(ma, "fspath", "/", -1);
749 ma = mount_arg(ma, "from", dev, -1);
750 ma = mount_arg(ma, "errmsg", errmsg, ERRMSGL);
751 ma = mount_arg(ma, "ro", NULL, 0);
752 ma = parse_mountroot_options(ma, opts);
753 error = kernel_mount(ma, MNT_ROOTFS);
757 printf("Mounting from %s:%s failed with error %d",
759 if (errmsg[0] != '\0')
760 printf(": %s", errmsg);
764 free(errmsg, M_TEMP);
767 /* kernel_mount can return -1 on error. */
768 return ((error < 0) ? EDOOFUS : error);
773 vfs_mountroot_parse(struct sbuf *sb, struct mount *mpdevfs)
779 root_mount_mddev = -1;
782 conf = sbuf_data(sb);
783 mp = TAILQ_NEXT(mpdevfs, mnt_list);
784 error = (mp == NULL) ? 0 : EDOOFUS;
785 root_mount_onfail = A_CONTINUE;
787 error = parse_skipto(&conf, CC_NONWHITESPACE);
788 if (error == PE_EOL) {
789 parse_advance(&conf);
794 switch (parse_peek(&conf)) {
796 error = parse_skipto(&conf, '\n');
799 error = parse_directive(&conf);
802 error = parse_mount(&conf);
804 printf("mountroot: invalid file system "
812 /* Ignore any trailing garbage on the line. */
813 if (parse_peek(&conf) != '\n') {
814 printf("mountroot: advancing to next directive...\n");
815 (void)parse_skipto(&conf, '\n');
817 mp = TAILQ_NEXT(mpdevfs, mnt_list);
823 * We failed to mount (a new) root.
825 switch (root_mount_onfail) {
829 panic("mountroot: unable to (re-)mount root.");
834 kern_reboot(RB_NOSYNC);
842 vfs_mountroot_conf0(struct sbuf *sb)
844 char *s, *tok, *mnt, *opt;
847 sbuf_printf(sb, ".onfail panic\n");
848 sbuf_printf(sb, ".timeout %d\n", root_mount_timeout);
849 if (boothowto & RB_ASKNAME)
850 sbuf_printf(sb, ".ask\n");
852 if (boothowto & RB_DFLTROOT)
853 sbuf_printf(sb, "%s\n", ROOTDEVNAME);
855 if (boothowto & RB_CDROM) {
856 sbuf_printf(sb, "cd9660:/dev/cd0 ro\n");
857 sbuf_printf(sb, ".timeout 0\n");
858 sbuf_printf(sb, "cd9660:/dev/acd0 ro\n");
859 sbuf_printf(sb, ".timeout %d\n", root_mount_timeout);
861 s = kern_getenv("vfs.root.mountfrom");
863 opt = kern_getenv("vfs.root.mountfrom.options");
865 error = parse_token(&tok, &mnt);
867 sbuf_printf(sb, "%s %s\n", mnt,
868 (opt != NULL) ? opt : "");
870 error = parse_token(&tok, &mnt);
876 if (rootdevnames[0] != NULL)
877 sbuf_printf(sb, "%s\n", rootdevnames[0]);
878 if (rootdevnames[1] != NULL)
879 sbuf_printf(sb, "%s\n", rootdevnames[1]);
881 if (!(boothowto & RB_DFLTROOT))
882 sbuf_printf(sb, "%s\n", ROOTDEVNAME);
884 if (!(boothowto & RB_ASKNAME))
885 sbuf_printf(sb, ".ask\n");
889 vfs_mountroot_readconf(struct thread *td, struct sbuf *sb)
891 static char buf[128];
895 int error, flags, len;
897 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/.mount.conf", td);
899 error = vn_open(&nd, &flags, 0, NULL);
903 NDFREE(&nd, NDF_ONLY_PNBUF);
905 len = sizeof(buf) - 1;
907 error = vn_rdwr(UIO_READ, nd.ni_vp, buf, len, ofs,
908 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred,
914 buf[len - resid] = 0;
915 sbuf_printf(sb, "%s", buf);
919 VOP_UNLOCK(nd.ni_vp, 0);
920 vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
925 vfs_mountroot_wait(void)
927 struct root_hold_token *h;
928 struct timeval lastfail;
936 mtx_lock(&root_holds_mtx);
937 if (LIST_EMPTY(&root_holds)) {
938 mtx_unlock(&root_holds_mtx);
941 if (ppsratecheck(&lastfail, &curfail, 1)) {
942 printf("Root mount waiting for:");
943 LIST_FOREACH(h, &root_holds, list)
944 printf(" %s", h->who);
947 msleep(&root_holds, &root_holds_mtx, PZERO | PDROP, "roothold",
963 vfs_mountroot_wait();
965 sb = sbuf_new_auto();
966 vfs_mountroot_conf0(sb);
969 error = vfs_mountroot_devfs(td, &mp);
971 error = vfs_mountroot_parse(sb, mp);
973 vfs_mountroot_shuffle(td, mp);
975 error = vfs_mountroot_readconf(td, sb);
983 * Iterate over all currently mounted file systems and use
984 * the time stamp found to check and/or initialize the RTC.
985 * Call inittodr() only once and pass it the largest of the
986 * timestamps we encounter.
989 mtx_lock(&mountlist_mtx);
990 mp = TAILQ_FIRST(&mountlist);
992 if (mp->mnt_time > timebase)
993 timebase = mp->mnt_time;
994 mp = TAILQ_NEXT(mp, mnt_list);
996 mtx_unlock(&mountlist_mtx);
999 /* Keep prison0's root in sync with the global rootvnode. */
1000 mtx_lock(&prison0.pr_mtx);
1001 prison0.pr_root = rootvnode;
1002 vref(prison0.pr_root);
1003 mtx_unlock(&prison0.pr_mtx);
1005 mtx_lock(&root_holds_mtx);
1006 atomic_store_rel_int(&root_mount_complete, 1);
1007 wakeup(&root_mount_complete);
1008 mtx_unlock(&root_holds_mtx);
1010 EVENTHANDLER_INVOKE(mountroot);
1013 static struct mntarg *
1014 parse_mountroot_options(struct mntarg *ma, const char *options)
1017 char *name, *name_arg;
1018 char *val, *val_arg;
1021 if (options == NULL || options[0] == '\0')
1024 p = opts = strdup(options, M_MOUNT);
1029 while((name = strsep(&p, ",")) != NULL) {
1030 if (name[0] == '\0')
1033 val = strchr(name, '=');
1038 if( strcmp(name, "rw") == 0 ||
1039 strcmp(name, "noro") == 0) {
1041 * The first time we mount the root file system,
1042 * we need to mount 'ro', so We need to ignore
1043 * 'rw' and 'noro' mount options.
1047 name_arg = strdup(name, M_MOUNT);
1050 val_arg = strdup(val, M_MOUNT);
1052 ma = mount_arg(ma, name_arg, val_arg,
1053 (val_arg != NULL ? -1 : 0));
1055 free(opts, M_MOUNT);