Home | History | Annotate | Line # | Download | only in mount_fdesc
mount_fdesc.c revision 1.1
      1 /*
      2  * Copyright (c) 1993 Christoher G. Demetriou
      3  * Copyright (c) 1990, 1992 Jan-Simon Pendry
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to Berkeley by
      7  * Jan-Simon Pendry.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *      This product includes software developed by the University of
     20  *      California, Berkeley and its contributors.
     21  * 4. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  * $Id: mount_fdesc.c,v 1.1 1993/03/28 03:19:41 cgd Exp $
     38  */
     39 
     40 #include <stdio.h>
     41 #include <string.h>
     42 #include <unistd.h>
     43 #include <sys/types.h>
     44 #include <sys/mount.h>
     45 
     46 main(c, v)
     47 int c;
     48 char *v[];
     49 {
     50 	extern char *optarg;
     51 	extern int optind;
     52 	int ch;
     53 	int usage = 0;
     54 	int mounttype, mntflags;
     55 	char *dummy;
     56 	char *mountpt;
     57 	int rc;
     58 	char *pname;
     59 
     60 	pname = strrchr(v[0], '/');
     61 	if (pname == NULL)
     62 		pname = v[0];
     63 	else
     64 		pname++;
     65 
     66 #ifdef MOUNT_DEVFS
     67 	if (!strcmp(pname, "devfs"))
     68 		mounttype = MOUNT_DEVFS;
     69 	else
     70 #endif
     71 #ifdef MOUNT_FDESC
     72 	if (!strcmp(pname, "fdesc"))
     73 		mounttype = MOUNT_FDESC;
     74         else
     75 #endif
     76 #ifdef MOUNT_KERNFS
     77 	if (!strcmp(pname, "kernfs"))
     78 		mounttype = MOUNT_KERNFS;
     79         else
     80 #endif
     81 		usage++;
     82 
     83 	/*
     84 	 * Crack -F option
     85 	 */
     86 	while ((ch = getopt(c, v, "F:")) != EOF)
     87 	switch (ch) {
     88 	case 'F':
     89 		mntflags = atoi(optarg);
     90 		break;
     91 	default:
     92 	case '?':
     93 		usage++;
     94 		break;
     95 	}
     96 
     97 	/*
     98 	 * Need two more arguments
     99 	 */
    100 	if (optind != (c - 2))
    101 		usage++;
    102 
    103 	if (usage) {
    104 		fputs("usage:\n", stderr);
    105 #if defined(MOUNT_DEVFS) || defined(MOUNT_FDESC) || defined(MOUNT_KERNFS)
    106 #ifdef MOUNT_DEVFS
    107 		fputs("   mount_devfs [ fsoptions ] devfs mount-point\n", stderr);
    108 #endif
    109 #ifdef MOUNT_FDESC
    110 		fputs("   mount_fdesc [ fsoptions ] fdesc mount-point\n", stderr);
    111 #endif
    112 #ifdef MOUNT_KERNFS
    113 		fputs("   mount_kernfs [ fsoptions ] kernfs mount-point\n", stderr);
    114 #endif
    115 #else /* none of the filesystem types defined */
    116 		fputs("   no valid uses!!!\n", stderr);
    117 #endif
    118 		exit(1);
    119 	}
    120 
    121 	/*
    122 	 * Get target and mount point
    123 	 */
    124 	dummy = v[optind];
    125 	mountpt = v[optind+1];
    126 
    127 	rc = mount(mounttype, mountpt, mntflags, (caddr_t) 0);
    128 	if (rc < 0) {
    129 		perror(pname);
    130 		exit(1);
    131 	}
    132 	exit(0);
    133 }
    134