Sync usage with man page.
[netbsd-mini2440.git] / sbin / mount_hfs / mount_hfs.c
blob6bb414188f1a24b5257ace7ceeeeeb7aee0f0e22
1 /* $NetBSD: mount_hfs.c,v 1.7 2008/07/20 01:20:22 lukem Exp $ */
3 /*-
4 * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Yevgeny Binder and Dieter Baron.
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.
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 */
33 * Copyright (c) 1993, 1994
34 * The Regents of the University of California. All rights reserved.
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.
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.
61 #include <sys/cdefs.h>
62 #ifndef lint
63 __COPYRIGHT("@(#) Copyright (c) 2005 Yevgeny Binder. All rights reserved.");
64 #endif /* not lint */
66 #ifndef lint
67 __RCSID("$NetBSD: mount_hfs.c,v 1.7 2008/07/20 01:20:22 lukem Exp $");
68 #endif /* not lint */
70 #include <sys/param.h>
71 #include <sys/mount.h>
73 #include <fs/hfs/hfs.h>
75 #include <err.h>
76 #include <unistd.h>
77 #include <stdio.h>
78 #include <stdlib.h>
79 #include <string.h>
81 #include <mntopts.h>
83 #include "mountprog.h"
84 #include "mount_hfs.h"
86 static const struct mntopt mopts[] = {
87 MOPT_STDOPTS,
88 MOPT_NULL,
91 int main(int, char *[]);
92 static void usage(void);
94 #ifndef MOUNT_NOMAIN
95 int
96 main(int argc, char **argv)
99 setprogname(argv[0]);
100 return mount_hfs(argc, argv);
102 #endif
104 void
105 mount_hfs_parseargs(int argc, char *argv[],
106 struct hfs_args *args, int *mntflags,
107 char *canon_dev, char *canon_dir)
109 mntoptparse_t optparse;
110 int ch;
112 memset(args, 0, sizeof(*args));
113 *mntflags = 0;
114 optind = optreset = 1; /* Reset for parse of new argv. */
115 while ((ch = getopt(argc, argv, "o:")) != -1)
116 switch (ch) {
117 case 'o':
118 optparse = getmntopts(optarg, mopts, mntflags, 0);
119 if (optparse == NULL)
120 err(1, "getmntopts");
121 freemntopts(optparse);
122 break;
123 case '?':
124 default:
125 usage();
127 argc -= optind;
128 argv += optind;
130 if (argc != 2)
131 usage();
133 pathadj(argv[0], canon_dev);
134 pathadj(argv[1], canon_dir);
135 args->fspec = canon_dev; /* The name of the device file. */
139 mount_hfs(int argc, char *argv[])
141 struct hfs_args args;
142 char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
143 int mntflags;
145 mount_hfs_parseargs(argc, argv, &args, &mntflags, canon_dev, canon_dir);
147 if (mount(MOUNT_HFS, canon_dir, mntflags, &args, sizeof args) == -1)
148 err(1, "%s on %s", args.fspec, canon_dir);
150 exit(0);
153 static void
154 usage(void)
156 fprintf(stderr, "usage: %s [-o options] special node\n", getprogname());
157 exit(1);