mount_hfs.c revision 1.5.6.1 1 1.5.6.1 mjf /* $NetBSD: mount_hfs.c,v 1.5.6.1 2007/12/27 00:47:00 mjf Exp $ */
2 1.1 dillo
3 1.1 dillo /*-
4 1.1 dillo * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
5 1.1 dillo * All rights reserved.
6 1.1 dillo *
7 1.1 dillo * This code is derived from software contributed to The NetBSD Foundation
8 1.1 dillo * by Yevgeny Binder and Dieter Baron.
9 1.1 dillo *
10 1.1 dillo * Redistribution and use in source and binary forms, with or without
11 1.1 dillo * modification, are permitted provided that the following conditions
12 1.1 dillo * are met:
13 1.1 dillo * 1. Redistributions of source code must retain the above copyright
14 1.1 dillo * notice, this list of conditions and the following disclaimer.
15 1.1 dillo * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 dillo * notice, this list of conditions and the following disclaimer in the
17 1.1 dillo * documentation and/or other materials provided with the distribution.
18 1.1 dillo *
19 1.1 dillo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 dillo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 dillo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 dillo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 dillo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 dillo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 dillo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 dillo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 dillo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 dillo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 dillo * POSSIBILITY OF SUCH DAMAGE.
30 1.1 dillo */
31 1.1 dillo
32 1.1 dillo /*
33 1.1 dillo * Copyright (c) 1993, 1994
34 1.1 dillo * The Regents of the University of California. All rights reserved.
35 1.1 dillo *
36 1.1 dillo * Redistribution and use in source and binary forms, with or without
37 1.1 dillo * modification, are permitted provided that the following conditions
38 1.1 dillo * are met:
39 1.1 dillo * 1. Redistributions of source code must retain the above copyright
40 1.1 dillo * notice, this list of conditions and the following disclaimer.
41 1.1 dillo * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 dillo * notice, this list of conditions and the following disclaimer in the
43 1.1 dillo * documentation and/or other materials provided with the distribution.
44 1.1 dillo * 3. Neither the name of the University nor the names of its contributors
45 1.1 dillo * may be used to endorse or promote products derived from this software
46 1.1 dillo * without specific prior written permission.
47 1.1 dillo *
48 1.1 dillo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 1.1 dillo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 1.1 dillo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 1.1 dillo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 1.1 dillo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 1.1 dillo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 1.1 dillo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 1.1 dillo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 1.1 dillo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 1.1 dillo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 1.1 dillo * SUCH DAMAGE.
59 1.1 dillo */
60 1.1 dillo
61 1.1 dillo #include <sys/cdefs.h>
62 1.1 dillo #ifndef lint
63 1.1 dillo __COPYRIGHT("@(#) Copyright (c) 2005 Yevgeny Binder\n\
64 1.1 dillo All rights reserved.\n");
65 1.1 dillo #endif /* not lint */
66 1.1 dillo
67 1.1 dillo #ifndef lint
68 1.5.6.1 mjf __RCSID("$NetBSD: mount_hfs.c,v 1.5.6.1 2007/12/27 00:47:00 mjf Exp $");
69 1.1 dillo #endif /* not lint */
70 1.1 dillo
71 1.1 dillo #include <sys/param.h>
72 1.1 dillo #include <sys/mount.h>
73 1.1 dillo
74 1.1 dillo #include <err.h>
75 1.1 dillo #include <unistd.h>
76 1.1 dillo #include <stdio.h>
77 1.1 dillo #include <stdlib.h>
78 1.1 dillo #include <string.h>
79 1.1 dillo
80 1.1 dillo #include <mntopts.h>
81 1.1 dillo
82 1.2 dillo #include <fs/hfs/hfs.h>
83 1.1 dillo
84 1.1 dillo static const struct mntopt mopts[] = {
85 1.1 dillo MOPT_STDOPTS,
86 1.1 dillo MOPT_GETARGS,
87 1.1 dillo MOPT_NULL,
88 1.1 dillo };
89 1.1 dillo
90 1.5.6.1 mjf int main(int, char *[]);
91 1.5.6.1 mjf int mount_hfs(int argc, char **argv);
92 1.5.6.1 mjf static void usage(void);
93 1.1 dillo
94 1.1 dillo #ifndef MOUNT_NOMAIN
95 1.1 dillo int
96 1.5.6.1 mjf main(int argc, char **argv)
97 1.1 dillo {
98 1.2 dillo return mount_hfs(argc, argv);
99 1.1 dillo }
100 1.1 dillo #endif
101 1.1 dillo
102 1.1 dillo int
103 1.5.6.1 mjf mount_hfs(int argc, char *argv[])
104 1.1 dillo {
105 1.2 dillo struct hfs_args args;
106 1.1 dillo mntoptparse_t optparse;
107 1.1 dillo int ch, mntflags;
108 1.1 dillo char *fs_name;
109 1.1 dillo
110 1.1 dillo args.fspec = NULL;
111 1.1 dillo
112 1.1 dillo mntflags = 0;
113 1.1 dillo optind = optreset = 1; /* Reset for parse of new argv. */
114 1.1 dillo while ((ch = getopt(argc, argv, "o:")) != -1)
115 1.1 dillo switch (ch) {
116 1.1 dillo case 'o':
117 1.1 dillo optparse = getmntopts(optarg, mopts, &mntflags, 0);
118 1.3 dillo if (optparse == NULL)
119 1.3 dillo err(1, "getmntopts");
120 1.1 dillo freemntopts(optparse);
121 1.1 dillo break;
122 1.1 dillo case '?':
123 1.1 dillo default:
124 1.1 dillo usage();
125 1.1 dillo }
126 1.1 dillo argc -= optind;
127 1.1 dillo argv += optind;
128 1.1 dillo
129 1.1 dillo if (argc != 2)
130 1.1 dillo usage();
131 1.1 dillo
132 1.1 dillo args.fspec = argv[0]; /* The name of the device file. */
133 1.1 dillo fs_name = argv[1]; /* The mount point. */
134 1.1 dillo
135 1.1 dillo
136 1.5 pooka if (mount(MOUNT_HFS, fs_name, mntflags, &args, sizeof args) == -1)
137 1.1 dillo err(1, "%s on %s", args.fspec, fs_name);
138 1.1 dillo
139 1.1 dillo exit(0);
140 1.1 dillo }
141 1.1 dillo
142 1.1 dillo static void
143 1.5.6.1 mjf usage(void)
144 1.1 dillo {
145 1.2 dillo (void)fprintf(stderr, "usage: mount_hfs [-o options] special node\n");
146 1.1 dillo exit(1);
147 1.1 dillo }
148