2 * Copyright (c) 2013 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Antonio Huete Jimenez <tuxillo@quantumachine.net>
6 * by Matthew Dillon <dillon@dragonflybsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/types.h>
37 #include <sys/diskslice.h>
38 #include <sys/diskmbr.h>
41 #include <sys/syslimits.h>
42 #include <sys/mount.h>
43 #include <sys/sysctl.h>
59 #define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 }
60 #define PLATFORM_LEN 16
62 static struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_UPDATE, MOPT_NULL };
64 static void usage(void);
67 main(int ac, char **av)
74 char *mountpt, *hostdir;
76 char platform[PLATFORM_LEN] = {0};
80 while ((ch = getopt(ac, av, "o:u")) != -1) {
83 init_flags |= MNT_UPDATE;
87 getmntopts(optarg, mopts, &mount_flags, NULL);
96 mount_flags |= init_flags;
99 * Check we're in a vkernel or abort.
101 vsize = PLATFORM_LEN;
102 error = sysctlbyname("hw.platform", &platform, &vsize, NULL,0);
104 errx(1, "Failed to get hw.platform sysctl");
106 if (strnstr(platform, "vkernel", PLATFORM_LEN) == NULL)
107 errx(1, "dirfs is only available for vkernels.");
110 * Only the mount point need be specified in update mode.
112 if (init_flags & MNT_UPDATE) {
118 if (mount(vfc.vfc_name, mountpt, mount_flags, NULL))
119 err(1, "mountpoint %s", mountpt);
132 * Load the dirfs module if necessary (this bit stolen from
135 error = getvfsbyname("dirfs", &vfc);
136 if (error && vfsisloadable("dirfs")) {
137 if (vfsload("dirfs") != 0)
138 err(1, "vfsload(dirfs)");
140 error = getvfsbyname("dirfs", &vfc);
143 errx(1, "dirfs filesystem is not available");
145 error = mount(vfc.vfc_name, mountpt, mount_flags, hostdir);
147 err(1, "failed to mount %s on %s", hostdir, mountpt);
156 fprintf(stderr, "usage: mount_dirfs [-u] [-o options] "