mount_efs.c revision 1.5 1 1.5 joerg /* $NetBSD: mount_efs.c,v 1.5 2011/08/29 14:35:00 joerg Exp $ */
2 1.1 rumble
3 1.1 rumble /*
4 1.1 rumble * Copyright (c) 2006 Stephen M. Rumble <rumble (at) ephemeral.org>
5 1.1 rumble *
6 1.1 rumble * Permission to use, copy, modify, and distribute this software for any
7 1.1 rumble * purpose with or without fee is hereby granted, provided that the above
8 1.1 rumble * copyright notice and this permission notice appear in all copies.
9 1.1 rumble *
10 1.1 rumble * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 1.1 rumble * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 1.1 rumble * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 1.1 rumble * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 1.1 rumble * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 1.1 rumble * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 1.1 rumble * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 1.1 rumble */
18 1.1 rumble
19 1.1 rumble #include <sys/param.h>
20 1.1 rumble #include <sys/mount.h>
21 1.1 rumble #include <fs/efs/efs.h>
22 1.1 rumble #include <fs/efs/efs_sb.h>
23 1.1 rumble #include <fs/efs/efs_mount.h>
24 1.1 rumble
25 1.1 rumble #include <err.h>
26 1.1 rumble #include <stdio.h>
27 1.1 rumble #include <stdlib.h>
28 1.1 rumble
29 1.1 rumble #include <string.h>
30 1.1 rumble #include <unistd.h>
31 1.1 rumble
32 1.1 rumble #include <mntopts.h>
33 1.1 rumble
34 1.4 pooka #include "mountprog.h"
35 1.4 pooka #include "mount_efs.h"
36 1.4 pooka
37 1.1 rumble static const struct mntopt mopts[] = {
38 1.1 rumble MOPT_STDOPTS,
39 1.1 rumble MOPT_GETARGS,
40 1.1 rumble MOPT_FORCE,
41 1.1 rumble MOPT_NULL
42 1.1 rumble };
43 1.1 rumble
44 1.5 joerg __dead static void usage(void);
45 1.1 rumble
46 1.1 rumble static void
47 1.5 joerg usage(void)
48 1.1 rumble {
49 1.1 rumble
50 1.1 rumble fprintf(stderr, "usage: %s [-o options] special node\n", getprogname());
51 1.1 rumble exit(1);
52 1.1 rumble }
53 1.1 rumble
54 1.4 pooka void
55 1.4 pooka mount_efs_parseargs(int argc, char **argv,
56 1.4 pooka struct efs_args *args, int *mntflags,
57 1.4 pooka char *canon_dev, char *canon_dir)
58 1.1 rumble {
59 1.4 pooka int ch;
60 1.1 rumble extern int optind;
61 1.1 rumble extern char *optarg;
62 1.1 rumble mntoptparse_t mp;
63 1.1 rumble
64 1.4 pooka memset(args, 0, sizeof(*args));
65 1.4 pooka *mntflags = 0;
66 1.1 rumble
67 1.1 rumble while ((ch = getopt(argc, argv, "o:")) != -1) {
68 1.1 rumble switch (ch) {
69 1.1 rumble case 'o':
70 1.4 pooka mp = getmntopts(optarg, mopts, mntflags, NULL);
71 1.1 rumble if (mp == NULL)
72 1.1 rumble err(1, "getmntopts");
73 1.1 rumble freemntopts(mp);
74 1.1 rumble break;
75 1.1 rumble
76 1.1 rumble default:
77 1.1 rumble usage();
78 1.1 rumble }
79 1.1 rumble }
80 1.1 rumble argc -= optind;
81 1.1 rumble argv += optind;
82 1.1 rumble
83 1.1 rumble if (argc != 2)
84 1.1 rumble usage();
85 1.1 rumble
86 1.4 pooka pathadj(argv[0], canon_dev);
87 1.4 pooka pathadj(argv[1], canon_dir);
88 1.1 rumble
89 1.4 pooka args->fspec = canon_dev;
90 1.4 pooka args->version = EFS_MNT_VERSION;
91 1.4 pooka }
92 1.4 pooka
93 1.4 pooka int
94 1.4 pooka mount_efs(int argc, char **argv)
95 1.4 pooka {
96 1.4 pooka char special[MAXPATHLEN], node[MAXPATHLEN];
97 1.4 pooka struct efs_args args;
98 1.4 pooka int mntflags;
99 1.4 pooka
100 1.4 pooka mount_efs_parseargs(argc, argv, &args, &mntflags, special, node);
101 1.1 rumble
102 1.3 pooka if (mount(MOUNT_EFS, node, mntflags, &args, sizeof args) == -1)
103 1.1 rumble err(EXIT_FAILURE, "%s on %s", special, node);
104 1.1 rumble
105 1.1 rumble return (0);
106 1.1 rumble }
107 1.1 rumble
108 1.1 rumble #ifndef MOUNT_NOMAIN
109 1.1 rumble int
110 1.1 rumble main(int argc, char **argv)
111 1.1 rumble {
112 1.1 rumble
113 1.4 pooka setprogname(argv[0]);
114 1.1 rumble return (mount_efs(argc, argv));
115 1.1 rumble }
116 1.1 rumble #endif
117