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 "proc" 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate static void rpterr(char *, char *); 51*7c478bd9Sstevel@tonic-gate static void do_mount(char *, char *, int); 52*7c478bd9Sstevel@tonic-gate static void usage(void); 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 roflag = 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, "?o:rmOq")) != -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 if (roflag) 98*7c478bd9Sstevel@tonic-gate errflag = 1; 99*7c478bd9Sstevel@tonic-gate else 100*7c478bd9Sstevel@tonic-gate roflag++; 101*7c478bd9Sstevel@tonic-gate break; 102*7c478bd9Sstevel@tonic-gate case 'O': 103*7c478bd9Sstevel@tonic-gate Oflg++; 104*7c478bd9Sstevel@tonic-gate break; 105*7c478bd9Sstevel@tonic-gate case 'o': 106*7c478bd9Sstevel@tonic-gate if (strlcpy(optbuf, optarg, sizeof (optbuf)) >= 107*7c478bd9Sstevel@tonic-gate sizeof (optbuf)) { 108*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 109*7c478bd9Sstevel@tonic-gate gettext("%s: Invalid argument: %s\n"), 110*7c478bd9Sstevel@tonic-gate myname, optarg); 111*7c478bd9Sstevel@tonic-gate return (2); 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate optsize = strlen(optbuf); 114*7c478bd9Sstevel@tonic-gate break; 115*7c478bd9Sstevel@tonic-gate case 'q': 116*7c478bd9Sstevel@tonic-gate qflg = 1; 117*7c478bd9Sstevel@tonic-gate break; 118*7c478bd9Sstevel@tonic-gate case '?': 119*7c478bd9Sstevel@tonic-gate errflag = 1; 120*7c478bd9Sstevel@tonic-gate break; 121*7c478bd9Sstevel@tonic-gate } 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate /* 124*7c478bd9Sstevel@tonic-gate * There must be at least 2 more arguments, the 125*7c478bd9Sstevel@tonic-gate * special file and the directory. 126*7c478bd9Sstevel@tonic-gate */ 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate if (((argc - optind) != 2) || (errflag)) 129*7c478bd9Sstevel@tonic-gate usage(); 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate special = argv[optind++]; 132*7c478bd9Sstevel@tonic-gate mountp = argv[optind++]; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate /* 135*7c478bd9Sstevel@tonic-gate * Perform the mount. 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate do_mount(special, mountp, roflag ? MS_RDONLY : 0); 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate return (0); 140*7c478bd9Sstevel@tonic-gate } 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate void 143*7c478bd9Sstevel@tonic-gate rpterr(char *bs, char *mp) 144*7c478bd9Sstevel@tonic-gate { 145*7c478bd9Sstevel@tonic-gate switch (errno) { 146*7c478bd9Sstevel@tonic-gate case EPERM: 147*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: insufficient privileges\n"), 148*7c478bd9Sstevel@tonic-gate myname); 149*7c478bd9Sstevel@tonic-gate break; 150*7c478bd9Sstevel@tonic-gate case ENXIO: 151*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s no such device\n"), 152*7c478bd9Sstevel@tonic-gate myname, bs); 153*7c478bd9Sstevel@tonic-gate break; 154*7c478bd9Sstevel@tonic-gate case ENOTDIR: 155*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 156*7c478bd9Sstevel@tonic-gate gettext("%s: %s not a directory\n\tor a component of %s is not a directory\n"), 157*7c478bd9Sstevel@tonic-gate myname, mp, bs); 158*7c478bd9Sstevel@tonic-gate break; 159*7c478bd9Sstevel@tonic-gate case ENOENT: 160*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 161*7c478bd9Sstevel@tonic-gate gettext("%s: %s or %s, no such file or directory\n"), 162*7c478bd9Sstevel@tonic-gate myname, bs, mp); 163*7c478bd9Sstevel@tonic-gate break; 164*7c478bd9Sstevel@tonic-gate case EINVAL: 165*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s is not this fstype.\n"), 166*7c478bd9Sstevel@tonic-gate myname, bs); 167*7c478bd9Sstevel@tonic-gate break; 168*7c478bd9Sstevel@tonic-gate case EBUSY: 169*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 170*7c478bd9Sstevel@tonic-gate gettext("%s: %s is already mounted or %s is busy\n"), 171*7c478bd9Sstevel@tonic-gate myname, bs, mp); 172*7c478bd9Sstevel@tonic-gate break; 173*7c478bd9Sstevel@tonic-gate case ENOTBLK: 174*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s not a block device\n"), 175*7c478bd9Sstevel@tonic-gate myname, bs); 176*7c478bd9Sstevel@tonic-gate break; 177*7c478bd9Sstevel@tonic-gate case EROFS: 178*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s write-protected\n"), 179*7c478bd9Sstevel@tonic-gate myname, bs); 180*7c478bd9Sstevel@tonic-gate break; 181*7c478bd9Sstevel@tonic-gate case ENOSPC: 182*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 183*7c478bd9Sstevel@tonic-gate gettext("%s: the state of %s is not okay\n" 184*7c478bd9Sstevel@tonic-gate "\tand it was attempted to mount read/write\n"), 185*7c478bd9Sstevel@tonic-gate myname, bs); 186*7c478bd9Sstevel@tonic-gate break; 187*7c478bd9Sstevel@tonic-gate default: 188*7c478bd9Sstevel@tonic-gate perror(myname); 189*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot mount %s\n"), 190*7c478bd9Sstevel@tonic-gate myname, bs); 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate static void 195*7c478bd9Sstevel@tonic-gate do_mount(char *special, char *mountp, int rflag) 196*7c478bd9Sstevel@tonic-gate { 197*7c478bd9Sstevel@tonic-gate char *savedoptbuf; 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate if ((savedoptbuf = strdup(optbuf)) == NULL) { 200*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of memory\n"), 201*7c478bd9Sstevel@tonic-gate myname); 202*7c478bd9Sstevel@tonic-gate exit(2); 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate if (Oflg) 206*7c478bd9Sstevel@tonic-gate rflag |= MS_OVERLAY; 207*7c478bd9Sstevel@tonic-gate if (mflg) 208*7c478bd9Sstevel@tonic-gate rflag |= MS_NOMNTTAB; 209*7c478bd9Sstevel@tonic-gate if (mount(special, mountp, rflag | MS_OPTIONSTR, fstype, NULL, 0, 210*7c478bd9Sstevel@tonic-gate optbuf, MAX_MNTOPT_STR)) { 211*7c478bd9Sstevel@tonic-gate rpterr(special, mountp); 212*7c478bd9Sstevel@tonic-gate exit(2); 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate if (optsize && !qflg) 215*7c478bd9Sstevel@tonic-gate cmp_requested_to_actual_options(savedoptbuf, optbuf, 216*7c478bd9Sstevel@tonic-gate special, mountp); 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate static void 220*7c478bd9Sstevel@tonic-gate usage(void) 221*7c478bd9Sstevel@tonic-gate { 222*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 223*7c478bd9Sstevel@tonic-gate gettext("%s usage:\n%s [-F %s] [-r] [-o specific_options] " 224*7c478bd9Sstevel@tonic-gate "{special | mount_point}\n%s [-F %s] [-r] [-o specific_options]" 225*7c478bd9Sstevel@tonic-gate " special mount_point\n"), 226*7c478bd9Sstevel@tonic-gate fstype, myname, fstype, myname, fstype); 227*7c478bd9Sstevel@tonic-gate exit(1); 228*7c478bd9Sstevel@tonic-gate } 229