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 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright 1996-2003 Sun Microsystems, Inc. All rights reserved. 28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 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 <limits.h> 35*7c478bd9Sstevel@tonic-gate #include <string.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/fstyp.h> 37*7c478bd9Sstevel@tonic-gate #include <errno.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/vfstab.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/wait.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #define FSTYPE_MAX 8 43*7c478bd9Sstevel@tonic-gate #define FULLPATH_MAX 64 44*7c478bd9Sstevel@tonic-gate #define ARGV_MAX 1024 45*7c478bd9Sstevel@tonic-gate #define VFS_PATH "/usr/lib/fs" 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate extern char *default_fstype(); 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate char *special = NULL; /* device special name */ 50*7c478bd9Sstevel@tonic-gate char *fstype = NULL; /* fstype name is filled in here */ 51*7c478bd9Sstevel@tonic-gate char *cbasename; /* name of command */ 52*7c478bd9Sstevel@tonic-gate char *newargv[ARGV_MAX]; /* args for the fstype specific command */ 53*7c478bd9Sstevel@tonic-gate char vfstab[] = VFSTAB; 54*7c478bd9Sstevel@tonic-gate char full_path[FULLPATH_MAX]; 55*7c478bd9Sstevel@tonic-gate char *vfs_path = VFS_PATH; 56*7c478bd9Sstevel@tonic-gate int newargc = 2; 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate struct commands { 59*7c478bd9Sstevel@tonic-gate char *c_basename; 60*7c478bd9Sstevel@tonic-gate char *c_optstr; 61*7c478bd9Sstevel@tonic-gate char *c_usgstr; 62*7c478bd9Sstevel@tonic-gate } cmd_data[] = { 63*7c478bd9Sstevel@tonic-gate "ff", "F:o:p:a:m:c:n:i:?IlsuV", 64*7c478bd9Sstevel@tonic-gate "[-F FSType] [-V] [current_options] [-o specific_options] special ...", 65*7c478bd9Sstevel@tonic-gate "ncheck", "F:o:?i:asV", 66*7c478bd9Sstevel@tonic-gate "[-F FSType] [-V] [current_options] [-o specific_options] [special ...]", 67*7c478bd9Sstevel@tonic-gate NULL, "F:o:?V", 68*7c478bd9Sstevel@tonic-gate "[-F FSType] [-V] [current_options] [-o specific_options] special ..." 69*7c478bd9Sstevel@tonic-gate }; 70*7c478bd9Sstevel@tonic-gate struct commands *c_ptr; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate main(argc, argv) 73*7c478bd9Sstevel@tonic-gate int argc; 74*7c478bd9Sstevel@tonic-gate char *argv[]; 75*7c478bd9Sstevel@tonic-gate { 76*7c478bd9Sstevel@tonic-gate FILE *fp; 77*7c478bd9Sstevel@tonic-gate struct vfstab vfsbuf; 78*7c478bd9Sstevel@tonic-gate register char *ptr; 79*7c478bd9Sstevel@tonic-gate int i; 80*7c478bd9Sstevel@tonic-gate int verbose = 0; /* set if -V is specified */ 81*7c478bd9Sstevel@tonic-gate int F_flg = 0; 82*7c478bd9Sstevel@tonic-gate int usgflag = 0; 83*7c478bd9Sstevel@tonic-gate int fs_flag = 0; 84*7c478bd9Sstevel@tonic-gate int arg; /* argument from getopt() */ 85*7c478bd9Sstevel@tonic-gate extern char *optarg; /* getopt specific */ 86*7c478bd9Sstevel@tonic-gate extern int optind; 87*7c478bd9Sstevel@tonic-gate extern int opterr; 88*7c478bd9Sstevel@tonic-gate size_t strlen(); 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate cbasename = ptr = argv[0]; 91*7c478bd9Sstevel@tonic-gate while (*ptr) { 92*7c478bd9Sstevel@tonic-gate if (*ptr++ == '/') 93*7c478bd9Sstevel@tonic-gate cbasename = ptr; 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate /* 96*7c478bd9Sstevel@tonic-gate * If there are no arguments and command is ncheck then the generic 97*7c478bd9Sstevel@tonic-gate * reads the VFSTAB and executes the specific module of 98*7c478bd9Sstevel@tonic-gate * each entry which has a numeric fsckpass field. 99*7c478bd9Sstevel@tonic-gate */ 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate if (argc == 1) { /* no arguments or options */ 102*7c478bd9Sstevel@tonic-gate if (strcmp(cbasename, "ncheck") == 0) { 103*7c478bd9Sstevel@tonic-gate /* open VFSTAB */ 104*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "r")) == NULL) { 105*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: cannot open vfstab\n", 106*7c478bd9Sstevel@tonic-gate cbasename); 107*7c478bd9Sstevel@tonic-gate exit(2); 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate while ((i = getvfsent(fp, &vfsbuf)) == 0) { 110*7c478bd9Sstevel@tonic-gate if (numbers(vfsbuf.vfs_fsckpass)) { 111*7c478bd9Sstevel@tonic-gate fstype = vfsbuf.vfs_fstype; 112*7c478bd9Sstevel@tonic-gate newargv[newargc] = vfsbuf.vfs_special; 113*7c478bd9Sstevel@tonic-gate exec_specific(); 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate exit(0); 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Usage:\n"); 119*7c478bd9Sstevel@tonic-gate fprintf(stderr, 120*7c478bd9Sstevel@tonic-gate "%s [-F FSType] [-V] [current_options] [-o specific_options] special ...\n", 121*7c478bd9Sstevel@tonic-gate cbasename); 122*7c478bd9Sstevel@tonic-gate exit(2); 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate for (c_ptr = cmd_data; ((c_ptr->c_basename != NULL) && 126*7c478bd9Sstevel@tonic-gate (strcmp(c_ptr->c_basename, cbasename) != 0)); c_ptr++) 127*7c478bd9Sstevel@tonic-gate ; 128*7c478bd9Sstevel@tonic-gate while ((arg = getopt(argc, argv, c_ptr->c_optstr)) != -1) { 129*7c478bd9Sstevel@tonic-gate switch (arg) { 130*7c478bd9Sstevel@tonic-gate case 'V': /* echo complete command line */ 131*7c478bd9Sstevel@tonic-gate verbose = 1; 132*7c478bd9Sstevel@tonic-gate break; 133*7c478bd9Sstevel@tonic-gate case 'F': /* FSType specified */ 134*7c478bd9Sstevel@tonic-gate F_flg++; 135*7c478bd9Sstevel@tonic-gate fstype = optarg; 136*7c478bd9Sstevel@tonic-gate break; 137*7c478bd9Sstevel@tonic-gate case 'o': /* FSType specific arguments */ 138*7c478bd9Sstevel@tonic-gate newargv[newargc++] = "-o"; 139*7c478bd9Sstevel@tonic-gate newargv[newargc++] = optarg; 140*7c478bd9Sstevel@tonic-gate break; 141*7c478bd9Sstevel@tonic-gate case '?': /* print usage message */ 142*7c478bd9Sstevel@tonic-gate newargv[newargc++] = "-?"; 143*7c478bd9Sstevel@tonic-gate usgflag = 1; 144*7c478bd9Sstevel@tonic-gate break; 145*7c478bd9Sstevel@tonic-gate default: 146*7c478bd9Sstevel@tonic-gate newargv[newargc] = (char *)malloc(3); 147*7c478bd9Sstevel@tonic-gate sprintf(newargv[newargc++], "-%c", arg); 148*7c478bd9Sstevel@tonic-gate if (optarg) 149*7c478bd9Sstevel@tonic-gate newargv[newargc++] = optarg; 150*7c478bd9Sstevel@tonic-gate break; 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate optarg = NULL; 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate if (F_flg > 1) { 155*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: more than one FSType specified\n", 156*7c478bd9Sstevel@tonic-gate cbasename); 157*7c478bd9Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr); 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate if (F_flg && (strlen(fstype) > (size_t)FSTYPE_MAX)) { 160*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: FSType %s exceeds %d characters\n", 161*7c478bd9Sstevel@tonic-gate cbasename, fstype, FSTYPE_MAX); 162*7c478bd9Sstevel@tonic-gate exit(2); 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate if (optind == argc) { 165*7c478bd9Sstevel@tonic-gate /* all commands except ncheck must exit now */ 166*7c478bd9Sstevel@tonic-gate if (strcmp(cbasename, "ncheck") != 0) { 167*7c478bd9Sstevel@tonic-gate if ((F_flg) && (usgflag)) { 168*7c478bd9Sstevel@tonic-gate exec_specific(); 169*7c478bd9Sstevel@tonic-gate exit(0); 170*7c478bd9Sstevel@tonic-gate } 171*7c478bd9Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr); 172*7c478bd9Sstevel@tonic-gate } 173*7c478bd9Sstevel@tonic-gate if ((F_flg) && (usgflag)) { 174*7c478bd9Sstevel@tonic-gate exec_specific(); 175*7c478bd9Sstevel@tonic-gate exit(0); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate if (usgflag) 178*7c478bd9Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate /* open VFSTAB */ 181*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "r")) == NULL) { 182*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: cannot open vfstab\n", cbasename); 183*7c478bd9Sstevel@tonic-gate exit(2); 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate while ((i = getvfsent(fp, &vfsbuf)) == 0) { 186*7c478bd9Sstevel@tonic-gate if (!numbers(vfsbuf.vfs_fsckpass)) 187*7c478bd9Sstevel@tonic-gate continue; 188*7c478bd9Sstevel@tonic-gate if ((F_flg) && (strcmp(fstype, vfsbuf.vfs_fstype) != 0)) 189*7c478bd9Sstevel@tonic-gate continue; 190*7c478bd9Sstevel@tonic-gate fs_flag++; 191*7c478bd9Sstevel@tonic-gate fstype = vfsbuf.vfs_fstype; 192*7c478bd9Sstevel@tonic-gate newargv[newargc] = vfsbuf.vfs_special; 193*7c478bd9Sstevel@tonic-gate if (verbose) { 194*7c478bd9Sstevel@tonic-gate printf("%s -F %s ", cbasename, 195*7c478bd9Sstevel@tonic-gate vfsbuf.vfs_fstype); 196*7c478bd9Sstevel@tonic-gate for (i = 2; newargv[i]; i++) 197*7c478bd9Sstevel@tonic-gate printf("%s\n", newargv[i]); 198*7c478bd9Sstevel@tonic-gate continue; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate exec_specific(); 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate /* 203*7c478bd9Sstevel@tonic-gate * if (! fs_flag) { 204*7c478bd9Sstevel@tonic-gate * if (sysfs(GETFSIND, fstype) == (-1)) { 205*7c478bd9Sstevel@tonic-gate * fprintf(stderr, 206*7c478bd9Sstevel@tonic-gate * "%s: FSType %s not installed in the kernel\n", 207*7c478bd9Sstevel@tonic-gate * cbasename, fstype); 208*7c478bd9Sstevel@tonic-gate * exit(1); 209*7c478bd9Sstevel@tonic-gate * } 210*7c478bd9Sstevel@tonic-gate * } 211*7c478bd9Sstevel@tonic-gate */ 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate exit(0); 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate /* All other arguments must be specials */ 217*7c478bd9Sstevel@tonic-gate /* perform a lookup if fstype is not specified */ 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate for (; optind < argc; optind++) { 220*7c478bd9Sstevel@tonic-gate newargv[newargc] = argv[optind]; 221*7c478bd9Sstevel@tonic-gate special = newargv[newargc]; 222*7c478bd9Sstevel@tonic-gate if ((F_flg) && (usgflag)) { 223*7c478bd9Sstevel@tonic-gate exec_specific(); 224*7c478bd9Sstevel@tonic-gate exit(0); 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate if (usgflag) 227*7c478bd9Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr); 228*7c478bd9Sstevel@tonic-gate if (fstype == NULL) 229*7c478bd9Sstevel@tonic-gate lookup(); 230*7c478bd9Sstevel@tonic-gate if (verbose) { 231*7c478bd9Sstevel@tonic-gate printf("%s -F %s ", cbasename, fstype); 232*7c478bd9Sstevel@tonic-gate for (i = 2; newargv[i]; i++) 233*7c478bd9Sstevel@tonic-gate printf("%s ", newargv[i]); 234*7c478bd9Sstevel@tonic-gate printf("\n"); 235*7c478bd9Sstevel@tonic-gate continue; 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate exec_specific(); 238*7c478bd9Sstevel@tonic-gate if (!F_flg) 239*7c478bd9Sstevel@tonic-gate fstype = NULL; 240*7c478bd9Sstevel@tonic-gate } 241*7c478bd9Sstevel@tonic-gate exit(0); 242*7c478bd9Sstevel@tonic-gate } 243*7c478bd9Sstevel@tonic-gate 244*7c478bd9Sstevel@tonic-gate /* see if all numbers */ 245*7c478bd9Sstevel@tonic-gate numbers(yp) 246*7c478bd9Sstevel@tonic-gate char *yp; 247*7c478bd9Sstevel@tonic-gate { 248*7c478bd9Sstevel@tonic-gate if (yp == NULL) 249*7c478bd9Sstevel@tonic-gate return (0); 250*7c478bd9Sstevel@tonic-gate while ('0' <= *yp && *yp <= '9') 251*7c478bd9Sstevel@tonic-gate yp++; 252*7c478bd9Sstevel@tonic-gate if (*yp) 253*7c478bd9Sstevel@tonic-gate return (0); 254*7c478bd9Sstevel@tonic-gate return (1); 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate usage(cmd, usg) 259*7c478bd9Sstevel@tonic-gate char *cmd, *usg; 260*7c478bd9Sstevel@tonic-gate { 261*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Usage:\n"); 262*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s %s\n", cmd, usg); 263*7c478bd9Sstevel@tonic-gate exit(2); 264*7c478bd9Sstevel@tonic-gate } 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate /* 268*7c478bd9Sstevel@tonic-gate * This looks up the /etc/vfstab entry given the device 'special'. 269*7c478bd9Sstevel@tonic-gate * It is called when the fstype is not specified on the command line. 270*7c478bd9Sstevel@tonic-gate * 271*7c478bd9Sstevel@tonic-gate * The following global variables are used: 272*7c478bd9Sstevel@tonic-gate * special, fstype 273*7c478bd9Sstevel@tonic-gate */ 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate lookup() 276*7c478bd9Sstevel@tonic-gate { 277*7c478bd9Sstevel@tonic-gate FILE *fd; 278*7c478bd9Sstevel@tonic-gate int ret; 279*7c478bd9Sstevel@tonic-gate struct vfstab vget, vref; 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate if ((fd = fopen(vfstab, "r")) == NULL) { 282*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: cannot open vfstab\n", cbasename); 283*7c478bd9Sstevel@tonic-gate exit(1); 284*7c478bd9Sstevel@tonic-gate } 285*7c478bd9Sstevel@tonic-gate vfsnull(&vref); 286*7c478bd9Sstevel@tonic-gate vref.vfs_special = special; 287*7c478bd9Sstevel@tonic-gate ret = getvfsany(fd, &vget, &vref); 288*7c478bd9Sstevel@tonic-gate if (ret == -1) { 289*7c478bd9Sstevel@tonic-gate rewind(fd); 290*7c478bd9Sstevel@tonic-gate vfsnull(&vref); 291*7c478bd9Sstevel@tonic-gate vref.vfs_fsckdev = special; 292*7c478bd9Sstevel@tonic-gate ret = getvfsany(fd, &vget, &vref); 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate fclose(fd); 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate switch (ret) { 297*7c478bd9Sstevel@tonic-gate case -1: 298*7c478bd9Sstevel@tonic-gate fstype = default_fstype(special); 299*7c478bd9Sstevel@tonic-gate break; 300*7c478bd9Sstevel@tonic-gate case 0: 301*7c478bd9Sstevel@tonic-gate fstype = vget.vfs_fstype; 302*7c478bd9Sstevel@tonic-gate break; 303*7c478bd9Sstevel@tonic-gate case VFS_TOOLONG: 304*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: line in vfstab exceeds %d characters\n", 305*7c478bd9Sstevel@tonic-gate cbasename, VFS_LINE_MAX-2); 306*7c478bd9Sstevel@tonic-gate exit(1); 307*7c478bd9Sstevel@tonic-gate break; 308*7c478bd9Sstevel@tonic-gate case VFS_TOOFEW: 309*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: line in vfstab has too few entries\n", 310*7c478bd9Sstevel@tonic-gate cbasename); 311*7c478bd9Sstevel@tonic-gate exit(1); 312*7c478bd9Sstevel@tonic-gate break; 313*7c478bd9Sstevel@tonic-gate case VFS_TOOMANY: 314*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: line in vfstab has too many entries\n", 315*7c478bd9Sstevel@tonic-gate cbasename); 316*7c478bd9Sstevel@tonic-gate exit(1); 317*7c478bd9Sstevel@tonic-gate break; 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate } 320*7c478bd9Sstevel@tonic-gate exec_specific() 321*7c478bd9Sstevel@tonic-gate { 322*7c478bd9Sstevel@tonic-gate int status, pid, ret; 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", vfs_path, fstype, cbasename); 325*7c478bd9Sstevel@tonic-gate newargv[1] = &full_path[FULLPATH_MAX]; 326*7c478bd9Sstevel@tonic-gate while (*newargv[1]-- != '/'); 327*7c478bd9Sstevel@tonic-gate newargv[1] += 2; 328*7c478bd9Sstevel@tonic-gate switch (pid = fork()) { 329*7c478bd9Sstevel@tonic-gate case 0: 330*7c478bd9Sstevel@tonic-gate execv(full_path, &newargv[1]); 331*7c478bd9Sstevel@tonic-gate if (errno == ENOEXEC) { 332*7c478bd9Sstevel@tonic-gate newargv[0] = "sh"; 333*7c478bd9Sstevel@tonic-gate newargv[1] = full_path; 334*7c478bd9Sstevel@tonic-gate execv("/sbin/sh", &newargv[0]); 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate if (errno != ENOENT) { 337*7c478bd9Sstevel@tonic-gate perror(cbasename); 338*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: cannot execute %s\n", cbasename, 339*7c478bd9Sstevel@tonic-gate full_path); 340*7c478bd9Sstevel@tonic-gate exit(1); 341*7c478bd9Sstevel@tonic-gate } 342*7c478bd9Sstevel@tonic-gate if (sysfs(GETFSIND, fstype) == (-1)) { 343*7c478bd9Sstevel@tonic-gate fprintf(stderr, 344*7c478bd9Sstevel@tonic-gate "%s: FSType %s not installed in the kernel\n", 345*7c478bd9Sstevel@tonic-gate cbasename, fstype); 346*7c478bd9Sstevel@tonic-gate exit(1); 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: operation not applicable for FSType %s\n", 349*7c478bd9Sstevel@tonic-gate cbasename, fstype); 350*7c478bd9Sstevel@tonic-gate exit(1); 351*7c478bd9Sstevel@tonic-gate case -1: 352*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: cannot fork process\n", cbasename); 353*7c478bd9Sstevel@tonic-gate exit(2); 354*7c478bd9Sstevel@tonic-gate default: 355*7c478bd9Sstevel@tonic-gate /* 356*7c478bd9Sstevel@tonic-gate * if cannot exec specific, or fstype is not installed, exit 357*7c478bd9Sstevel@tonic-gate * after first 'exec_specific' to avoid printing duplicate 358*7c478bd9Sstevel@tonic-gate * error messages 359*7c478bd9Sstevel@tonic-gate */ 360*7c478bd9Sstevel@tonic-gate 361*7c478bd9Sstevel@tonic-gate if (wait(&status) == pid) { 362*7c478bd9Sstevel@tonic-gate ret = WHIBYTE(status); 363*7c478bd9Sstevel@tonic-gate if (ret > 0) { 364*7c478bd9Sstevel@tonic-gate exit(ret); 365*7c478bd9Sstevel@tonic-gate } 366*7c478bd9Sstevel@tonic-gate } 367*7c478bd9Sstevel@tonic-gate } 368*7c478bd9Sstevel@tonic-gate } 369