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 #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <ctype.h> 30*7c478bd9Sstevel@tonic-gate #include <string.h> 31*7c478bd9Sstevel@tonic-gate #include <stdio.h> 32*7c478bd9Sstevel@tonic-gate #include <stdlib.h> /* for getopt(3) */ 33*7c478bd9Sstevel@tonic-gate #include <signal.h> 34*7c478bd9Sstevel@tonic-gate #include <locale.h> 35*7c478bd9Sstevel@tonic-gate #include <fslib.h> 36*7c478bd9Sstevel@tonic-gate #include <errno.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/mnttab.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/mount.h> 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #define FSTYPE "udfs" 42*7c478bd9Sstevel@tonic-gate #define NAME_MAX 64 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate static int roflag = 0; 45*7c478bd9Sstevel@tonic-gate static int mflag = 0; 46*7c478bd9Sstevel@tonic-gate static int Oflag = 0; 47*7c478bd9Sstevel@tonic-gate static int qflag = 0; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate static char optbuf[MAX_MNTOPT_STR] = { '\0', }; 50*7c478bd9Sstevel@tonic-gate static int optsize = 0; 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate static char fstype[] = FSTYPE; 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate static char typename[NAME_MAX], *myname; 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate static void do_mount(char *, char *, int); 57*7c478bd9Sstevel@tonic-gate static void rpterr(char *, char *); 58*7c478bd9Sstevel@tonic-gate static void usage(void); 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate int 61*7c478bd9Sstevel@tonic-gate main(int argc, char **argv) 62*7c478bd9Sstevel@tonic-gate { 63*7c478bd9Sstevel@tonic-gate char *special, *mountp; 64*7c478bd9Sstevel@tonic-gate int flags = 0; 65*7c478bd9Sstevel@tonic-gate int c; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 70*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 71*7c478bd9Sstevel@tonic-gate #endif 72*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate myname = strrchr(argv[0], '/'); 75*7c478bd9Sstevel@tonic-gate if (myname) { 76*7c478bd9Sstevel@tonic-gate myname++; 77*7c478bd9Sstevel@tonic-gate } else { 78*7c478bd9Sstevel@tonic-gate myname = argv[0]; 79*7c478bd9Sstevel@tonic-gate } 80*7c478bd9Sstevel@tonic-gate (void) snprintf(typename, sizeof (typename), "%s %s", fstype, myname); 81*7c478bd9Sstevel@tonic-gate argv[0] = typename; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate /* check for proper arguments */ 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "mo:rOq")) != EOF) { 86*7c478bd9Sstevel@tonic-gate switch (c) { 87*7c478bd9Sstevel@tonic-gate case 'm': 88*7c478bd9Sstevel@tonic-gate mflag++; 89*7c478bd9Sstevel@tonic-gate break; 90*7c478bd9Sstevel@tonic-gate case 'o': 91*7c478bd9Sstevel@tonic-gate if (strlcpy(optbuf, optarg, sizeof (optbuf)) >= 92*7c478bd9Sstevel@tonic-gate sizeof (optbuf)) { 93*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 94*7c478bd9Sstevel@tonic-gate gettext("%s: Invalid argument: %s\n"), 95*7c478bd9Sstevel@tonic-gate myname, optarg); 96*7c478bd9Sstevel@tonic-gate return (2); 97*7c478bd9Sstevel@tonic-gate } 98*7c478bd9Sstevel@tonic-gate optsize = strlen(optbuf); 99*7c478bd9Sstevel@tonic-gate break; 100*7c478bd9Sstevel@tonic-gate case 'r': 101*7c478bd9Sstevel@tonic-gate roflag++; 102*7c478bd9Sstevel@tonic-gate break; 103*7c478bd9Sstevel@tonic-gate case 'O': 104*7c478bd9Sstevel@tonic-gate Oflag++; 105*7c478bd9Sstevel@tonic-gate break; 106*7c478bd9Sstevel@tonic-gate case 'q': 107*7c478bd9Sstevel@tonic-gate qflag = 1; 108*7c478bd9Sstevel@tonic-gate break; 109*7c478bd9Sstevel@tonic-gate default : 110*7c478bd9Sstevel@tonic-gate break; 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate if ((argc - optind) != 2) 115*7c478bd9Sstevel@tonic-gate usage(); 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate special = argv[optind++]; 118*7c478bd9Sstevel@tonic-gate mountp = argv[optind++]; 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate if (roflag) 121*7c478bd9Sstevel@tonic-gate flags = MS_RDONLY; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate if (optsize > 0) { 124*7c478bd9Sstevel@tonic-gate struct mnttab m; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate m.mnt_mntopts = optbuf; 127*7c478bd9Sstevel@tonic-gate if (hasmntopt(&m, "m")) 128*7c478bd9Sstevel@tonic-gate mflag++; 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate flags |= (Oflag ? MS_OVERLAY : 0); 132*7c478bd9Sstevel@tonic-gate flags |= (mflag ? MS_NOMNTTAB : 0); 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* 136*7c478bd9Sstevel@tonic-gate * Perform the mount. 137*7c478bd9Sstevel@tonic-gate * Only the low-order bit of "roflag" is used by the system 138*7c478bd9Sstevel@tonic-gate * calls (to denote read-only or read-write). 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate do_mount(special, mountp, flags); 141*7c478bd9Sstevel@tonic-gate return (0); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate static void 146*7c478bd9Sstevel@tonic-gate rpterr(char *bs, char *mp) 147*7c478bd9Sstevel@tonic-gate { 148*7c478bd9Sstevel@tonic-gate switch (errno) { 149*7c478bd9Sstevel@tonic-gate case EPERM: 150*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 151*7c478bd9Sstevel@tonic-gate gettext("%s: insufficient privileges\n"), myname); 152*7c478bd9Sstevel@tonic-gate break; 153*7c478bd9Sstevel@tonic-gate case ENXIO: 154*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 155*7c478bd9Sstevel@tonic-gate gettext("%s: %s no such device\n"), myname, bs); 156*7c478bd9Sstevel@tonic-gate break; 157*7c478bd9Sstevel@tonic-gate case ENOTDIR: 158*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 159*7c478bd9Sstevel@tonic-gate gettext("%s: %s not a directory\n\t" 160*7c478bd9Sstevel@tonic-gate "or a component of %s is not a directory\n"), 161*7c478bd9Sstevel@tonic-gate myname, mp, bs); 162*7c478bd9Sstevel@tonic-gate break; 163*7c478bd9Sstevel@tonic-gate case ENOENT: 164*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 165*7c478bd9Sstevel@tonic-gate gettext("%s: %s or %s, no such file or directory\n"), 166*7c478bd9Sstevel@tonic-gate myname, bs, mp); 167*7c478bd9Sstevel@tonic-gate break; 168*7c478bd9Sstevel@tonic-gate case EINVAL: 169*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 170*7c478bd9Sstevel@tonic-gate gettext("%s: %s is not an udfs file system.\n"), 171*7c478bd9Sstevel@tonic-gate typename, bs); 172*7c478bd9Sstevel@tonic-gate break; 173*7c478bd9Sstevel@tonic-gate case EBUSY: 174*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 175*7c478bd9Sstevel@tonic-gate gettext("%s: %s is already mounted or %s is busy\n"), 176*7c478bd9Sstevel@tonic-gate myname, bs, mp); 177*7c478bd9Sstevel@tonic-gate break; 178*7c478bd9Sstevel@tonic-gate case ENOTBLK: 179*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 180*7c478bd9Sstevel@tonic-gate gettext("%s: %s not a block device\n"), myname, bs); 181*7c478bd9Sstevel@tonic-gate break; 182*7c478bd9Sstevel@tonic-gate case EROFS: 183*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 184*7c478bd9Sstevel@tonic-gate gettext("%s: %s write-protected\n"), 185*7c478bd9Sstevel@tonic-gate myname, bs); 186*7c478bd9Sstevel@tonic-gate break; 187*7c478bd9Sstevel@tonic-gate case ENOSPC: 188*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 189*7c478bd9Sstevel@tonic-gate gettext("%s: %s is corrupted. needs checking\n"), 190*7c478bd9Sstevel@tonic-gate myname, bs); 191*7c478bd9Sstevel@tonic-gate break; 192*7c478bd9Sstevel@tonic-gate default: 193*7c478bd9Sstevel@tonic-gate perror(myname); 194*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 195*7c478bd9Sstevel@tonic-gate gettext("%s: cannot mount %s\n"), myname, bs); 196*7c478bd9Sstevel@tonic-gate } 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate static void 201*7c478bd9Sstevel@tonic-gate do_mount(char *special, char *mountp, int flag) 202*7c478bd9Sstevel@tonic-gate { 203*7c478bd9Sstevel@tonic-gate char *savedoptbuf; 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate if ((savedoptbuf = strdup(optbuf)) == NULL) { 206*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of memory\n"), 207*7c478bd9Sstevel@tonic-gate myname); 208*7c478bd9Sstevel@tonic-gate exit(2); 209*7c478bd9Sstevel@tonic-gate } 210*7c478bd9Sstevel@tonic-gate if (mount(special, mountp, flag | MS_DATA | MS_OPTIONSTR, 211*7c478bd9Sstevel@tonic-gate fstype, NULL, 0, optbuf, MAX_MNTOPT_STR) == -1) { 212*7c478bd9Sstevel@tonic-gate rpterr(special, mountp); 213*7c478bd9Sstevel@tonic-gate exit(31+2); 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate if (optsize && !qflag) 216*7c478bd9Sstevel@tonic-gate cmp_requested_to_actual_options(savedoptbuf, optbuf, 217*7c478bd9Sstevel@tonic-gate special, mountp); 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate static void 222*7c478bd9Sstevel@tonic-gate usage(void) 223*7c478bd9Sstevel@tonic-gate { 224*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("udfs usage:\n" 225*7c478bd9Sstevel@tonic-gate "mount [-F udfs] [generic options] " 226*7c478bd9Sstevel@tonic-gate "[-o suboptions] {special | mount_point}\n")); 227*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("\tsuboptions are: \n" 228*7c478bd9Sstevel@tonic-gate "\t ro,rw,nosuid,remount,m\n")); 229*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext( 230*7c478bd9Sstevel@tonic-gate "\t only one of ro, rw can be " 231*7c478bd9Sstevel@tonic-gate "used at the same time\n")); 232*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext( 233*7c478bd9Sstevel@tonic-gate "\t remount can be used only with rw\n")); 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate exit(32); 236*7c478bd9Sstevel@tonic-gate } 237