Home | History | Annotate | Line # | Download | only in mount_sysvbfs
mount_sysvbfs.c revision 1.5.16.1
      1  1.5.16.1  wrstuden /*	$NetBSD: mount_sysvbfs.c,v 1.5.16.1 2008/09/18 04:28:28 wrstuden Exp $	*/
      2       1.1   tsutsui 
      3       1.1   tsutsui /*-
      4       1.1   tsutsui  * Copyright (c) 1993, 1994
      5       1.1   tsutsui  *	The Regents of the University of California.  All rights reserved.
      6       1.1   tsutsui  *
      7       1.1   tsutsui  * Redistribution and use in source and binary forms, with or without
      8       1.1   tsutsui  * modification, are permitted provided that the following conditions
      9       1.1   tsutsui  * are met:
     10       1.1   tsutsui  * 1. Redistributions of source code must retain the above copyright
     11       1.1   tsutsui  *    notice, this list of conditions and the following disclaimer.
     12       1.1   tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   tsutsui  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   tsutsui  *    documentation and/or other materials provided with the distribution.
     15       1.1   tsutsui  * 3. Neither the name of the University nor the names of its contributors
     16       1.1   tsutsui  *    may be used to endorse or promote products derived from this software
     17       1.1   tsutsui  *    without specific prior written permission.
     18       1.1   tsutsui  *
     19       1.1   tsutsui  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1   tsutsui  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1   tsutsui  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1   tsutsui  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1   tsutsui  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1   tsutsui  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1   tsutsui  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1   tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1   tsutsui  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1   tsutsui  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1   tsutsui  * SUCH DAMAGE.
     30       1.1   tsutsui  */
     31       1.1   tsutsui 
     32       1.1   tsutsui #include <sys/cdefs.h>
     33       1.1   tsutsui #ifndef lint
     34  1.5.16.1  wrstuden __COPYRIGHT("@(#) Copyright (c) 1993, 1994\
     35  1.5.16.1  wrstuden  The Regents of the University of California.  All rights reserved.");
     36       1.1   tsutsui #endif /* not lint */
     37       1.1   tsutsui 
     38       1.1   tsutsui #ifndef lint
     39  1.5.16.1  wrstuden __RCSID("$NetBSD: mount_sysvbfs.c,v 1.5.16.1 2008/09/18 04:28:28 wrstuden Exp $");
     40       1.1   tsutsui #endif /* not lint */
     41       1.1   tsutsui 
     42       1.1   tsutsui #include <sys/param.h>
     43       1.1   tsutsui #include <sys/mount.h>
     44       1.1   tsutsui 
     45       1.1   tsutsui #include <err.h>
     46       1.1   tsutsui #include <errno.h>
     47       1.1   tsutsui #include <stdio.h>
     48       1.1   tsutsui #include <stdlib.h>
     49       1.1   tsutsui 
     50       1.1   tsutsui #include <string.h>
     51       1.1   tsutsui #include <unistd.h>
     52       1.1   tsutsui 
     53       1.1   tsutsui #include <mntopts.h>
     54       1.1   tsutsui 
     55  1.5.16.1  wrstuden #include "mountprog.h"
     56  1.5.16.1  wrstuden #include "mount_sysvbfs.h"
     57       1.1   tsutsui 
     58       1.1   tsutsui static const struct mntopt mopts[] = {
     59       1.1   tsutsui 	MOPT_STDOPTS,
     60       1.1   tsutsui 	MOPT_UPDATE,
     61       1.1   tsutsui 	MOPT_GETARGS,
     62       1.3  christos 	MOPT_NULL,
     63       1.1   tsutsui };
     64       1.1   tsutsui 
     65  1.5.16.1  wrstuden static void
     66  1.5.16.1  wrstuden sysvbfs_usage(void)
     67  1.5.16.1  wrstuden {
     68  1.5.16.1  wrstuden 
     69  1.5.16.1  wrstuden 	(void)fprintf(stderr, "usage: %s [-o options] special node\n",
     70  1.5.16.1  wrstuden 	    getprogname());
     71  1.5.16.1  wrstuden 	exit(EXIT_FAILURE);
     72  1.5.16.1  wrstuden }
     73  1.5.16.1  wrstuden 
     74       1.1   tsutsui #ifndef MOUNT_NOMAIN
     75       1.1   tsutsui int
     76       1.1   tsutsui main(int argc, char **argv)
     77       1.1   tsutsui {
     78       1.1   tsutsui 
     79       1.1   tsutsui 	return mount_sysvbfs(argc, argv);
     80       1.1   tsutsui }
     81       1.1   tsutsui #endif
     82       1.1   tsutsui 
     83  1.5.16.1  wrstuden void
     84  1.5.16.1  wrstuden mount_sysvbfs_parseargs(int argc, char **argv,
     85  1.5.16.1  wrstuden 	struct sysvbfs_args *args, int *mntflags,
     86  1.5.16.1  wrstuden 	char *canon_dev, char *canon_dir)
     87       1.1   tsutsui {
     88  1.5.16.1  wrstuden 	int ch;
     89       1.2  christos 	mntoptparse_t mp;
     90       1.1   tsutsui 
     91  1.5.16.1  wrstuden 	*mntflags = 0;
     92       1.1   tsutsui 	optind = optreset = 1;		/* Reset for parse of new argv. */
     93       1.1   tsutsui 	while ((ch = getopt(argc, argv, "o:")) != -1)
     94       1.1   tsutsui 		switch (ch) {
     95       1.1   tsutsui 		case 'o':
     96  1.5.16.1  wrstuden 			mp = getmntopts(optarg, mopts, mntflags, 0);
     97       1.2  christos 			if (mp == NULL)
     98       1.2  christos 				err(1, "getmntopts");
     99       1.2  christos 			freemntopts(mp);
    100       1.1   tsutsui 			break;
    101       1.1   tsutsui 		case '?':
    102       1.1   tsutsui 		default:
    103       1.1   tsutsui 			sysvbfs_usage();
    104       1.1   tsutsui 		}
    105       1.1   tsutsui 	argc -= optind;
    106       1.1   tsutsui 	argv += optind;
    107       1.1   tsutsui 
    108       1.1   tsutsui 	if (argc != 2)
    109       1.1   tsutsui 		sysvbfs_usage();
    110       1.1   tsutsui 
    111  1.5.16.1  wrstuden 	pathadj(argv[0], canon_dev);
    112  1.5.16.1  wrstuden 	args->fspec = canon_dev;
    113  1.5.16.1  wrstuden 	pathadj(argv[1], canon_dir);
    114  1.5.16.1  wrstuden }
    115       1.1   tsutsui 
    116  1.5.16.1  wrstuden int
    117  1.5.16.1  wrstuden mount_sysvbfs(int argc, char *argv[])
    118  1.5.16.1  wrstuden {
    119  1.5.16.1  wrstuden 	struct sysvbfs_args args;
    120  1.5.16.1  wrstuden 	char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
    121  1.5.16.1  wrstuden 	const char *errcause;
    122  1.5.16.1  wrstuden 	int mntflags;
    123  1.5.16.1  wrstuden 
    124  1.5.16.1  wrstuden 	mount_sysvbfs_parseargs(argc, argv, &args, &mntflags,
    125  1.5.16.1  wrstuden 	    canon_dev, canon_dir);
    126       1.1   tsutsui 
    127  1.5.16.1  wrstuden 	if (mount(MOUNT_SYSVBFS, canon_dir, mntflags, &args, sizeof args)==-1) {
    128       1.1   tsutsui 		switch (errno) {
    129       1.1   tsutsui 		case EMFILE:
    130       1.1   tsutsui 			errcause = "mount table full";
    131       1.1   tsutsui 			break;
    132       1.1   tsutsui 		case EINVAL:
    133       1.1   tsutsui 			if (mntflags & MNT_UPDATE)
    134       1.1   tsutsui 				errcause =
    135       1.1   tsutsui 			    "specified device does not match mounted device";
    136       1.1   tsutsui 			else
    137       1.1   tsutsui 				errcause = "incorrect super block";
    138       1.1   tsutsui 			break;
    139       1.1   tsutsui 		default:
    140       1.1   tsutsui 			errcause = strerror(errno);
    141       1.1   tsutsui 			break;
    142       1.1   tsutsui 		}
    143       1.1   tsutsui 		errx(EXIT_FAILURE, "%s on %s: %s",
    144  1.5.16.1  wrstuden 		    canon_dev, canon_dir, errcause);
    145       1.1   tsutsui 	}
    146       1.1   tsutsui 	exit(EXIT_SUCCESS);
    147       1.1   tsutsui }
    148