17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23355d6bb5Sswilcox * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <stdio.h> 347c478bd9Sstevel@tonic-gate #include <errno.h> 357c478bd9Sstevel@tonic-gate #include <limits.h> 367c478bd9Sstevel@tonic-gate #include <fcntl.h> 377c478bd9Sstevel@tonic-gate #include <string.h> 387c478bd9Sstevel@tonic-gate #include <sys/types.h> 397c478bd9Sstevel@tonic-gate #include <sys/stat.h> 407c478bd9Sstevel@tonic-gate #include <sys/wait.h> 417c478bd9Sstevel@tonic-gate #include <sys/vfstab.h> 427c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 437c478bd9Sstevel@tonic-gate #include <locale.h> 447c478bd9Sstevel@tonic-gate #include <libintl.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #define ARGV_MAX 16 477c478bd9Sstevel@tonic-gate #define FSTYPE_MAX 8 487c478bd9Sstevel@tonic-gate #define VFS_PATH "/usr/lib/fs" 497c478bd9Sstevel@tonic-gate #define VFS_PATH2 "/etc/fs" 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define CHECK(xx, yy)\ 527c478bd9Sstevel@tonic-gate if (xx == (yy)-1) {\ 537c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: too many arguments\n"), myname); \ 547c478bd9Sstevel@tonic-gate usage(); \ 557c478bd9Sstevel@tonic-gate } 567c478bd9Sstevel@tonic-gate #define OPTION(flag)\ 577c478bd9Sstevel@tonic-gate options++; \ 587c478bd9Sstevel@tonic-gate nargv[nargc++] = flag; \ 597c478bd9Sstevel@tonic-gate CHECK(nargc, ARGV_MAX); \ 607c478bd9Sstevel@tonic-gate break 617c478bd9Sstevel@tonic-gate #define OPTARG(flag)\ 627c478bd9Sstevel@tonic-gate nargv[nargc++] = flag; \ 637c478bd9Sstevel@tonic-gate CHECK(nargc, ARGV_MAX); \ 647c478bd9Sstevel@tonic-gate if (optarg) {\ 657c478bd9Sstevel@tonic-gate nargv[nargc++] = optarg; \ 667c478bd9Sstevel@tonic-gate CHECK(nargc, ARGV_MAX); \ 677c478bd9Sstevel@tonic-gate }\ 687c478bd9Sstevel@tonic-gate break 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate int nrun, ndisks; 727c478bd9Sstevel@tonic-gate int maxrun = 8; /* should be based on the machine resources */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate extern char *optarg; 757c478bd9Sstevel@tonic-gate extern int optind; 767c478bd9Sstevel@tonic-gate extern char *default_fstype(); 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate int nargc = 2; 797c478bd9Sstevel@tonic-gate int options = 0; 807c478bd9Sstevel@tonic-gate int mnt_passno = 0; 817c478bd9Sstevel@tonic-gate int exitstat = 0; 82355d6bb5Sswilcox int verbose = 0; 837c478bd9Sstevel@tonic-gate char *nargv[ARGV_MAX]; 847c478bd9Sstevel@tonic-gate char *myname, *fstype; 857c478bd9Sstevel@tonic-gate char *malloc(); 867c478bd9Sstevel@tonic-gate char vfstab[] = VFSTAB; 877c478bd9Sstevel@tonic-gate char pflg = 0, Vflg = 0; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * Keep an idea of the last device arg type as a hint to the 917c478bd9Sstevel@tonic-gate * type of the next arg. In the case of mountall, it's very likely 927c478bd9Sstevel@tonic-gate * to be the same type and the next entry in the file. This should 937c478bd9Sstevel@tonic-gate * help speed vfstab lookups. 947c478bd9Sstevel@tonic-gate */ 957c478bd9Sstevel@tonic-gate enum dev_arg_t { UNKNOWN, SPECIAL, FSCKDEV, MOUNTPT }; 967c478bd9Sstevel@tonic-gate enum dev_arg_t arg_hint = UNKNOWN; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate static struct devlist { 997c478bd9Sstevel@tonic-gate char *name; 1007c478bd9Sstevel@tonic-gate char *fsname; 1017c478bd9Sstevel@tonic-gate pid_t pid; 1027c478bd9Sstevel@tonic-gate struct devlist *nxt; 1037c478bd9Sstevel@tonic-gate } *newdev(), *getdev(); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * private copy vfstab functions 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate static struct vfstab vfsave = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; 1097c478bd9Sstevel@tonic-gate 110*08190127Sdh145677 static void usage(void); 111*08190127Sdh145677 static void fsck_dopreen(struct devlist **devp, int ndevs); 112*08190127Sdh145677 static void waiter(struct devlist **blp, struct devlist **badlist); 113*08190127Sdh145677 static void print_badlist(struct devlist *lp); 114*08190127Sdh145677 static void startdisk(struct devlist *dp); 115*08190127Sdh145677 static void do_exec(char *fstype, char *nargv[]); 116*08190127Sdh145677 static void prnt_cmd(FILE *fd, char *fstype); 117*08190127Sdh145677 static void vfserror(int flag); 118*08190127Sdh145677 1197c478bd9Sstevel@tonic-gate static int 1207c478bd9Sstevel@tonic-gate vfdup(struct vfstab *vp) 1217c478bd9Sstevel@tonic-gate { 1227c478bd9Sstevel@tonic-gate if (vfsave.vfs_special != NULL) { 1237c478bd9Sstevel@tonic-gate free(vfsave.vfs_special); 1247c478bd9Sstevel@tonic-gate vfsave.vfs_special = NULL; 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate if ((vp->vfs_special != NULL) && 1277c478bd9Sstevel@tonic-gate ((vfsave.vfs_special = strdup(vp->vfs_special)) == NULL)) { 1287c478bd9Sstevel@tonic-gate perror(myname); 1297c478bd9Sstevel@tonic-gate return (4); /* XXX */ 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate if (vfsave.vfs_fsckdev != NULL) { 1337c478bd9Sstevel@tonic-gate free(vfsave.vfs_fsckdev); 1347c478bd9Sstevel@tonic-gate vfsave.vfs_fsckdev = NULL; 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate if ((vp->vfs_fsckdev != NULL) && 1377c478bd9Sstevel@tonic-gate ((vfsave.vfs_fsckdev = strdup(vp->vfs_fsckdev)) == NULL)) { 1387c478bd9Sstevel@tonic-gate perror(myname); 1397c478bd9Sstevel@tonic-gate return (4); /* XXX */ 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate if (vfsave.vfs_mountp != NULL) { 1437c478bd9Sstevel@tonic-gate free(vfsave.vfs_mountp); 1447c478bd9Sstevel@tonic-gate vfsave.vfs_mountp = NULL; 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate if ((vp->vfs_mountp != NULL) && 1477c478bd9Sstevel@tonic-gate ((vfsave.vfs_mountp = strdup(vp->vfs_mountp)) == NULL)) { 1487c478bd9Sstevel@tonic-gate perror(myname); 1497c478bd9Sstevel@tonic-gate return (4); /* XXX */ 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate if (vfsave.vfs_fstype != NULL) { 1537c478bd9Sstevel@tonic-gate free(vfsave.vfs_fstype); 1547c478bd9Sstevel@tonic-gate vfsave.vfs_fstype = NULL; 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate if ((vp->vfs_fstype != NULL) && 1577c478bd9Sstevel@tonic-gate ((vfsave.vfs_fstype = strdup(vp->vfs_fstype)) == NULL)) { 1587c478bd9Sstevel@tonic-gate perror(myname); 1597c478bd9Sstevel@tonic-gate return (4); /* XXX */ 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate if (vfsave.vfs_fsckpass != NULL) { 1637c478bd9Sstevel@tonic-gate free(vfsave.vfs_fsckpass); 1647c478bd9Sstevel@tonic-gate vfsave.vfs_fsckpass = NULL; 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate if ((vp->vfs_fsckpass != NULL) && 1677c478bd9Sstevel@tonic-gate ((vfsave.vfs_fsckpass = strdup(vp->vfs_fsckpass)) == NULL)) { 1687c478bd9Sstevel@tonic-gate perror(myname); 1697c478bd9Sstevel@tonic-gate return (4); /* XXX */ 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate if (vfsave.vfs_automnt != NULL) { 1737c478bd9Sstevel@tonic-gate free(vfsave.vfs_automnt); 1747c478bd9Sstevel@tonic-gate vfsave.vfs_automnt = NULL; 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate if ((vp->vfs_automnt != NULL) && 1777c478bd9Sstevel@tonic-gate ((vfsave.vfs_automnt = strdup(vp->vfs_automnt)) == NULL)) { 1787c478bd9Sstevel@tonic-gate perror(myname); 1797c478bd9Sstevel@tonic-gate return (4); /* XXX */ 1807c478bd9Sstevel@tonic-gate } 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate if (vfsave.vfs_mntopts != NULL) { 1837c478bd9Sstevel@tonic-gate free(vfsave.vfs_mntopts); 1847c478bd9Sstevel@tonic-gate vfsave.vfs_mntopts = NULL; 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate if ((vp->vfs_mntopts != NULL) && 1877c478bd9Sstevel@tonic-gate ((vfsave.vfs_mntopts = strdup(vp->vfs_mntopts)) == NULL)) { 1887c478bd9Sstevel@tonic-gate perror(myname); 1897c478bd9Sstevel@tonic-gate return (4); /* XXX */ 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate *vp = vfsave; 1937c478bd9Sstevel@tonic-gate return (0); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate static int 1977c478bd9Sstevel@tonic-gate mygetvfsent(FILE *fp, struct vfstab *vp) 1987c478bd9Sstevel@tonic-gate { 1997c478bd9Sstevel@tonic-gate int error; 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate if ((error = getvfsent(fp, vp)) != 0) 2027c478bd9Sstevel@tonic-gate return (error); 2037c478bd9Sstevel@tonic-gate return (vfdup(vp)); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate static int 2077c478bd9Sstevel@tonic-gate mygetvfsany(FILE *fp, struct vfstab *vp, struct vfstab *vrefp) 2087c478bd9Sstevel@tonic-gate { 2097c478bd9Sstevel@tonic-gate int error; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate if ((error = getvfsany(fp, vp, vrefp)) != 0) 2127c478bd9Sstevel@tonic-gate return (error); 2137c478bd9Sstevel@tonic-gate return (vfdup(vp)); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 216*08190127Sdh145677 int 217*08190127Sdh145677 main(int argc, char *argv[]) 2187c478bd9Sstevel@tonic-gate { 2197c478bd9Sstevel@tonic-gate int cc, ret, other_than_ufs = 0; 2207c478bd9Sstevel@tonic-gate int questflg = 0, Fflg = 0, Vflg = 0, sanity = 0; 2217c478bd9Sstevel@tonic-gate char *subopt; 2227c478bd9Sstevel@tonic-gate FILE *fd = NULL; 2237c478bd9Sstevel@tonic-gate struct vfstab vget, vref; 2247c478bd9Sstevel@tonic-gate int preencnt = 0; 2257c478bd9Sstevel@tonic-gate struct devlist *dp, *devs = NULL; 2267c478bd9Sstevel@tonic-gate int status; 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 2297c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 2307c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ 2317c478bd9Sstevel@tonic-gate #endif 2327c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate myname = strrchr(argv[0], '/'); 2357c478bd9Sstevel@tonic-gate if (myname) 2367c478bd9Sstevel@tonic-gate myname++; 2377c478bd9Sstevel@tonic-gate else 2387c478bd9Sstevel@tonic-gate myname = argv[0]; 2397c478bd9Sstevel@tonic-gate 240355d6bb5Sswilcox while ((cc = getopt(argc, argv, "?F:mnNo:vVyY")) != -1) { 2417c478bd9Sstevel@tonic-gate switch (cc) { 2427c478bd9Sstevel@tonic-gate case '?': 2437c478bd9Sstevel@tonic-gate questflg++; 2447c478bd9Sstevel@tonic-gate if (questflg > 1) 2457c478bd9Sstevel@tonic-gate usage(); 2467c478bd9Sstevel@tonic-gate nargv[nargc++] = "-?"; 2477c478bd9Sstevel@tonic-gate CHECK(nargc, ARGV_MAX); 2487c478bd9Sstevel@tonic-gate break; 2497c478bd9Sstevel@tonic-gate case 'F': 2507c478bd9Sstevel@tonic-gate Fflg++; 2517c478bd9Sstevel@tonic-gate /* check for more that one -F */ 2527c478bd9Sstevel@tonic-gate if (Fflg > 1) { 2537c478bd9Sstevel@tonic-gate fprintf(stderr, 2547c478bd9Sstevel@tonic-gate gettext("%s: more than one fstype specified\n"), 2557c478bd9Sstevel@tonic-gate myname); 2567c478bd9Sstevel@tonic-gate usage(); 2577c478bd9Sstevel@tonic-gate } 2587c478bd9Sstevel@tonic-gate fstype = optarg; 2597c478bd9Sstevel@tonic-gate if (strlen(fstype) > (size_t)FSTYPE_MAX) { 2607c478bd9Sstevel@tonic-gate fprintf(stderr, 2617c478bd9Sstevel@tonic-gate gettext("%s: Fstype %s exceeds %d characters\n"), 2627c478bd9Sstevel@tonic-gate myname, fstype, FSTYPE_MAX); 2637c478bd9Sstevel@tonic-gate exit(1); 2647c478bd9Sstevel@tonic-gate } 2657c478bd9Sstevel@tonic-gate break; 2667c478bd9Sstevel@tonic-gate case 'm': 2677c478bd9Sstevel@tonic-gate sanity++; 2687c478bd9Sstevel@tonic-gate OPTION("-m"); 2697c478bd9Sstevel@tonic-gate case 'n': 2707c478bd9Sstevel@tonic-gate OPTION("-n"); 2717c478bd9Sstevel@tonic-gate case 'N': 2727c478bd9Sstevel@tonic-gate OPTION("-N"); 2737c478bd9Sstevel@tonic-gate case 'o': 2747c478bd9Sstevel@tonic-gate subopt = optarg; 2757c478bd9Sstevel@tonic-gate while (*subopt != '\0') { 2767c478bd9Sstevel@tonic-gate if (*subopt == 'p') { 2777c478bd9Sstevel@tonic-gate pflg++; 2787c478bd9Sstevel@tonic-gate break; 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate subopt++; 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate OPTARG("-o"); 283355d6bb5Sswilcox case 'v': 284355d6bb5Sswilcox OPTION("-v"); 2857c478bd9Sstevel@tonic-gate case 'V': 2867c478bd9Sstevel@tonic-gate Vflg++; 2877c478bd9Sstevel@tonic-gate if (Vflg > 1) 2887c478bd9Sstevel@tonic-gate usage(); 2897c478bd9Sstevel@tonic-gate break; 2907c478bd9Sstevel@tonic-gate case 'y': 2917c478bd9Sstevel@tonic-gate OPTION("-y"); 2927c478bd9Sstevel@tonic-gate case 'Y': 2937c478bd9Sstevel@tonic-gate OPTION("-Y"); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate optarg = NULL; 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* copy '--' to specific */ 2997c478bd9Sstevel@tonic-gate if (strcmp(argv[optind-1], "--") == 0) { 3007c478bd9Sstevel@tonic-gate nargv[nargc++] = argv[optind-1]; 3017c478bd9Sstevel@tonic-gate CHECK(nargc, ARGV_MAX); 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate if (questflg) { 3057c478bd9Sstevel@tonic-gate if (Fflg) { 3067c478bd9Sstevel@tonic-gate nargc = 2; 3077c478bd9Sstevel@tonic-gate nargv[nargc++] = "-?"; 3087c478bd9Sstevel@tonic-gate nargv[nargc] = NULL; 3097c478bd9Sstevel@tonic-gate do_exec(fstype, nargv); 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate usage(); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate if ((sanity) && (options > 1)) { 3157c478bd9Sstevel@tonic-gate usage(); 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate if (optind == argc) { /* no device name is specified */ 3197c478bd9Sstevel@tonic-gate if (fstype == NULL) { 3207c478bd9Sstevel@tonic-gate if ((argc > 2) && (sanity)) { 3217c478bd9Sstevel@tonic-gate usage(); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * Try to check UFS filesystems first, then check other 3267c478bd9Sstevel@tonic-gate * filesystems if they exist. 3277c478bd9Sstevel@tonic-gate * Note: Parallel checking is only available in UFS for now. 3287c478bd9Sstevel@tonic-gate */ 3297c478bd9Sstevel@tonic-gate if (fstype == NULL || strcmp(fstype, MNTTYPE_UFS) == 0) { 3307c478bd9Sstevel@tonic-gate if ((fd = fopen(vfstab, "r")) == NULL) { 3317c478bd9Sstevel@tonic-gate fprintf(stderr, 3327c478bd9Sstevel@tonic-gate gettext("%s: cannot open vfstab\n"), 3337c478bd9Sstevel@tonic-gate myname); 3347c478bd9Sstevel@tonic-gate exit(1); 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate while ((ret = mygetvfsent(fd, &vget)) == 0) { 3377c478bd9Sstevel@tonic-gate if (strcmp(vget.vfs_fstype, MNTTYPE_UFS) && 3387c478bd9Sstevel@tonic-gate numbers(vget.vfs_fsckpass)) { 3397c478bd9Sstevel@tonic-gate other_than_ufs ++; 3407c478bd9Sstevel@tonic-gate continue; 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate if (numbers(vget.vfs_fsckpass)) 3437c478bd9Sstevel@tonic-gate mnt_passno = atoi(vget.vfs_fsckpass); 3447c478bd9Sstevel@tonic-gate else 3457c478bd9Sstevel@tonic-gate continue; 3467c478bd9Sstevel@tonic-gate if (mnt_passno < 1) 3477c478bd9Sstevel@tonic-gate continue; 3487c478bd9Sstevel@tonic-gate if (pflg == 0 || mnt_passno == 1) { 3497c478bd9Sstevel@tonic-gate status = execute(vget.vfs_fsckdev, 3507c478bd9Sstevel@tonic-gate MNTTYPE_UFS, Vflg, fd); 3517c478bd9Sstevel@tonic-gate /* return the highest exit code */ 3527c478bd9Sstevel@tonic-gate if (status > exitstat) 3537c478bd9Sstevel@tonic-gate exitstat = status; 3547c478bd9Sstevel@tonic-gate } else if (preen_addev(vget.vfs_fsckdev) == 0) { 3557c478bd9Sstevel@tonic-gate preencnt++; 3567c478bd9Sstevel@tonic-gate dp = newdev(&vget); 3577c478bd9Sstevel@tonic-gate dp->nxt = devs; 3587c478bd9Sstevel@tonic-gate devs = dp; 3597c478bd9Sstevel@tonic-gate } else { 3607c478bd9Sstevel@tonic-gate /* 3617c478bd9Sstevel@tonic-gate * preening setup failed, so 3627c478bd9Sstevel@tonic-gate * execute serially here... 3637c478bd9Sstevel@tonic-gate */ 3647c478bd9Sstevel@tonic-gate fprintf(stderr, 3657c478bd9Sstevel@tonic-gate gettext("%s: preen_addev error\n"), 3667c478bd9Sstevel@tonic-gate myname); 3677c478bd9Sstevel@tonic-gate status = execute(vget.vfs_fsckdev, 3687c478bd9Sstevel@tonic-gate MNTTYPE_UFS, Vflg, fd); 3697c478bd9Sstevel@tonic-gate /* return the highest exit code */ 3707c478bd9Sstevel@tonic-gate if (status > exitstat) 3717c478bd9Sstevel@tonic-gate exitstat = status; 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate fclose(fd); 3757c478bd9Sstevel@tonic-gate if (ret > 0) 3767c478bd9Sstevel@tonic-gate vfserror(ret); 3777c478bd9Sstevel@tonic-gate if (pflg && exitstat == 0) { 3787c478bd9Sstevel@tonic-gate fsck_dopreen(&devs, preencnt); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate else 3827c478bd9Sstevel@tonic-gate other_than_ufs = 1; 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate if (other_than_ufs) { 3857c478bd9Sstevel@tonic-gate if ((fd = fopen(vfstab, "r")) == NULL) { 3867c478bd9Sstevel@tonic-gate fprintf(stderr, 3877c478bd9Sstevel@tonic-gate gettext("%s: cannot open vfstab\n"), 3887c478bd9Sstevel@tonic-gate myname); 3897c478bd9Sstevel@tonic-gate exit(1); 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate while ((ret = mygetvfsent(fd, &vget)) == 0) 3927c478bd9Sstevel@tonic-gate if (strcmp(vget.vfs_fstype, MNTTYPE_UFS) && 3937c478bd9Sstevel@tonic-gate numbers(vget.vfs_fsckpass) && 3947c478bd9Sstevel@tonic-gate vget.vfs_fsckdev != NULL && 3957c478bd9Sstevel@tonic-gate (fstype == NULL || 3967c478bd9Sstevel@tonic-gate strcmp(fstype, vget.vfs_fstype) == 0)) { 3977c478bd9Sstevel@tonic-gate status = execute(vget.vfs_fsckdev, 3987c478bd9Sstevel@tonic-gate vget.vfs_fstype, Vflg, fd); 3997c478bd9Sstevel@tonic-gate /* return the highest exit code */ 4007c478bd9Sstevel@tonic-gate if (status > exitstat) 4017c478bd9Sstevel@tonic-gate exitstat = status; 4027c478bd9Sstevel@tonic-gate } 4037c478bd9Sstevel@tonic-gate fclose(fd); 4047c478bd9Sstevel@tonic-gate if (ret > 0) 4057c478bd9Sstevel@tonic-gate vfserror(ret); 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate } else { /* device name is specified */ 4097c478bd9Sstevel@tonic-gate if (fstype == NULL && (fd = fopen(vfstab, "r")) == NULL) { 4107c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: cannot open vfstab\n"), 4117c478bd9Sstevel@tonic-gate myname); 4127c478bd9Sstevel@tonic-gate exit(1); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate while (optind < argc) { 4157c478bd9Sstevel@tonic-gate /* 4167c478bd9Sstevel@tonic-gate * If "-F FStype" is specified, use that fs type. 4177c478bd9Sstevel@tonic-gate * Otherwise, determine the fs type from /etc/vfstab 4187c478bd9Sstevel@tonic-gate * if the entry exists. Otherwise, determine the 4197c478bd9Sstevel@tonic-gate * local or remote fs type from /etc/default/df 4207c478bd9Sstevel@tonic-gate * or /etc/dfs/fstypes respectively. 4217c478bd9Sstevel@tonic-gate */ 4227c478bd9Sstevel@tonic-gate if (fstype == NULL) { 4237c478bd9Sstevel@tonic-gate if ((argc > 3) && (sanity)) { 4247c478bd9Sstevel@tonic-gate usage(); 4257c478bd9Sstevel@tonic-gate } 4267c478bd9Sstevel@tonic-gate /* must check for both special && raw devices */ 4277c478bd9Sstevel@tonic-gate vfsnull(&vref); 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate /* 4307c478bd9Sstevel@tonic-gate * Find the vfstab entry for this device. 4317c478bd9Sstevel@tonic-gate * arg_hint tells us what to try to match, 4327c478bd9Sstevel@tonic-gate * based on the type of the last arg. If 4337c478bd9Sstevel@tonic-gate * arg_hint equals UNKNOWN, then we're not 4347c478bd9Sstevel@tonic-gate * sure of the type and need to fallthrough 4357c478bd9Sstevel@tonic-gate * all 3 possibilities for vfstab lookup. 4367c478bd9Sstevel@tonic-gate * Try it as a mountpt first, since that's 4377c478bd9Sstevel@tonic-gate * what mountall gives us. 4387c478bd9Sstevel@tonic-gate */ 4397c478bd9Sstevel@tonic-gate try_again: 4407c478bd9Sstevel@tonic-gate switch (arg_hint) { 4417c478bd9Sstevel@tonic-gate case UNKNOWN: 4427c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate case MOUNTPT: 4457c478bd9Sstevel@tonic-gate vref.vfs_mountp = argv[optind]; 4467c478bd9Sstevel@tonic-gate if ((ret = mygetvfsany(fd, &vget, 4477c478bd9Sstevel@tonic-gate &vref)) == -1 || 4487c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate vref.vfs_mountp = NULL; 4517c478bd9Sstevel@tonic-gate rewind(fd); 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate if (arg_hint == MOUNTPT) { 4547c478bd9Sstevel@tonic-gate arg_hint = UNKNOWN; 4557c478bd9Sstevel@tonic-gate goto try_again; 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 4587c478bd9Sstevel@tonic-gate } else { 4597c478bd9Sstevel@tonic-gate /* Found it */ 4607c478bd9Sstevel@tonic-gate if (vget.vfs_fsckdev != NULL) { 4617c478bd9Sstevel@tonic-gate argv[optind] = 4627c478bd9Sstevel@tonic-gate vget.vfs_fsckdev; 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate arg_hint = MOUNTPT; 4657c478bd9Sstevel@tonic-gate break; 4667c478bd9Sstevel@tonic-gate } 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate case FSCKDEV: 4697c478bd9Sstevel@tonic-gate vref.vfs_fsckdev = argv[optind]; 4707c478bd9Sstevel@tonic-gate if ((ret = mygetvfsany(fd, &vget, 4717c478bd9Sstevel@tonic-gate &vref)) == -1 || 4727c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate vref.vfs_fsckdev = NULL; 4757c478bd9Sstevel@tonic-gate rewind(fd); 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate if (arg_hint == FSCKDEV) { 4787c478bd9Sstevel@tonic-gate arg_hint = UNKNOWN; 4797c478bd9Sstevel@tonic-gate goto try_again; 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 4827c478bd9Sstevel@tonic-gate } else { 4837c478bd9Sstevel@tonic-gate /* Found it */ 4847c478bd9Sstevel@tonic-gate arg_hint = FSCKDEV; 4857c478bd9Sstevel@tonic-gate break; 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate case SPECIAL: 4897c478bd9Sstevel@tonic-gate vref.vfs_special = argv[optind]; 4907c478bd9Sstevel@tonic-gate if ((ret = mygetvfsany(fd, &vget, 4917c478bd9Sstevel@tonic-gate &vref)) == -1 || 4927c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate vref.vfs_special = NULL; 4957c478bd9Sstevel@tonic-gate rewind(fd); 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate if (arg_hint == SPECIAL) { 4987c478bd9Sstevel@tonic-gate arg_hint = UNKNOWN; 4997c478bd9Sstevel@tonic-gate goto try_again; 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 5027c478bd9Sstevel@tonic-gate } else { 5037c478bd9Sstevel@tonic-gate /* Found it */ 5047c478bd9Sstevel@tonic-gate arg_hint = SPECIAL; 5057c478bd9Sstevel@tonic-gate break; 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate if (ret == 0 && vget.vfs_fstype) { 5107c478bd9Sstevel@tonic-gate if ((pflg) && (strcmp(vget.vfs_fstype, 5117c478bd9Sstevel@tonic-gate MNTTYPE_UFS) == 0) && (preen_addev( 5127c478bd9Sstevel@tonic-gate vget.vfs_fsckdev) == 0)) { 5137c478bd9Sstevel@tonic-gate preencnt++; 5147c478bd9Sstevel@tonic-gate dp = newdev(&vget); 5157c478bd9Sstevel@tonic-gate dp->nxt = devs; 5167c478bd9Sstevel@tonic-gate devs = dp; 5177c478bd9Sstevel@tonic-gate } else { 5187c478bd9Sstevel@tonic-gate status = execute(argv[optind], 5197c478bd9Sstevel@tonic-gate vget.vfs_fstype, Vflg, fd); 5207c478bd9Sstevel@tonic-gate if (status > exitstat) 5217c478bd9Sstevel@tonic-gate exitstat = status; 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate } else if (ret == -1 || 5247c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 5257c478bd9Sstevel@tonic-gate fstype = 5267c478bd9Sstevel@tonic-gate default_fstype(argv[optind]); 5277c478bd9Sstevel@tonic-gate status = execute(argv[optind], fstype, 5287c478bd9Sstevel@tonic-gate Vflg, fd); 5297c478bd9Sstevel@tonic-gate /* return the highest exit code */ 5307c478bd9Sstevel@tonic-gate if (status > exitstat) 5317c478bd9Sstevel@tonic-gate exitstat = status; 5327c478bd9Sstevel@tonic-gate } else 5337c478bd9Sstevel@tonic-gate vfserror(ret); 5347c478bd9Sstevel@tonic-gate } else { 5357c478bd9Sstevel@tonic-gate status = execute(argv[optind], fstype, 5367c478bd9Sstevel@tonic-gate Vflg, NULL); 5377c478bd9Sstevel@tonic-gate /* return the highest exit code */ 5387c478bd9Sstevel@tonic-gate if (status > exitstat) 5397c478bd9Sstevel@tonic-gate exitstat = status; 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate optind++; 5427c478bd9Sstevel@tonic-gate } 5437c478bd9Sstevel@tonic-gate if (fd != NULL) 5447c478bd9Sstevel@tonic-gate fclose(fd); 5457c478bd9Sstevel@tonic-gate if ((pflg) && (exitstat == 0)) { 5467c478bd9Sstevel@tonic-gate fsck_dopreen(&devs, preencnt); 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate } 549*08190127Sdh145677 return (exitstat); 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate 552*08190127Sdh145677 static void 553*08190127Sdh145677 fsck_dopreen(struct devlist **devp, int ndevs) 5547c478bd9Sstevel@tonic-gate { 5557c478bd9Sstevel@tonic-gate char name[1024]; 5567c478bd9Sstevel@tonic-gate int rc; 557*08190127Sdh145677 int i; 5587c478bd9Sstevel@tonic-gate struct devlist *bl, *bdp; 5597c478bd9Sstevel@tonic-gate struct devlist *badlist; 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate bl = badlist = NULL; 5627c478bd9Sstevel@tonic-gate while (ndevs > 0) { 5637c478bd9Sstevel@tonic-gate if (nrun > maxrun) 5647c478bd9Sstevel@tonic-gate waiter(&bl, &badlist); 5657c478bd9Sstevel@tonic-gate rc = preen_getdev(name); 5667c478bd9Sstevel@tonic-gate switch (rc) { 5677c478bd9Sstevel@tonic-gate case 0: 5687c478bd9Sstevel@tonic-gate break; 5697c478bd9Sstevel@tonic-gate case 1: 5707c478bd9Sstevel@tonic-gate bdp = getdev(name, devp); 5717c478bd9Sstevel@tonic-gate if (bdp == NULL) { 5727c478bd9Sstevel@tonic-gate fprintf(stderr, 5737c478bd9Sstevel@tonic-gate gettext("%s: unknown dev: `%s'\n"), 5747c478bd9Sstevel@tonic-gate myname, name); 5757c478bd9Sstevel@tonic-gate exit(1); 5767c478bd9Sstevel@tonic-gate } 5777c478bd9Sstevel@tonic-gate bdp->nxt = bl; 5787c478bd9Sstevel@tonic-gate bl = bdp; 5797c478bd9Sstevel@tonic-gate startdisk(bdp); 5807c478bd9Sstevel@tonic-gate ndevs--; 5817c478bd9Sstevel@tonic-gate break; 5827c478bd9Sstevel@tonic-gate case 2: 5837c478bd9Sstevel@tonic-gate waiter(&bl, &badlist); 5847c478bd9Sstevel@tonic-gate break; 5857c478bd9Sstevel@tonic-gate default: 5867c478bd9Sstevel@tonic-gate fprintf(stderr, 5877c478bd9Sstevel@tonic-gate gettext("%s: bad return `%d' from preen_getdev\n"), 5887c478bd9Sstevel@tonic-gate myname, rc); 5897c478bd9Sstevel@tonic-gate break; 5907c478bd9Sstevel@tonic-gate } 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate while (bl != NULL) { 5937c478bd9Sstevel@tonic-gate waiter(&bl, &badlist); 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate if (badlist != NULL) 5977c478bd9Sstevel@tonic-gate print_badlist(badlist); 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate 600*08190127Sdh145677 static void 601*08190127Sdh145677 startdisk(struct devlist *dp) 6027c478bd9Sstevel@tonic-gate { 6037c478bd9Sstevel@tonic-gate pid_t pid; 6047c478bd9Sstevel@tonic-gate 6057c478bd9Sstevel@tonic-gate nrun++; 6067c478bd9Sstevel@tonic-gate if ((pid = fork()) == -1) { 6077c478bd9Sstevel@tonic-gate perror("fork"); 6087c478bd9Sstevel@tonic-gate exit(1); 6097c478bd9Sstevel@tonic-gate } else if (pid == 0) { 6107c478bd9Sstevel@tonic-gate exitstat = execute(dp->name, MNTTYPE_UFS, Vflg, NULL); 6117c478bd9Sstevel@tonic-gate exit(exitstat); 6127c478bd9Sstevel@tonic-gate } else { 6137c478bd9Sstevel@tonic-gate dp->pid = pid; 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate 617*08190127Sdh145677 static void 618*08190127Sdh145677 waiter(struct devlist **blp, struct devlist **badlist) 6197c478bd9Sstevel@tonic-gate { 6207c478bd9Sstevel@tonic-gate pid_t curpid; 6217c478bd9Sstevel@tonic-gate int status; 622*08190127Sdh145677 struct devlist *bdp, *pbdp; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate curpid = wait(&status); 6257c478bd9Sstevel@tonic-gate if (curpid == -1) { 6267c478bd9Sstevel@tonic-gate perror("wait"); 6277c478bd9Sstevel@tonic-gate exit(1); 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate for (pbdp = NULL, bdp = *blp; bdp != NULL; pbdp = bdp, bdp = bdp->nxt) { 6317c478bd9Sstevel@tonic-gate if (bdp->pid == curpid) { 6327c478bd9Sstevel@tonic-gate break; 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate if (bdp == NULL) 6367c478bd9Sstevel@tonic-gate return; 6377c478bd9Sstevel@tonic-gate nrun--; 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate if (pbdp) 6407c478bd9Sstevel@tonic-gate pbdp->nxt = bdp->nxt; 6417c478bd9Sstevel@tonic-gate else 6427c478bd9Sstevel@tonic-gate *blp = bdp->nxt; 6437c478bd9Sstevel@tonic-gate preen_releasedev(bdp->name); 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate if (WTERMSIG(status)) { 6467c478bd9Sstevel@tonic-gate printf(gettext("%s (%s): EXITED WITH SIGNAL %d\n"), 6477c478bd9Sstevel@tonic-gate bdp->name, bdp->fsname, WTERMSIG(status)); 6487c478bd9Sstevel@tonic-gate status = status&0377 | 8<<8; 6497c478bd9Sstevel@tonic-gate } 6507c478bd9Sstevel@tonic-gate if (WHIBYTE(status) != 0) { 6517c478bd9Sstevel@tonic-gate if (WHIBYTE(status) > exitstat) 6527c478bd9Sstevel@tonic-gate exitstat = WHIBYTE(status); 6537c478bd9Sstevel@tonic-gate while (*badlist != NULL) 6547c478bd9Sstevel@tonic-gate badlist = &(*badlist)->nxt; 6557c478bd9Sstevel@tonic-gate *badlist = bdp; 6567c478bd9Sstevel@tonic-gate bdp->nxt = NULL; 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate } 6597c478bd9Sstevel@tonic-gate 660*08190127Sdh145677 static void 661*08190127Sdh145677 print_badlist(struct devlist *lp) 6627c478bd9Sstevel@tonic-gate { 6637c478bd9Sstevel@tonic-gate int x, len; 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate printf( 6667c478bd9Sstevel@tonic-gate gettext("\nTHE FOLLOWING FILE SYSTEM(S) HAD AN UNEXPECTED INCONSISTENCY:")); 6677c478bd9Sstevel@tonic-gate for (x = 3; lp != NULL; lp = lp->nxt) { 6687c478bd9Sstevel@tonic-gate len = strlen(lp->name) + strlen(lp->fsname) + 5; 6697c478bd9Sstevel@tonic-gate x += len; 6707c478bd9Sstevel@tonic-gate if (x >= 80) { 6717c478bd9Sstevel@tonic-gate printf("\n "); 6727c478bd9Sstevel@tonic-gate x = len + 3; 6737c478bd9Sstevel@tonic-gate } else { 6747c478bd9Sstevel@tonic-gate printf(" "); 6757c478bd9Sstevel@tonic-gate } 6767c478bd9Sstevel@tonic-gate printf("%s (%s)%s", lp->name, lp->fsname, 6777c478bd9Sstevel@tonic-gate lp->nxt ? "," : "\n"); 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate /* 6827c478bd9Sstevel@tonic-gate * allocate and initialize a `devlist' structure 6837c478bd9Sstevel@tonic-gate */ 6847c478bd9Sstevel@tonic-gate static 6857c478bd9Sstevel@tonic-gate struct devlist * 686*08190127Sdh145677 newdev(struct vfstab *vfsp) 6877c478bd9Sstevel@tonic-gate { 6887c478bd9Sstevel@tonic-gate struct devlist *dp; 6897c478bd9Sstevel@tonic-gate extern char *strdup(); 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate dp = (struct devlist *)malloc(sizeof (struct devlist)); 6927c478bd9Sstevel@tonic-gate if (dp == NULL) { 6937c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: out of memory\n"), myname); 6947c478bd9Sstevel@tonic-gate exit(1); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate dp->name = strdup(vfsp->vfs_fsckdev); 6977c478bd9Sstevel@tonic-gate dp->fsname = strdup(vfsp->vfs_mountp); 6987c478bd9Sstevel@tonic-gate if (dp->name == NULL || dp->fsname == NULL) { 6997c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: out of memory\n"), myname); 7007c478bd9Sstevel@tonic-gate exit(1); 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate return (dp); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate /* 7067c478bd9Sstevel@tonic-gate * locate the devlist structure in the given list that matches `name'. 7077c478bd9Sstevel@tonic-gate * If found, the structure is removed from the list, and a pointer to 7087c478bd9Sstevel@tonic-gate * it is returned. If not, NULL is returned. 7097c478bd9Sstevel@tonic-gate */ 7107c478bd9Sstevel@tonic-gate static 7117c478bd9Sstevel@tonic-gate struct devlist * 712*08190127Sdh145677 getdev(char *name, struct devlist **list) 7137c478bd9Sstevel@tonic-gate { 714*08190127Sdh145677 struct devlist *p, *lp; 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate for (lp = NULL, p = *list; p != NULL; lp = p, p = p->nxt) { 7177c478bd9Sstevel@tonic-gate if (strcmp(p->name, name) == 0) 7187c478bd9Sstevel@tonic-gate break; 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate if (p != NULL) { 7227c478bd9Sstevel@tonic-gate if (lp != NULL) 7237c478bd9Sstevel@tonic-gate lp->nxt = p->nxt; 7247c478bd9Sstevel@tonic-gate else 7257c478bd9Sstevel@tonic-gate *list = p->nxt; 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate return (p); 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate /* see if all numbers */ 731*08190127Sdh145677 int 732*08190127Sdh145677 numbers(char *yp) 7337c478bd9Sstevel@tonic-gate { 7347c478bd9Sstevel@tonic-gate if (yp == NULL) 7357c478bd9Sstevel@tonic-gate return (0); 7367c478bd9Sstevel@tonic-gate while ('0' <= *yp && *yp <= '9') 7377c478bd9Sstevel@tonic-gate yp++; 7387c478bd9Sstevel@tonic-gate if (*yp) 7397c478bd9Sstevel@tonic-gate return (0); 7407c478bd9Sstevel@tonic-gate return (1); 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate 743*08190127Sdh145677 int 744*08190127Sdh145677 execute(char *fsckdev, char *fstype, int Vflg, FILE *fd) 7457c478bd9Sstevel@tonic-gate { 7467c478bd9Sstevel@tonic-gate int st; 7477c478bd9Sstevel@tonic-gate pid_t fk; 7487c478bd9Sstevel@tonic-gate char full_path[PATH_MAX]; 7497c478bd9Sstevel@tonic-gate char *vfs_path = VFS_PATH; 7507c478bd9Sstevel@tonic-gate int status = 0; 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate nargv[nargc] = fsckdev; 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate if (Vflg) { 7557c478bd9Sstevel@tonic-gate prnt_cmd(stdout, fstype); 7567c478bd9Sstevel@tonic-gate return (0); 7577c478bd9Sstevel@tonic-gate } 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate if (fd) 7607c478bd9Sstevel@tonic-gate fcntl(fileno(fd), F_SETFD, 1); /* close on exec */ 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate if ((fk = fork()) == (pid_t)-1) { 7637c478bd9Sstevel@tonic-gate fprintf(stderr, 7647c478bd9Sstevel@tonic-gate gettext("%s: cannot fork. Try again later\n"), 7657c478bd9Sstevel@tonic-gate myname); 7667c478bd9Sstevel@tonic-gate perror(myname); 7677c478bd9Sstevel@tonic-gate exit(1); 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate if (fk == 0) { 7717c478bd9Sstevel@tonic-gate /* Try to exec the fstype dependent portion of the fsck. */ 7727c478bd9Sstevel@tonic-gate do_exec(fstype, nargv); 7737c478bd9Sstevel@tonic-gate } else { 7747c478bd9Sstevel@tonic-gate /* parent waits for child */ 7757c478bd9Sstevel@tonic-gate if (wait(&st) == (pid_t)-1) { 7767c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: bad wait\n"), myname); 7777c478bd9Sstevel@tonic-gate perror(myname); 7787c478bd9Sstevel@tonic-gate exit(1); 7797c478bd9Sstevel@tonic-gate } 7807c478bd9Sstevel@tonic-gate 7817c478bd9Sstevel@tonic-gate if ((st & 0xff) == 0x7f) { 7827c478bd9Sstevel@tonic-gate fprintf(stderr, 7837c478bd9Sstevel@tonic-gate gettext("%s: warning: the following command" 7847c478bd9Sstevel@tonic-gate " (process %d) was stopped by signal %d\n"), 7857c478bd9Sstevel@tonic-gate myname, fk, (st >> 8) & 0xff); 7867c478bd9Sstevel@tonic-gate prnt_cmd(stderr, fstype); 7877c478bd9Sstevel@tonic-gate status = ((st >> 8) & 0xff) | 0x80; 7887c478bd9Sstevel@tonic-gate } else if (st & 0xff) { 7897c478bd9Sstevel@tonic-gate if (st & 0x80) 7907c478bd9Sstevel@tonic-gate fprintf(stderr, 7917c478bd9Sstevel@tonic-gate gettext("%s: warning: the following command" 7927c478bd9Sstevel@tonic-gate " (process %d) was terminated by signal %d" 7937c478bd9Sstevel@tonic-gate " and dumped core\n"), 7947c478bd9Sstevel@tonic-gate myname, fk, st & 0x7f); 7957c478bd9Sstevel@tonic-gate else 7967c478bd9Sstevel@tonic-gate fprintf(stderr, 7977c478bd9Sstevel@tonic-gate gettext("%s: warning: the following command" 7987c478bd9Sstevel@tonic-gate " (process %d) was terminated by signal %d\n"), 7997c478bd9Sstevel@tonic-gate myname, fk, st & 0x7f); 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate prnt_cmd(stderr, fstype); 8027c478bd9Sstevel@tonic-gate status = ((st & 0xff) | 0x80); 8037c478bd9Sstevel@tonic-gate } else if (st & 0xff00) 8047c478bd9Sstevel@tonic-gate status = (st >> 8) & 0xff; 8057c478bd9Sstevel@tonic-gate } 8067c478bd9Sstevel@tonic-gate 8077c478bd9Sstevel@tonic-gate return (status); 8087c478bd9Sstevel@tonic-gate } 8097c478bd9Sstevel@tonic-gate 810*08190127Sdh145677 static void 811*08190127Sdh145677 do_exec(char *fstype, char *nargv[]) 8127c478bd9Sstevel@tonic-gate { 8137c478bd9Sstevel@tonic-gate char full_path[PATH_MAX]; 8147c478bd9Sstevel@tonic-gate char *vfs_path = VFS_PATH; 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate if (strlen(fstype) > (size_t)FSTYPE_MAX) { 8177c478bd9Sstevel@tonic-gate fprintf(stderr, 8187c478bd9Sstevel@tonic-gate gettext("%s: Fstype %s exceeds %d characters\n"), 8197c478bd9Sstevel@tonic-gate myname, fstype, FSTYPE_MAX); 8207c478bd9Sstevel@tonic-gate exit(1); 8217c478bd9Sstevel@tonic-gate } 8227c478bd9Sstevel@tonic-gate /* build the full pathname of the fstype dependent command. */ 8237c478bd9Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", vfs_path, fstype, myname); 8247c478bd9Sstevel@tonic-gate 8257c478bd9Sstevel@tonic-gate /* set the new argv[0] to the filename */ 8267c478bd9Sstevel@tonic-gate nargv[1] = myname; 8277c478bd9Sstevel@tonic-gate /* Try to exec the fstype dependent portion of the fsck. */ 8287c478bd9Sstevel@tonic-gate execv(full_path, &nargv[1]); 8297c478bd9Sstevel@tonic-gate if (errno == EACCES) { 8307c478bd9Sstevel@tonic-gate fprintf(stderr, 8317c478bd9Sstevel@tonic-gate gettext("%s: cannot execute %s - permission denied\n"), 8327c478bd9Sstevel@tonic-gate myname, full_path); 8337c478bd9Sstevel@tonic-gate } 8347c478bd9Sstevel@tonic-gate if (errno == ENOEXEC) { 8357c478bd9Sstevel@tonic-gate nargv[0] = "sh"; 8367c478bd9Sstevel@tonic-gate nargv[1] = full_path; 8377c478bd9Sstevel@tonic-gate execv("/sbin/sh", &nargv[0]); 8387c478bd9Sstevel@tonic-gate } 8397c478bd9Sstevel@tonic-gate /* second path to try */ 8407c478bd9Sstevel@tonic-gate vfs_path = VFS_PATH2; 8417c478bd9Sstevel@tonic-gate /* build the full pathname of the fstype dependent command. */ 8427c478bd9Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", vfs_path, fstype, myname); 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate /* set the new argv[0] to the filename */ 8457c478bd9Sstevel@tonic-gate nargv[1] = myname; 8467c478bd9Sstevel@tonic-gate /* Try to exec the second fstype dependent portion of the fsck. */ 8477c478bd9Sstevel@tonic-gate execv(full_path, &nargv[1]); 8487c478bd9Sstevel@tonic-gate if (errno == EACCES) { 8497c478bd9Sstevel@tonic-gate fprintf(stderr, 8507c478bd9Sstevel@tonic-gate gettext("%s: cannot execute %s - permission denied\n"), 8517c478bd9Sstevel@tonic-gate myname, full_path); 8527c478bd9Sstevel@tonic-gate exit(1); 8537c478bd9Sstevel@tonic-gate } 8547c478bd9Sstevel@tonic-gate if (errno == ENOEXEC) { 8557c478bd9Sstevel@tonic-gate nargv[0] = "sh"; 8567c478bd9Sstevel@tonic-gate nargv[1] = full_path; 8577c478bd9Sstevel@tonic-gate execv("/sbin/sh", &nargv[0]); 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate fprintf(stderr, 8607c478bd9Sstevel@tonic-gate gettext("%s: operation not applicable to FSType %s\n"), 8617c478bd9Sstevel@tonic-gate myname, fstype); 8627c478bd9Sstevel@tonic-gate exit(1); 8637c478bd9Sstevel@tonic-gate } 8647c478bd9Sstevel@tonic-gate 865*08190127Sdh145677 static void 866*08190127Sdh145677 prnt_cmd(FILE *fd, char *fstype) 8677c478bd9Sstevel@tonic-gate { 8687c478bd9Sstevel@tonic-gate char **argp; 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate fprintf(fd, "%s -F %s", myname, fstype); 8717c478bd9Sstevel@tonic-gate for (argp = &nargv[2]; *argp; argp++) 8727c478bd9Sstevel@tonic-gate fprintf(fd, " %s", *argp); 8737c478bd9Sstevel@tonic-gate fprintf(fd, "\n"); 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 876*08190127Sdh145677 static void 877*08190127Sdh145677 vfserror(int flag) 8787c478bd9Sstevel@tonic-gate { 8797c478bd9Sstevel@tonic-gate switch (flag) { 8807c478bd9Sstevel@tonic-gate case VFS_TOOLONG: 8817c478bd9Sstevel@tonic-gate fprintf(stderr, 8827c478bd9Sstevel@tonic-gate gettext("%s: line in vfstab exceeds %d characters\n"), 8837c478bd9Sstevel@tonic-gate myname, VFS_LINE_MAX-2); 8847c478bd9Sstevel@tonic-gate break; 8857c478bd9Sstevel@tonic-gate case VFS_TOOFEW: 8867c478bd9Sstevel@tonic-gate fprintf(stderr, 8877c478bd9Sstevel@tonic-gate gettext("%s: line in vfstab has too few entries\n"), 8887c478bd9Sstevel@tonic-gate myname); 8897c478bd9Sstevel@tonic-gate break; 8907c478bd9Sstevel@tonic-gate case VFS_TOOMANY: 8917c478bd9Sstevel@tonic-gate fprintf(stderr, 8927c478bd9Sstevel@tonic-gate gettext("%s: line in vfstab has too many entries\n"), 8937c478bd9Sstevel@tonic-gate myname); 8947c478bd9Sstevel@tonic-gate break; 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate exit(1); 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate 8997c478bd9Sstevel@tonic-gate int opterr = 1, optind = 1, optopt = 0; 9007c478bd9Sstevel@tonic-gate char *optarg = 0; 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate int 9037c478bd9Sstevel@tonic-gate getopt(int argc, char * const *argv, const char *opts) 9047c478bd9Sstevel@tonic-gate { 9057c478bd9Sstevel@tonic-gate static int sp = 1; 906*08190127Sdh145677 int c; 907*08190127Sdh145677 char *cp; 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate if (sp == 1) 9107c478bd9Sstevel@tonic-gate if (optind >= argc || 9117c478bd9Sstevel@tonic-gate argv[optind][0] != '-' || argv[optind][1] == '\0') 9127c478bd9Sstevel@tonic-gate return (-1); 9137c478bd9Sstevel@tonic-gate else if (strcmp(argv[optind], "--") == 0) { 9147c478bd9Sstevel@tonic-gate optind++; 9157c478bd9Sstevel@tonic-gate return (-1); 9167c478bd9Sstevel@tonic-gate } 9177c478bd9Sstevel@tonic-gate optopt = c = argv[optind][sp]; 9187c478bd9Sstevel@tonic-gate if (c == ':' || (cp = strchr(opts, c)) == 0) { 9197c478bd9Sstevel@tonic-gate if (opterr) 9207c478bd9Sstevel@tonic-gate fprintf(stderr, 9217c478bd9Sstevel@tonic-gate gettext("%s: illegal option -- %c\n"), 9227c478bd9Sstevel@tonic-gate *argv, c); 9237c478bd9Sstevel@tonic-gate if (argv[optind][++sp] == '\0') { 9247c478bd9Sstevel@tonic-gate optind++; 9257c478bd9Sstevel@tonic-gate sp = 1; 9267c478bd9Sstevel@tonic-gate } 9277c478bd9Sstevel@tonic-gate return ('?'); 9287c478bd9Sstevel@tonic-gate } 9297c478bd9Sstevel@tonic-gate if (*++cp == ':') { 9307c478bd9Sstevel@tonic-gate if (argv[optind][sp+1] != '\0') 9317c478bd9Sstevel@tonic-gate optarg = &argv[optind++][sp+1]; 9327c478bd9Sstevel@tonic-gate else if (++optind >= argc) { 9337c478bd9Sstevel@tonic-gate if (opterr) 9347c478bd9Sstevel@tonic-gate fprintf(stderr, 9357c478bd9Sstevel@tonic-gate gettext("%s: option requires an argument -- %c\n"), *argv, c); 9367c478bd9Sstevel@tonic-gate sp = 1; 9377c478bd9Sstevel@tonic-gate return ('?'); 9387c478bd9Sstevel@tonic-gate } else 9397c478bd9Sstevel@tonic-gate optarg = argv[optind++]; 9407c478bd9Sstevel@tonic-gate sp = 1; 9417c478bd9Sstevel@tonic-gate } else if (*cp == ';') { 9427c478bd9Sstevel@tonic-gate if (argv[optind][++sp] != '\0') 9437c478bd9Sstevel@tonic-gate if (isoptarg(c, &argv[optind][sp])) { 9447c478bd9Sstevel@tonic-gate optarg = &argv[optind++][sp]; 9457c478bd9Sstevel@tonic-gate sp = 1; 9467c478bd9Sstevel@tonic-gate } else 9477c478bd9Sstevel@tonic-gate optarg = NULL; 9487c478bd9Sstevel@tonic-gate else { 9497c478bd9Sstevel@tonic-gate sp = 1; 9507c478bd9Sstevel@tonic-gate if (++optind >= argc || !isoptarg(c, &argv[optind][0])) 9517c478bd9Sstevel@tonic-gate optarg = NULL; 9527c478bd9Sstevel@tonic-gate else 9537c478bd9Sstevel@tonic-gate optarg = argv[optind++]; 9547c478bd9Sstevel@tonic-gate } 9557c478bd9Sstevel@tonic-gate } else { 9567c478bd9Sstevel@tonic-gate if (argv[optind][++sp] == '\0') { 9577c478bd9Sstevel@tonic-gate sp = 1; 9587c478bd9Sstevel@tonic-gate optind++; 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate optarg = NULL; 9617c478bd9Sstevel@tonic-gate } 9627c478bd9Sstevel@tonic-gate return (c); 9637c478bd9Sstevel@tonic-gate } 9647c478bd9Sstevel@tonic-gate 965*08190127Sdh145677 int 966*08190127Sdh145677 isoptarg(int cc, char *arg) 9677c478bd9Sstevel@tonic-gate { 9687c478bd9Sstevel@tonic-gate if (cc == 's' || cc == 'S') { 9697c478bd9Sstevel@tonic-gate while (*arg >= '0' && *arg <= '9') 9707c478bd9Sstevel@tonic-gate arg++; 9717c478bd9Sstevel@tonic-gate if (*arg++ != ':') 9727c478bd9Sstevel@tonic-gate return (0); 9737c478bd9Sstevel@tonic-gate while (*arg >= '0' && *arg <= '9') 9747c478bd9Sstevel@tonic-gate arg++; 9757c478bd9Sstevel@tonic-gate if (*arg) 9767c478bd9Sstevel@tonic-gate return (0); 9777c478bd9Sstevel@tonic-gate return (1); 9787c478bd9Sstevel@tonic-gate } 9797c478bd9Sstevel@tonic-gate return (0); 9807c478bd9Sstevel@tonic-gate } 9817c478bd9Sstevel@tonic-gate 982*08190127Sdh145677 static void 983*08190127Sdh145677 usage(void) 9847c478bd9Sstevel@tonic-gate { 9857c478bd9Sstevel@tonic-gate fprintf(stderr, 9867c478bd9Sstevel@tonic-gate gettext("Usage:\n%s [-F FSType] [-V] [-m] [special ...]\n" 9877c478bd9Sstevel@tonic-gate "%s [-F FSType] [-V] [-y|Y|n|N]" 9887c478bd9Sstevel@tonic-gate " [-o specific_options] [special ...]\n"), 9897c478bd9Sstevel@tonic-gate myname, myname); 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate exit(1); 9927c478bd9Sstevel@tonic-gate } 993