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