1 /* 2 * Copyright (c) 1990, 1992 Jan-Simon Pendry 3 * Copyright (c) 1992, 1993, 1994 4 * The Regents of the University of California. 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 * @(#) Copyright (c) 1992, 1993, 1994 The Regents of the University of California. All rights reserved. 38 * $FreeBSD: src/sbin/mount_std/mount_std.c,v 1.10.2.1 2001/07/30 10:30:07 dd Exp $ 39 */ 40 41 #include <sys/param.h> 42 #include <sys/mount.h> 43 44 #include <err.h> 45 #include <mntopts.h> 46 #include <stdio.h> 47 #include <stdlib.h> 48 #include <string.h> 49 #include <sysexits.h> 50 #include <unistd.h> 51 52 static struct mntopt mopts[] = { 53 MOPT_STDOPTS, 54 { .m_option = NULL } 55 }; 56 57 static void usage(void) __dead2; 58 static const char *fsname; 59 60 int 61 main(int argc, char **argv) 62 { 63 int ch, mntflags; 64 char mntpath[MAXPATHLEN]; 65 struct vfsconf vfc; 66 int error; 67 68 /* 69 * XXX 70 * mount(8) calls the mount programs with an argv[0] which is 71 * /just/ the filesystem name. So, if there is no underscore 72 * in argv[0], we assume that we are being called from mount(8) 73 * and that argv[0] is thus the name of the filesystem type. 74 */ 75 fsname = strrchr(argv[0], '_'); 76 if (fsname) { 77 if (strcmp(fsname, "_std") == 0) 78 errx(EX_USAGE, "argv[0] must end in _fsname"); 79 fsname++; 80 } else { 81 fsname = argv[0]; 82 } 83 84 mntflags = 0; 85 while ((ch = getopt(argc, argv, "o:")) != -1) 86 switch (ch) { 87 case 'o': 88 getmntopts(optarg, mopts, &mntflags, 0); 89 break; 90 case '?': 91 default: 92 usage(); 93 } 94 argc -= optind; 95 argv += optind; 96 97 if (argc != 2) 98 usage(); 99 100 error = getvfsbyname(fsname, &vfc); 101 if (error && vfsisloadable(fsname)) { 102 if(vfsload(fsname)) 103 err(EX_OSERR, "vfsload(%s)", fsname); 104 endvfsent(); 105 error = getvfsbyname(fsname, &vfc); 106 } 107 if (error) 108 errx(EX_OSERR, "%s filesystem not available", fsname); 109 110 /* resolve the mountpoint with realpath(3) */ 111 checkpath(argv[1], mntpath); 112 113 if (mount(vfc.vfc_name, mntpath, mntflags, NULL)) 114 err(EX_OSERR, NULL); 115 exit(0); 116 } 117 118 void 119 usage(void) 120 { 121 fprintf(stderr, 122 "usage: mount_%s [-o options] what_to_mount mount_point\n", fsname); 123 exit(EX_USAGE); 124 } 125