1*6b362760Sandvar /* $NetBSD: mount_chfs.c,v 1.5 2021/07/16 12:09:36 andvar Exp $ */
2ccfcc4b3Sahoka
3ccfcc4b3Sahoka /*-
4ccfcc4b3Sahoka * Copyright (c) 2010 Department of Software Engineering,
5ccfcc4b3Sahoka * University of Szeged, Hungary
6ccfcc4b3Sahoka * All rights reserved.
7ccfcc4b3Sahoka *
8ccfcc4b3Sahoka * This code is derived from software contributed to The NetBSD Foundation
9ccfcc4b3Sahoka * by the Department of Software Engineering, University of Szeged, Hungary
10ccfcc4b3Sahoka *
11ccfcc4b3Sahoka * Redistribution and use in source and binary forms, with or without
12ccfcc4b3Sahoka * modification, are permitted provided that the following conditions
13ccfcc4b3Sahoka * are met:
14ccfcc4b3Sahoka * 1. Redistributions of source code must retain the above copyright
15ccfcc4b3Sahoka * notice, this list of conditions and the following disclaimer.
16ccfcc4b3Sahoka * 2. Redistributions in binary form must reproduce the above copyright
17ccfcc4b3Sahoka * notice, this list of conditions and the following disclaimer in the
18ccfcc4b3Sahoka * documentation and/or other materials provided with the distribution.
19ccfcc4b3Sahoka *
20ccfcc4b3Sahoka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21ccfcc4b3Sahoka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22ccfcc4b3Sahoka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23ccfcc4b3Sahoka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24ccfcc4b3Sahoka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25ccfcc4b3Sahoka * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26ccfcc4b3Sahoka * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27ccfcc4b3Sahoka * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28ccfcc4b3Sahoka * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29ccfcc4b3Sahoka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30ccfcc4b3Sahoka * SUCH DAMAGE.
31ccfcc4b3Sahoka */
32ccfcc4b3Sahoka
33ccfcc4b3Sahoka #include <sys/cdefs.h>
34ccfcc4b3Sahoka #ifndef lint
35ccfcc4b3Sahoka #endif /* not lint */
36ccfcc4b3Sahoka
37ccfcc4b3Sahoka #include <sys/param.h>
38ccfcc4b3Sahoka #include <sys/mount.h>
39ccfcc4b3Sahoka #include <sys/stat.h>
40ccfcc4b3Sahoka #include <ufs/ufs/ufsmount.h>
41ccfcc4b3Sahoka
42ccfcc4b3Sahoka #include <ctype.h>
43ccfcc4b3Sahoka #include <err.h>
44ccfcc4b3Sahoka #include <errno.h>
45ccfcc4b3Sahoka #include <grp.h>
46ccfcc4b3Sahoka #include <mntopts.h>
47ccfcc4b3Sahoka #include <pwd.h>
48ccfcc4b3Sahoka #include <stdio.h>
49ccfcc4b3Sahoka #include <stdlib.h>
50ccfcc4b3Sahoka #include <string.h>
51ccfcc4b3Sahoka #include <unistd.h>
52ccfcc4b3Sahoka
53ccfcc4b3Sahoka #include "mountprog.h"
54ccfcc4b3Sahoka #include "mount_chfs.h"
55ccfcc4b3Sahoka
5697604924Sdholland static const struct mntopt mopts[] = {
5797604924Sdholland MOPT_STDOPTS,
5897604924Sdholland MOPT_GETARGS,
5997604924Sdholland MOPT_NULL,
6097604924Sdholland };
6197604924Sdholland
62ccfcc4b3Sahoka /* --------------------------------------------------------------------- */
63ccfcc4b3Sahoka
64ccfcc4b3Sahoka static void usage(void) __dead;
65ccfcc4b3Sahoka
66ccfcc4b3Sahoka /* --------------------------------------------------------------------- */
67ccfcc4b3Sahoka
68ccfcc4b3Sahoka void
mount_chfs_parseargs(int argc,char * argv[],struct ufs_args * args,int * mntflags,char * canon_dev,char * canon_dir)69ccfcc4b3Sahoka mount_chfs_parseargs(int argc, char *argv[], struct ufs_args *args,
70ccfcc4b3Sahoka int *mntflags, char *canon_dev, char *canon_dir)
71ccfcc4b3Sahoka {
72ccfcc4b3Sahoka int ch;
7397604924Sdholland mntoptparse_t mp;
74ccfcc4b3Sahoka struct stat sb;
75ccfcc4b3Sahoka
76ccfcc4b3Sahoka /* Set default values for mount point arguments. */
77ccfcc4b3Sahoka memset(args, 0, sizeof(*args));
78ccfcc4b3Sahoka *mntflags = 0;
79ccfcc4b3Sahoka
80ccfcc4b3Sahoka optind = optreset = 1;
81ccfcc4b3Sahoka
8297604924Sdholland while ((ch = getopt(argc, argv, "o:")) != -1) {
83ccfcc4b3Sahoka switch (ch) {
8497604924Sdholland case 'o':
8597604924Sdholland mp = getmntopts(optarg, mopts, mntflags, 0);
8697604924Sdholland if (mp == NULL)
8797604924Sdholland err(1, "getmntopts");
8897604924Sdholland freemntopts(mp);
8997604924Sdholland break;
90ccfcc4b3Sahoka case '?':
91ccfcc4b3Sahoka default:
92ccfcc4b3Sahoka usage();
93ccfcc4b3Sahoka }
94ccfcc4b3Sahoka }
95ccfcc4b3Sahoka argc -= optind;
96ccfcc4b3Sahoka argv += optind;
97ccfcc4b3Sahoka
98ccfcc4b3Sahoka if (argc != 2)
99ccfcc4b3Sahoka usage();
100ccfcc4b3Sahoka
101ccfcc4b3Sahoka pathadj(argv[0], canon_dev);
102ccfcc4b3Sahoka pathadj(argv[1], canon_dir);
103ccfcc4b3Sahoka
104ccfcc4b3Sahoka args->fspec = canon_dev;
105ccfcc4b3Sahoka
106ccfcc4b3Sahoka if (stat(canon_dir, &sb) == -1) {
107ccfcc4b3Sahoka err(EXIT_FAILURE, "cannot stat `%s'", canon_dir);
108ccfcc4b3Sahoka }
109ccfcc4b3Sahoka
110ccfcc4b3Sahoka }
111ccfcc4b3Sahoka
112ccfcc4b3Sahoka /* --------------------------------------------------------------------- */
113ccfcc4b3Sahoka
114ccfcc4b3Sahoka static void
usage(void)115ccfcc4b3Sahoka usage(void)
116ccfcc4b3Sahoka {
117ccfcc4b3Sahoka (void)fprintf(stderr,
118ccfcc4b3Sahoka "usage: %s special mountpath\n",
119ccfcc4b3Sahoka getprogname());
120ccfcc4b3Sahoka exit(1);
121ccfcc4b3Sahoka }
122ccfcc4b3Sahoka
123ccfcc4b3Sahoka /* --------------------------------------------------------------------- */
124ccfcc4b3Sahoka
125ccfcc4b3Sahoka int
mount_chfs(int argc,char * argv[])126ccfcc4b3Sahoka mount_chfs(int argc, char *argv[])
127ccfcc4b3Sahoka {
128ccfcc4b3Sahoka struct ufs_args args;
129ccfcc4b3Sahoka char canon_dev[MAXPATHLEN], fs_name[MAXPATHLEN];
130ccfcc4b3Sahoka int mntflags;
131ccfcc4b3Sahoka
132ccfcc4b3Sahoka mount_chfs_parseargs(argc, argv, &args, &mntflags,
133ccfcc4b3Sahoka canon_dev, fs_name);
134ccfcc4b3Sahoka
1353494bf46Sriastradh if (mount(MOUNT_CHFS, fs_name, mntflags, &args, sizeof args) == -1) {
136ccfcc4b3Sahoka err(EXIT_FAILURE, "chfs on %s", fs_name);
137ccfcc4b3Sahoka }
138ccfcc4b3Sahoka
139ccfcc4b3Sahoka return EXIT_SUCCESS;
140ccfcc4b3Sahoka }
141ccfcc4b3Sahoka
142ccfcc4b3Sahoka #ifndef MOUNT_NOMAIN
143ccfcc4b3Sahoka int
main(int argc,char * argv[])144ccfcc4b3Sahoka main(int argc, char *argv[])
145ccfcc4b3Sahoka {
146ccfcc4b3Sahoka setprogname(argv[0]);
147ccfcc4b3Sahoka return mount_chfs(argc, argv);
148ccfcc4b3Sahoka }
149ccfcc4b3Sahoka #endif
150