mount_efs.c revision 1.6 1 1.6 rillig /* $NetBSD: mount_efs.c,v 1.6 2024/11/03 10:43:27 rillig 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 mntoptparse_t mp;
61 1.1 rumble
62 1.4 pooka memset(args, 0, sizeof(*args));
63 1.4 pooka *mntflags = 0;
64 1.1 rumble
65 1.1 rumble while ((ch = getopt(argc, argv, "o:")) != -1) {
66 1.1 rumble switch (ch) {
67 1.1 rumble case 'o':
68 1.4 pooka mp = getmntopts(optarg, mopts, mntflags, NULL);
69 1.1 rumble if (mp == NULL)
70 1.1 rumble err(1, "getmntopts");
71 1.1 rumble freemntopts(mp);
72 1.1 rumble break;
73 1.1 rumble
74 1.1 rumble default:
75 1.1 rumble usage();
76 1.1 rumble }
77 1.1 rumble }
78 1.1 rumble argc -= optind;
79 1.1 rumble argv += optind;
80 1.1 rumble
81 1.1 rumble if (argc != 2)
82 1.1 rumble usage();
83 1.1 rumble
84 1.4 pooka pathadj(argv[0], canon_dev);
85 1.4 pooka pathadj(argv[1], canon_dir);
86 1.1 rumble
87 1.4 pooka args->fspec = canon_dev;
88 1.4 pooka args->version = EFS_MNT_VERSION;
89 1.4 pooka }
90 1.4 pooka
91 1.4 pooka int
92 1.4 pooka mount_efs(int argc, char **argv)
93 1.4 pooka {
94 1.4 pooka char special[MAXPATHLEN], node[MAXPATHLEN];
95 1.4 pooka struct efs_args args;
96 1.4 pooka int mntflags;
97 1.4 pooka
98 1.4 pooka mount_efs_parseargs(argc, argv, &args, &mntflags, special, node);
99 1.1 rumble
100 1.3 pooka if (mount(MOUNT_EFS, node, mntflags, &args, sizeof args) == -1)
101 1.1 rumble err(EXIT_FAILURE, "%s on %s", special, node);
102 1.1 rumble
103 1.1 rumble return (0);
104 1.1 rumble }
105 1.1 rumble
106 1.1 rumble #ifndef MOUNT_NOMAIN
107 1.1 rumble int
108 1.1 rumble main(int argc, char **argv)
109 1.1 rumble {
110 1.1 rumble
111 1.4 pooka setprogname(argv[0]);
112 1.1 rumble return (mount_efs(argc, argv));
113 1.1 rumble }
114 1.1 rumble #endif
115