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