Home | History | Annotate | Line # | Download | only in mount_lfs
mount_lfs.c revision 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[] = "from: @(#)mount_lfs.c	8.3 (Berkeley) 3/27/94";*/
     42 static char *rcsid = "$Id: mount_lfs.c,v 1.1 1994/06/08 19:15:57 mycroft Exp $";
     43 #endif /* not lint */
     44 
     45 #include <sys/param.h>
     46 #include <sys/mount.h>
     47 
     48 #include <err.h>
     49 #include <stdio.h>
     50 #include <stdlib.h>
     51 #include <string.h>
     52 #include <unistd.h>
     53 
     54 #include "mntopts.h"
     55 #include "pathnames.h"
     56 
     57 struct mntopt mopts[] = {
     58 	MOPT_STDOPTS,
     59 	MOPT_UPDATE,
     60 	{ NULL }
     61 };
     62 
     63 void	usage __P((void));
     64 void	invoke_cleaner __P((char *));
     65 
     66 int short_rds, cleaner_debug;
     67 
     68 int
     69 main(argc, argv)
     70 	int argc;
     71 	char *argv[];
     72 {
     73 	struct ufs_args args;
     74 	int ch, mntflags, noclean;
     75 	char *fs_name, *options;
     76 
     77 	options = NULL;
     78 	mntflags = noclean = 0;
     79 	while ((ch = getopt(argc, argv, "dno:s")) != EOF)
     80 		switch (ch) {
     81 		case 'd':
     82 			cleaner_debug = 1;
     83 			break;
     84 		case 'n':
     85 			noclean = 1;
     86 			break;
     87 		case 'o':
     88 			getmntopts(optarg, mopts, &mntflags);
     89 			break;
     90 		case 's':
     91 			short_rds = 1;
     92 			break;
     93 		case '?':
     94 		default:
     95 			usage();
     96 		}
     97 	argc -= optind;
     98 	argv += optind;
     99 
    100 	if (argc != 2)
    101 		usage();
    102 
    103         args.fspec = argv[0];	/* the name of the device file */
    104 	fs_name = argv[1];	/* the mount point */
    105 
    106 #define DEFAULT_ROOTUID	-2
    107 	args.export.ex_root = DEFAULT_ROOTUID;
    108 	if (mntflags & MNT_RDONLY)
    109 		args.export.ex_flags = MNT_EXRDONLY;
    110 	else
    111 		args.export.ex_flags = 0;
    112 
    113 	if (mount(MOUNT_LFS, fs_name, mntflags, &args))
    114 		err(1, NULL);
    115 
    116 	if (!noclean)
    117 		invoke_cleaner(fs_name);
    118 		/* NOTREACHED */
    119 
    120 	exit(0);
    121 }
    122 
    123 void
    124 invoke_cleaner(name)
    125 	char *name;
    126 {
    127 	char *args[6], **ap = args;
    128 
    129 	/* Build the argument list. */
    130 	*ap++ = _PATH_LFS_CLEANERD;
    131 	if (short_rds)
    132 		*ap++ = "-s";
    133 	if (cleaner_debug)
    134 		*ap++ = "-d";
    135 	*ap++ = name;
    136 	*ap = NULL;
    137 
    138 	execv(args[0], args);
    139 	err(1, "exec %s", _PATH_LFS_CLEANERD);
    140 }
    141 
    142 void
    143 usage()
    144 {
    145 	(void)fprintf(stderr,
    146 		"usage: mount_lfs [-dns] [-o options] special node\n");
    147 	exit(1);
    148 }
    149