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/param.h>
37 #include <sys/diskslice.h>
38 #include <sys/diskmbr.h>
40 #include <sys/mount.h>
41 #include <sys/sysctl.h>
57 #define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 }
58 #define PLATFORM_LEN 16
60 static struct mntopt mopts
[] = { MOPT_STDOPTS
, MOPT_UPDATE
, MOPT_NULL
};
62 static void usage(void);
65 main(int ac
, char **av
)
72 char *mountpt
, *hostdir
;
74 char platform
[PLATFORM_LEN
] = {0};
78 while ((ch
= getopt(ac
, av
, "o:u")) != -1) {
81 init_flags
|= MNT_UPDATE
;
85 getmntopts(optarg
, mopts
, &mount_flags
, NULL
);
94 mount_flags
|= init_flags
;
97 * Check we're in a vkernel or abort.
100 error
= sysctlbyname("hw.platform", &platform
, &vsize
, NULL
,0);
102 errx(1, "Failed to get hw.platform sysctl");
104 if (strnstr(platform
, "vkernel", PLATFORM_LEN
) == NULL
)
105 errx(1, "dirfs is only available for vkernels.");
108 * Only the mount point need be specified in update mode.
110 if (init_flags
& MNT_UPDATE
) {
116 if (mount(vfc
.vfc_name
, mountpt
, mount_flags
, NULL
))
117 err(1, "mountpoint %s", mountpt
);
130 * Load the dirfs module if necessary (this bit stolen from
133 error
= getvfsbyname("dirfs", &vfc
);
134 if (error
&& vfsisloadable("dirfs")) {
135 if (vfsload("dirfs") != 0)
136 err(1, "vfsload(dirfs)");
138 error
= getvfsbyname("dirfs", &vfc
);
141 errx(1, "dirfs filesystem is not available");
143 error
= mount(vfc
.vfc_name
, mountpt
, mount_flags
, hostdir
);
145 err(1, "failed to mount %s on %s", hostdir
, mountpt
);
154 fprintf(stderr
, "usage: mount_dirfs [-u] [-o options] "