162797Sbostic /*- 2*62805Sbostic * Copyright (c) 1993 3*62805Sbostic * The Regents of the University of California. All rights reserved. 462797Sbostic * 562797Sbostic * %sccs.include.redist.c% 662797Sbostic */ 762797Sbostic 862797Sbostic #ifndef lint 9*62805Sbostic static char copyright[] = 10*62805Sbostic "@(#) Copyright (c) 1993\n\ 11*62805Sbostic The Regents of the University of California. All rights reserved.\n"; 1262797Sbostic #endif /* not lint */ 1362797Sbostic 1462797Sbostic #ifndef lint 15*62805Sbostic static char sccsid[] = "@(#)mount_lfs.c 8.1 (Berkeley) 06/08/93"; 1662797Sbostic #endif /* not lint */ 1762797Sbostic 1862797Sbostic #include <sys/param.h> 1962797Sbostic #include <sys/mount.h> 2062797Sbostic 2162797Sbostic #include <err.h> 2262797Sbostic #include <errno.h> 2362797Sbostic #include <stdio.h> 2462797Sbostic #include <stdlib.h> 2562797Sbostic #include <string.h> 2662797Sbostic #include <unistd.h> 2762797Sbostic 2862797Sbostic #include "pathnames.h" 2962797Sbostic 3062797Sbostic #define DEFAULT_ROOTUID -2 /* copied from mount's UFS code */ 3162797Sbostic 3262797Sbostic void usage __P((void)); 3362797Sbostic void invoke_cleaner __P((char *)); 3462797Sbostic 3562797Sbostic int short_rds, cleaner_debug; 3662797Sbostic 3762797Sbostic int 3862797Sbostic main(argc, argv) 3962797Sbostic int argc; 4062797Sbostic char *argv[]; 4162797Sbostic { 4262797Sbostic struct ufs_args args; 4362797Sbostic int ch, mntflags; 4462797Sbostic int noclean; 4562797Sbostic char *fs_name; 4662797Sbostic 4762797Sbostic mntflags = noclean = 0; 4862797Sbostic while ((ch = getopt(argc, argv, "F:nsd")) != EOF) 4962797Sbostic switch(ch) { 5062797Sbostic case 'F': 5162797Sbostic mntflags = atoi(optarg); 5262797Sbostic break; 5362797Sbostic case 'n': 5462797Sbostic noclean = 1; 5562797Sbostic break; 5662797Sbostic case 's': 5762797Sbostic short_rds = 1; 5862797Sbostic break; 5962797Sbostic case 'd': 6062797Sbostic cleaner_debug = 1; 6162797Sbostic break; 6262797Sbostic case '?': 6362797Sbostic default: 6462797Sbostic usage(); 6562797Sbostic } 6662797Sbostic argc -= optind; 6762797Sbostic argv += optind; 6862797Sbostic 6962797Sbostic if (argc != 2) 7062797Sbostic usage(); 7162797Sbostic 7262797Sbostic args.fspec = argv[0]; /* the name of the device file */ 7362797Sbostic fs_name = argv[1]; /* the mount point */ 7462797Sbostic 7562797Sbostic /* copied from mount's UFS code */ 7662797Sbostic args.exroot = DEFAULT_ROOTUID; 7762797Sbostic if (mntflags & MNT_RDONLY) 7862797Sbostic args.exflags = MNT_EXRDONLY; 7962797Sbostic else 8062797Sbostic args.exflags = 0; 8162797Sbostic 8262797Sbostic if (mount(MOUNT_LFS, fs_name, mntflags, &args)) { 8362797Sbostic (void)fprintf(stderr, "mount_lfs: %s\n", strerror(errno)); 8462797Sbostic exit(1); 8562797Sbostic } 8662797Sbostic 8762797Sbostic if (!noclean) { 8862797Sbostic /* 8962797Sbostic * invoke the lfs_cleanerd for this filesystem as its arg! 9062797Sbostic */ 9162797Sbostic invoke_cleaner(fs_name); 9262797Sbostic /* never returns */ 9362797Sbostic } 9462797Sbostic 9562797Sbostic exit(0); 9662797Sbostic } 9762797Sbostic 9862797Sbostic void 9962797Sbostic usage() 10062797Sbostic { 10162797Sbostic (void)fprintf(stderr, 10262797Sbostic "usage: mount_lfs [ -nsd ] [ -F fsoptions ] device mount_point\n"); 10362797Sbostic exit(1); 10462797Sbostic } 10562797Sbostic 10662797Sbostic void 10762797Sbostic invoke_cleaner(name) 10862797Sbostic char *name; 10962797Sbostic { 11062797Sbostic char *args[6], **ap = args; 11162797Sbostic 11262797Sbostic /* build the argument list */ 11362797Sbostic *ap++ = _PATH_LFS_CLEANERD; 11462797Sbostic if (short_rds) 11562797Sbostic *ap++ = "-s"; 11662797Sbostic if (cleaner_debug) 11762797Sbostic *ap++ = "-d"; 11862797Sbostic *ap++ = name; 11962797Sbostic *ap = NULL; 12062797Sbostic 12162797Sbostic execv(args[0], args); 12262797Sbostic err(1, "exec of %x failed", _PATH_LFS_CLEANERD); 12362797Sbostic } 124