1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1993, 1994\n\
11 The Regents of the University of California. All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)mount_lfs.c 8.4 (Berkeley) 04/26/95";
16 #endif /* not lint */
17
18 #include <sys/param.h>
19 #include <sys/mount.h>
20 #include <ufs/ufs/ufsmount.h>
21
22 #include <err.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27
28 #include "mntopts.h"
29 #include "pathnames.h"
30
31 struct mntopt mopts[] = {
32 MOPT_STDOPTS,
33 MOPT_UPDATE,
34 { NULL }
35 };
36
37 void usage __P((void));
38 void invoke_cleaner __P((char *));
39
40 int short_rds, cleaner_debug;
41
42 int
main(argc,argv)43 main(argc, argv)
44 int argc;
45 char *argv[];
46 {
47 struct ufs_args args;
48 int ch, mntflags, noclean;
49 char *fs_name, *options;
50
51 options = NULL;
52 mntflags = noclean = 0;
53 while ((ch = getopt(argc, argv, "dno:s")) != EOF)
54 switch (ch) {
55 case 'd':
56 cleaner_debug = 1;
57 break;
58 case 'n':
59 noclean = 1;
60 break;
61 case 'o':
62 getmntopts(optarg, mopts, &mntflags, 0);
63 break;
64 case 's':
65 short_rds = 1;
66 break;
67 case '?':
68 default:
69 usage();
70 }
71 argc -= optind;
72 argv += optind;
73
74 if (argc != 2)
75 usage();
76
77 args.fspec = argv[0]; /* the name of the device file */
78 fs_name = argv[1]; /* the mount point */
79
80 #define DEFAULT_ROOTUID -2
81 args.export.ex_root = DEFAULT_ROOTUID;
82 if (mntflags & MNT_RDONLY)
83 args.export.ex_flags = MNT_EXRDONLY;
84 else
85 args.export.ex_flags = 0;
86
87 if (mount("lfs", fs_name, mntflags, &args))
88 err(1, NULL);
89
90 if (!noclean)
91 invoke_cleaner(fs_name);
92 /* NOTREACHED */
93
94 exit(0);
95 }
96
97 void
invoke_cleaner(name)98 invoke_cleaner(name)
99 char *name;
100 {
101 char *args[6], **ap = args;
102
103 /* Build the argument list. */
104 *ap++ = _PATH_LFS_CLEANERD;
105 if (short_rds)
106 *ap++ = "-s";
107 if (cleaner_debug)
108 *ap++ = "-d";
109 *ap++ = name;
110 *ap = NULL;
111
112 execv(args[0], args);
113 err(1, "exec %s", _PATH_LFS_CLEANERD);
114 }
115
116 void
usage()117 usage()
118 {
119 (void)fprintf(stderr,
120 "usage: mount_lfs [-dns] [-o options] special node\n");
121 exit(1);
122 }
123