Home | History | Annotate | Line # | Download | only in mount_lfs
mount_lfs.c revision 1.1.1.1
      1 /*-
      2  * Copyright (c) 1993, 1994
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #ifndef lint
     35 static char copyright[] =
     36 "@(#) Copyright (c) 1993, 1994\n\
     37 	The Regents of the University of California.  All rights reserved.\n";
     38 #endif /* not lint */
     39 
     40 #ifndef lint
     41 static char sccsid[] = "@(#)mount_lfs.c	8.3 (Berkeley) 3/27/94";
     42 #endif /* not lint */
     43 
     44 #include <sys/param.h>
     45 #include <sys/mount.h>
     46 
     47 #include <err.h>
     48 #include <stdio.h>
     49 #include <stdlib.h>
     50 #include <string.h>
     51 #include <unistd.h>
     52 
     53 #include "mntopts.h"
     54 #include "pathnames.h"
     55 
     56 struct mntopt mopts[] = {
     57 	MOPT_STDOPTS,
     58 	MOPT_UPDATE,
     59 	{ NULL }
     60 };
     61 
     62 void	usage __P((void));
     63 void	invoke_cleaner __P((char *));
     64 
     65 int short_rds, cleaner_debug;
     66 
     67 int
     68 main(argc, argv)
     69 	int argc;
     70 	char *argv[];
     71 {
     72 	struct ufs_args args;
     73 	int ch, mntflags, noclean;
     74 	char *fs_name, *options;
     75 
     76 	options = NULL;
     77 	mntflags = noclean = 0;
     78 	while ((ch = getopt(argc, argv, "dno:s")) != EOF)
     79 		switch (ch) {
     80 		case 'd':
     81 			cleaner_debug = 1;
     82 			break;
     83 		case 'n':
     84 			noclean = 1;
     85 			break;
     86 		case 'o':
     87 			getmntopts(optarg, mopts, &mntflags);
     88 			break;
     89 		case 's':
     90 			short_rds = 1;
     91 			break;
     92 		case '?':
     93 		default:
     94 			usage();
     95 		}
     96 	argc -= optind;
     97 	argv += optind;
     98 
     99 	if (argc != 2)
    100 		usage();
    101 
    102         args.fspec = argv[0];	/* the name of the device file */
    103 	fs_name = argv[1];	/* the mount point */
    104 
    105 #define DEFAULT_ROOTUID	-2
    106 	args.export.ex_root = DEFAULT_ROOTUID;
    107 	if (mntflags & MNT_RDONLY)
    108 		args.export.ex_flags = MNT_EXRDONLY;
    109 	else
    110 		args.export.ex_flags = 0;
    111 
    112 	if (mount(MOUNT_LFS, fs_name, mntflags, &args))
    113 		err(1, NULL);
    114 
    115 	if (!noclean)
    116 		invoke_cleaner(fs_name);
    117 		/* NOTREACHED */
    118 
    119 	exit(0);
    120 }
    121 
    122 void
    123 invoke_cleaner(name)
    124 	char *name;
    125 {
    126 	char *args[6], **ap = args;
    127 
    128 	/* Build the argument list. */
    129 	*ap++ = _PATH_LFS_CLEANERD;
    130 	if (short_rds)
    131 		*ap++ = "-s";
    132 	if (cleaner_debug)
    133 		*ap++ = "-d";
    134 	*ap++ = name;
    135 	*ap = NULL;
    136 
    137 	execv(args[0], args);
    138 	err(1, "exec %s", _PATH_LFS_CLEANERD);
    139 }
    140 
    141 void
    142 usage()
    143 {
    144 	(void)fprintf(stderr,
    145 		"usage: mount_lfs [-dns] [-o options] special node\n");
    146 	exit(1);
    147 }
    148