1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <stdio.h> 34*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 35*7c478bd9Sstevel@tonic-gate #include <signal.h> 36*7c478bd9Sstevel@tonic-gate #include <errno.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/mnttab.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/mount.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 40*7c478bd9Sstevel@tonic-gate #include <locale.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 42*7c478bd9Sstevel@tonic-gate #include <string.h> 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #include <fslib.h> 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #define NAME_MAX 64 /* sizeof "fstype myname" */ 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #define FSTYPE "mntfs" 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate static void do_mount(char *, char *, int); 51*7c478bd9Sstevel@tonic-gate static void usage(void); 52*7c478bd9Sstevel@tonic-gate static void rpterr(char *, char *); 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate static char optbuf[MAX_MNTOPT_STR] = { '\0', }; 55*7c478bd9Sstevel@tonic-gate static int optsize = 0; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate static int flags = 0; 58*7c478bd9Sstevel@tonic-gate static int mflg = 0; /* don't update /etc/mnttab flag */ 59*7c478bd9Sstevel@tonic-gate static int Oflg = 0; 60*7c478bd9Sstevel@tonic-gate static int qflg = 0; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate static char typename[NAME_MAX], *myname; 63*7c478bd9Sstevel@tonic-gate static char fstype[] = FSTYPE; 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate int 66*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 67*7c478bd9Sstevel@tonic-gate { 68*7c478bd9Sstevel@tonic-gate char *special, *mountp; 69*7c478bd9Sstevel@tonic-gate int errflag = 0; 70*7c478bd9Sstevel@tonic-gate int cc; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 75*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 76*7c478bd9Sstevel@tonic-gate #endif 77*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate myname = strrchr(argv[0], '/'); 80*7c478bd9Sstevel@tonic-gate if (myname) 81*7c478bd9Sstevel@tonic-gate myname++; 82*7c478bd9Sstevel@tonic-gate else 83*7c478bd9Sstevel@tonic-gate myname = argv[0]; 84*7c478bd9Sstevel@tonic-gate (void) snprintf(typename, sizeof (typename), "%s %s", fstype, myname); 85*7c478bd9Sstevel@tonic-gate argv[0] = typename; 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* 88*7c478bd9Sstevel@tonic-gate * check for proper arguments 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate while ((cc = getopt(argc, argv, "?rmOo:q")) != -1) 92*7c478bd9Sstevel@tonic-gate switch (cc) { 93*7c478bd9Sstevel@tonic-gate case 'm': 94*7c478bd9Sstevel@tonic-gate mflg++; 95*7c478bd9Sstevel@tonic-gate break; 96*7c478bd9Sstevel@tonic-gate case 'r': 97*7c478bd9Sstevel@tonic-gate flags |= MS_RDONLY; 98*7c478bd9Sstevel@tonic-gate break; 99*7c478bd9Sstevel@tonic-gate case 'O': 100*7c478bd9Sstevel@tonic-gate Oflg++; 101*7c478bd9Sstevel@tonic-gate break; 102*7c478bd9Sstevel@tonic-gate case 'o': 103*7c478bd9Sstevel@tonic-gate if (strlcpy(optbuf, optarg, sizeof (optbuf)) >= 104*7c478bd9Sstevel@tonic-gate sizeof (optbuf)) { 105*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 106*7c478bd9Sstevel@tonic-gate gettext("%s: Invalid argument: %s\n"), 107*7c478bd9Sstevel@tonic-gate myname, optarg); 108*7c478bd9Sstevel@tonic-gate return (2); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate optsize = strlen(optbuf); 111*7c478bd9Sstevel@tonic-gate break; 112*7c478bd9Sstevel@tonic-gate case 'q': 113*7c478bd9Sstevel@tonic-gate qflg++; 114*7c478bd9Sstevel@tonic-gate break; 115*7c478bd9Sstevel@tonic-gate case '?': 116*7c478bd9Sstevel@tonic-gate default: 117*7c478bd9Sstevel@tonic-gate errflag = 1; 118*7c478bd9Sstevel@tonic-gate break; 119*7c478bd9Sstevel@tonic-gate } 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* 122*7c478bd9Sstevel@tonic-gate * There must be at least 2 more arguments, the 123*7c478bd9Sstevel@tonic-gate * special file and the directory. 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate if (((argc - optind) != 2) || (errflag)) 127*7c478bd9Sstevel@tonic-gate usage(); 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate special = argv[optind++]; 130*7c478bd9Sstevel@tonic-gate mountp = argv[optind++]; 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* 133*7c478bd9Sstevel@tonic-gate * Perform the mount. 134*7c478bd9Sstevel@tonic-gate */ 135*7c478bd9Sstevel@tonic-gate if (mflg) 136*7c478bd9Sstevel@tonic-gate flags |= MS_NOMNTTAB; 137*7c478bd9Sstevel@tonic-gate do_mount(special, mountp, flags); 138*7c478bd9Sstevel@tonic-gate return (0); 139*7c478bd9Sstevel@tonic-gate } 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate static void 142*7c478bd9Sstevel@tonic-gate rpterr(char *bs, char *mp) 143*7c478bd9Sstevel@tonic-gate { 144*7c478bd9Sstevel@tonic-gate switch (errno) { 145*7c478bd9Sstevel@tonic-gate case EPERM: 146*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: insufficient privileges\n"), 147*7c478bd9Sstevel@tonic-gate myname); 148*7c478bd9Sstevel@tonic-gate break; 149*7c478bd9Sstevel@tonic-gate case ENXIO: 150*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s no such device\n"), 151*7c478bd9Sstevel@tonic-gate myname, bs); 152*7c478bd9Sstevel@tonic-gate break; 153*7c478bd9Sstevel@tonic-gate case ENOTDIR: 154*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 155*7c478bd9Sstevel@tonic-gate gettext("%s: %s not a directory\n\tor a component of %s is not a directory\n"), 156*7c478bd9Sstevel@tonic-gate myname, mp, bs); 157*7c478bd9Sstevel@tonic-gate break; 158*7c478bd9Sstevel@tonic-gate case ENOENT: 159*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 160*7c478bd9Sstevel@tonic-gate gettext("%s: %s or %s, no such file or directory\n"), 161*7c478bd9Sstevel@tonic-gate myname, bs, mp); 162*7c478bd9Sstevel@tonic-gate break; 163*7c478bd9Sstevel@tonic-gate case EINVAL: 164*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s is not this fstype.\n"), 165*7c478bd9Sstevel@tonic-gate myname, bs); 166*7c478bd9Sstevel@tonic-gate break; 167*7c478bd9Sstevel@tonic-gate case EBUSY: 168*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 169*7c478bd9Sstevel@tonic-gate gettext("%s: %s is already mounted or %s is busy\n"), 170*7c478bd9Sstevel@tonic-gate myname, bs, mp); 171*7c478bd9Sstevel@tonic-gate break; 172*7c478bd9Sstevel@tonic-gate case EROFS: 173*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s write-protected\n"), 174*7c478bd9Sstevel@tonic-gate myname, bs); 175*7c478bd9Sstevel@tonic-gate break; 176*7c478bd9Sstevel@tonic-gate case ENOSPC: 177*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 178*7c478bd9Sstevel@tonic-gate gettext("%s: the state of %s is not okay\n" 179*7c478bd9Sstevel@tonic-gate "\tand it was attempted to mount read/write\n"), 180*7c478bd9Sstevel@tonic-gate myname, bs); 181*7c478bd9Sstevel@tonic-gate break; 182*7c478bd9Sstevel@tonic-gate default: 183*7c478bd9Sstevel@tonic-gate perror(myname); 184*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot mount %s\n"), 185*7c478bd9Sstevel@tonic-gate myname, bs); 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate } 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate static void 190*7c478bd9Sstevel@tonic-gate do_mount(char *special, char *mountp, int rflag) 191*7c478bd9Sstevel@tonic-gate { 192*7c478bd9Sstevel@tonic-gate char *savedoptbuf; 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate if ((savedoptbuf = strdup(optbuf)) == NULL) { 195*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of memory\n"), 196*7c478bd9Sstevel@tonic-gate myname); 197*7c478bd9Sstevel@tonic-gate exit(1); 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate rflag |= Oflg ? MS_OVERLAY : 0; 201*7c478bd9Sstevel@tonic-gate if (mount(special, mountp, rflag | MS_OPTIONSTR, fstype, NULL, 0, 202*7c478bd9Sstevel@tonic-gate optbuf, MAX_MNTOPT_STR)) { 203*7c478bd9Sstevel@tonic-gate rpterr(special, mountp); 204*7c478bd9Sstevel@tonic-gate exit(1); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate if (optsize && !qflg) 208*7c478bd9Sstevel@tonic-gate cmp_requested_to_actual_options(savedoptbuf, optbuf, 209*7c478bd9Sstevel@tonic-gate special, mountp); 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate static void 213*7c478bd9Sstevel@tonic-gate usage(void) 214*7c478bd9Sstevel@tonic-gate { 215*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 216*7c478bd9Sstevel@tonic-gate gettext("%s usage:\n%s [-F %s] [-r] [-o specific_options] " 217*7c478bd9Sstevel@tonic-gate "{special | mount_point}\n%s [-F %s] [-r] [-o specific_options]" 218*7c478bd9Sstevel@tonic-gate " special mount_point\n"), 219*7c478bd9Sstevel@tonic-gate fstype, myname, fstype, myname, fstype); 220*7c478bd9Sstevel@tonic-gate exit(2); 221*7c478bd9Sstevel@tonic-gate } 222