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 524da5b34Srie * Common Development and Distribution License (the "License"). 624da5b34Srie * 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*65908c77Syu, larry liu - Sun Microsystems - Beijing China * Copyright 2009 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 #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <errno.h> 317c478bd9Sstevel@tonic-gate #include <limits.h> 327c478bd9Sstevel@tonic-gate #include <fcntl.h> 337c478bd9Sstevel@tonic-gate #include <string.h> 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/stat.h> 367c478bd9Sstevel@tonic-gate #include <sys/wait.h> 377c478bd9Sstevel@tonic-gate #include <sys/vfstab.h> 387c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 39*65908c77Syu, larry liu - Sun Microsystems - Beijing China #include <sys/sysmacros.h> 407c478bd9Sstevel@tonic-gate #include <locale.h> 417c478bd9Sstevel@tonic-gate #include <libintl.h> 42*65908c77Syu, larry liu - Sun Microsystems - Beijing China #include <sys/dkio.h> 437c478bd9Sstevel@tonic-gate 44*65908c77Syu, larry liu - Sun Microsystems - Beijing China #define DEV_BSIZE 512 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; 220*65908c77Syu, larry liu - Sun Microsystems - Beijing China int devfd; 2217c478bd9Sstevel@tonic-gate struct vfstab vget, vref; 222*65908c77Syu, larry liu - Sun Microsystems - Beijing China struct dk_minfo dkminfo; 2237c478bd9Sstevel@tonic-gate int preencnt = 0; 2247c478bd9Sstevel@tonic-gate struct devlist *dp, *devs = NULL; 2257c478bd9Sstevel@tonic-gate int status; 226*65908c77Syu, larry liu - Sun Microsystems - Beijing China uint_t lbs; 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; 259355d6bb5Sswilcox 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 } 414*65908c77Syu, larry liu - Sun Microsystems - Beijing China 4157c478bd9Sstevel@tonic-gate while (optind < argc) { 4167c478bd9Sstevel@tonic-gate /* 4177c478bd9Sstevel@tonic-gate * If "-F FStype" is specified, use that fs type. 4187c478bd9Sstevel@tonic-gate * Otherwise, determine the fs type from /etc/vfstab 4197c478bd9Sstevel@tonic-gate * if the entry exists. Otherwise, determine the 4207c478bd9Sstevel@tonic-gate * local or remote fs type from /etc/default/df 4217c478bd9Sstevel@tonic-gate * or /etc/dfs/fstypes respectively. 4227c478bd9Sstevel@tonic-gate */ 4237c478bd9Sstevel@tonic-gate if (fstype == NULL) { 4247c478bd9Sstevel@tonic-gate if ((argc > 3) && (sanity)) { 4257c478bd9Sstevel@tonic-gate usage(); 4267c478bd9Sstevel@tonic-gate } 4277c478bd9Sstevel@tonic-gate /* must check for both special && raw devices */ 4287c478bd9Sstevel@tonic-gate vfsnull(&vref); 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate /* 4317c478bd9Sstevel@tonic-gate * Find the vfstab entry for this device. 4327c478bd9Sstevel@tonic-gate * arg_hint tells us what to try to match, 4337c478bd9Sstevel@tonic-gate * based on the type of the last arg. If 4347c478bd9Sstevel@tonic-gate * arg_hint equals UNKNOWN, then we're not 4357c478bd9Sstevel@tonic-gate * sure of the type and need to fallthrough 4367c478bd9Sstevel@tonic-gate * all 3 possibilities for vfstab lookup. 4377c478bd9Sstevel@tonic-gate * Try it as a mountpt first, since that's 4387c478bd9Sstevel@tonic-gate * what mountall gives us. 4397c478bd9Sstevel@tonic-gate */ 4407c478bd9Sstevel@tonic-gate try_again: 4417c478bd9Sstevel@tonic-gate switch (arg_hint) { 4427c478bd9Sstevel@tonic-gate case UNKNOWN: 4437c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate case MOUNTPT: 4467c478bd9Sstevel@tonic-gate vref.vfs_mountp = argv[optind]; 4477c478bd9Sstevel@tonic-gate if ((ret = mygetvfsany(fd, &vget, 4487c478bd9Sstevel@tonic-gate &vref)) == -1 || 4497c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate vref.vfs_mountp = NULL; 4527c478bd9Sstevel@tonic-gate rewind(fd); 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate if (arg_hint == MOUNTPT) { 4557c478bd9Sstevel@tonic-gate arg_hint = UNKNOWN; 4567c478bd9Sstevel@tonic-gate goto try_again; 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 4597c478bd9Sstevel@tonic-gate } else { 4607c478bd9Sstevel@tonic-gate /* Found it */ 4617c478bd9Sstevel@tonic-gate if (vget.vfs_fsckdev != NULL) { 4627c478bd9Sstevel@tonic-gate argv[optind] = 4637c478bd9Sstevel@tonic-gate vget.vfs_fsckdev; 4647c478bd9Sstevel@tonic-gate } 4657c478bd9Sstevel@tonic-gate arg_hint = MOUNTPT; 4667c478bd9Sstevel@tonic-gate break; 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate case FSCKDEV: 4707c478bd9Sstevel@tonic-gate vref.vfs_fsckdev = argv[optind]; 471*65908c77Syu, larry liu - Sun Microsystems - Beijing China 472*65908c77Syu, larry liu - Sun Microsystems - Beijing China /* 473*65908c77Syu, larry liu - Sun Microsystems - Beijing China * Check the media sector size 474*65908c77Syu, larry liu - Sun Microsystems - Beijing China */ 475*65908c77Syu, larry liu - Sun Microsystems - Beijing China if (((devfd = open(vref.vfs_fsckdev, 476*65908c77Syu, larry liu - Sun Microsystems - Beijing China O_RDWR)) >= 0) && (ioctl(devfd, 477*65908c77Syu, larry liu - Sun Microsystems - Beijing China DKIOCGMEDIAINFO, &dkminfo) != 478*65908c77Syu, larry liu - Sun Microsystems - Beijing China -1)) { 479*65908c77Syu, larry liu - Sun Microsystems - Beijing China lbs = dkminfo.dki_lbsize; 480*65908c77Syu, larry liu - Sun Microsystems - Beijing China if (lbs != 0 && ISP2(lbs / 481*65908c77Syu, larry liu - Sun Microsystems - Beijing China DEV_BSIZE) && 482*65908c77Syu, larry liu - Sun Microsystems - Beijing China lbs != DEV_BSIZE) { 483*65908c77Syu, larry liu - Sun Microsystems - Beijing China fprintf(stderr, 484*65908c77Syu, larry liu - Sun Microsystems - Beijing China gettext("The device" 485*65908c77Syu, larry liu - Sun Microsystems - Beijing China " sector size is" 486*65908c77Syu, larry liu - Sun Microsystems - Beijing China " not supported by" 487*65908c77Syu, larry liu - Sun Microsystems - Beijing China " fsck\n")); 488*65908c77Syu, larry liu - Sun Microsystems - Beijing China (void) close(devfd); 489*65908c77Syu, larry liu - Sun Microsystems - Beijing China exit(1); 490*65908c77Syu, larry liu - Sun Microsystems - Beijing China } 491*65908c77Syu, larry liu - Sun Microsystems - Beijing China } 492*65908c77Syu, larry liu - Sun Microsystems - Beijing China 493*65908c77Syu, larry liu - Sun Microsystems - Beijing China if (devfd >= 0) { 494*65908c77Syu, larry liu - Sun Microsystems - Beijing China (void) close(devfd); 495*65908c77Syu, larry liu - Sun Microsystems - Beijing China } 496*65908c77Syu, larry liu - Sun Microsystems - Beijing China 4977c478bd9Sstevel@tonic-gate if ((ret = mygetvfsany(fd, &vget, 4987c478bd9Sstevel@tonic-gate &vref)) == -1 || 4997c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate vref.vfs_fsckdev = NULL; 5027c478bd9Sstevel@tonic-gate rewind(fd); 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate if (arg_hint == FSCKDEV) { 5057c478bd9Sstevel@tonic-gate arg_hint = UNKNOWN; 5067c478bd9Sstevel@tonic-gate goto try_again; 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 5097c478bd9Sstevel@tonic-gate } else { 5107c478bd9Sstevel@tonic-gate /* Found it */ 5117c478bd9Sstevel@tonic-gate arg_hint = FSCKDEV; 5127c478bd9Sstevel@tonic-gate break; 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate case SPECIAL: 5167c478bd9Sstevel@tonic-gate vref.vfs_special = argv[optind]; 5177c478bd9Sstevel@tonic-gate if ((ret = mygetvfsany(fd, &vget, 5187c478bd9Sstevel@tonic-gate &vref)) == -1 || 5197c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate vref.vfs_special = NULL; 5227c478bd9Sstevel@tonic-gate rewind(fd); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate if (arg_hint == SPECIAL) { 5257c478bd9Sstevel@tonic-gate arg_hint = UNKNOWN; 5267c478bd9Sstevel@tonic-gate goto try_again; 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 5297c478bd9Sstevel@tonic-gate } else { 5307c478bd9Sstevel@tonic-gate /* Found it */ 5317c478bd9Sstevel@tonic-gate arg_hint = SPECIAL; 5327c478bd9Sstevel@tonic-gate break; 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate if (ret == 0 && vget.vfs_fstype) { 5377c478bd9Sstevel@tonic-gate if ((pflg) && (strcmp(vget.vfs_fstype, 5387c478bd9Sstevel@tonic-gate MNTTYPE_UFS) == 0) && (preen_addev( 5397c478bd9Sstevel@tonic-gate vget.vfs_fsckdev) == 0)) { 5407c478bd9Sstevel@tonic-gate preencnt++; 5417c478bd9Sstevel@tonic-gate dp = newdev(&vget); 5427c478bd9Sstevel@tonic-gate dp->nxt = devs; 5437c478bd9Sstevel@tonic-gate devs = dp; 5447c478bd9Sstevel@tonic-gate } else { 5457c478bd9Sstevel@tonic-gate status = execute(argv[optind], 5467c478bd9Sstevel@tonic-gate vget.vfs_fstype, Vflg, fd); 5477c478bd9Sstevel@tonic-gate if (status > exitstat) 5487c478bd9Sstevel@tonic-gate exitstat = status; 5497c478bd9Sstevel@tonic-gate } 5507c478bd9Sstevel@tonic-gate } else if (ret == -1 || 5517c478bd9Sstevel@tonic-gate vget.vfs_fstype == NULL) { 5527c478bd9Sstevel@tonic-gate fstype = 5537c478bd9Sstevel@tonic-gate default_fstype(argv[optind]); 5547c478bd9Sstevel@tonic-gate status = execute(argv[optind], fstype, 5557c478bd9Sstevel@tonic-gate Vflg, fd); 5567c478bd9Sstevel@tonic-gate /* return the highest exit code */ 5577c478bd9Sstevel@tonic-gate if (status > exitstat) 5587c478bd9Sstevel@tonic-gate exitstat = status; 5597c478bd9Sstevel@tonic-gate } else 5607c478bd9Sstevel@tonic-gate vfserror(ret); 5617c478bd9Sstevel@tonic-gate } else { 5627c478bd9Sstevel@tonic-gate status = execute(argv[optind], fstype, 5637c478bd9Sstevel@tonic-gate Vflg, NULL); 5647c478bd9Sstevel@tonic-gate /* return the highest exit code */ 5657c478bd9Sstevel@tonic-gate if (status > exitstat) 5667c478bd9Sstevel@tonic-gate exitstat = status; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate optind++; 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate if (fd != NULL) 5717c478bd9Sstevel@tonic-gate fclose(fd); 5727c478bd9Sstevel@tonic-gate if ((pflg) && (exitstat == 0)) { 5737c478bd9Sstevel@tonic-gate fsck_dopreen(&devs, preencnt); 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate } 57608190127Sdh return (exitstat); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate 57908190127Sdh static void 58008190127Sdh fsck_dopreen(struct devlist **devp, int ndevs) 5817c478bd9Sstevel@tonic-gate { 5827c478bd9Sstevel@tonic-gate char name[1024]; 5837c478bd9Sstevel@tonic-gate int rc; 58408190127Sdh int i; 5857c478bd9Sstevel@tonic-gate struct devlist *bl, *bdp; 5867c478bd9Sstevel@tonic-gate struct devlist *badlist; 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate bl = badlist = NULL; 5897c478bd9Sstevel@tonic-gate while (ndevs > 0) { 5907c478bd9Sstevel@tonic-gate if (nrun > maxrun) 5917c478bd9Sstevel@tonic-gate waiter(&bl, &badlist); 5927c478bd9Sstevel@tonic-gate rc = preen_getdev(name); 5937c478bd9Sstevel@tonic-gate switch (rc) { 5947c478bd9Sstevel@tonic-gate case 0: 5957c478bd9Sstevel@tonic-gate break; 5967c478bd9Sstevel@tonic-gate case 1: 5977c478bd9Sstevel@tonic-gate bdp = getdev(name, devp); 5987c478bd9Sstevel@tonic-gate if (bdp == NULL) { 5997c478bd9Sstevel@tonic-gate fprintf(stderr, 6007c478bd9Sstevel@tonic-gate gettext("%s: unknown dev: `%s'\n"), 6017c478bd9Sstevel@tonic-gate myname, name); 6027c478bd9Sstevel@tonic-gate exit(1); 6037c478bd9Sstevel@tonic-gate } 6047c478bd9Sstevel@tonic-gate bdp->nxt = bl; 6057c478bd9Sstevel@tonic-gate bl = bdp; 6067c478bd9Sstevel@tonic-gate startdisk(bdp); 6077c478bd9Sstevel@tonic-gate ndevs--; 6087c478bd9Sstevel@tonic-gate break; 6097c478bd9Sstevel@tonic-gate case 2: 6107c478bd9Sstevel@tonic-gate waiter(&bl, &badlist); 6117c478bd9Sstevel@tonic-gate break; 6127c478bd9Sstevel@tonic-gate default: 6137c478bd9Sstevel@tonic-gate fprintf(stderr, 6147c478bd9Sstevel@tonic-gate gettext("%s: bad return `%d' from preen_getdev\n"), 6157c478bd9Sstevel@tonic-gate myname, rc); 6167c478bd9Sstevel@tonic-gate break; 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate while (bl != NULL) { 6207c478bd9Sstevel@tonic-gate waiter(&bl, &badlist); 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate if (badlist != NULL) 6247c478bd9Sstevel@tonic-gate print_badlist(badlist); 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate 62708190127Sdh static void 62808190127Sdh startdisk(struct devlist *dp) 6297c478bd9Sstevel@tonic-gate { 6307c478bd9Sstevel@tonic-gate pid_t pid; 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate nrun++; 6337c478bd9Sstevel@tonic-gate if ((pid = fork()) == -1) { 6347c478bd9Sstevel@tonic-gate perror("fork"); 6357c478bd9Sstevel@tonic-gate exit(1); 6367c478bd9Sstevel@tonic-gate } else if (pid == 0) { 6377c478bd9Sstevel@tonic-gate exitstat = execute(dp->name, MNTTYPE_UFS, Vflg, NULL); 6387c478bd9Sstevel@tonic-gate exit(exitstat); 6397c478bd9Sstevel@tonic-gate } else { 6407c478bd9Sstevel@tonic-gate dp->pid = pid; 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate } 6437c478bd9Sstevel@tonic-gate 64408190127Sdh static void 64508190127Sdh waiter(struct devlist **blp, struct devlist **badlist) 6467c478bd9Sstevel@tonic-gate { 6477c478bd9Sstevel@tonic-gate pid_t curpid; 6487c478bd9Sstevel@tonic-gate int status; 64908190127Sdh struct devlist *bdp, *pbdp; 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate curpid = wait(&status); 6527c478bd9Sstevel@tonic-gate if (curpid == -1) { 6537c478bd9Sstevel@tonic-gate perror("wait"); 6547c478bd9Sstevel@tonic-gate exit(1); 6557c478bd9Sstevel@tonic-gate } 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate for (pbdp = NULL, bdp = *blp; bdp != NULL; pbdp = bdp, bdp = bdp->nxt) { 6587c478bd9Sstevel@tonic-gate if (bdp->pid == curpid) { 6597c478bd9Sstevel@tonic-gate break; 6607c478bd9Sstevel@tonic-gate } 6617c478bd9Sstevel@tonic-gate } 6627c478bd9Sstevel@tonic-gate if (bdp == NULL) 6637c478bd9Sstevel@tonic-gate return; 6647c478bd9Sstevel@tonic-gate nrun--; 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate if (pbdp) 6677c478bd9Sstevel@tonic-gate pbdp->nxt = bdp->nxt; 6687c478bd9Sstevel@tonic-gate else 6697c478bd9Sstevel@tonic-gate *blp = bdp->nxt; 6707c478bd9Sstevel@tonic-gate preen_releasedev(bdp->name); 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate if (WTERMSIG(status)) { 6737c478bd9Sstevel@tonic-gate printf(gettext("%s (%s): EXITED WITH SIGNAL %d\n"), 6747c478bd9Sstevel@tonic-gate bdp->name, bdp->fsname, WTERMSIG(status)); 6757c478bd9Sstevel@tonic-gate status = status&0377 | 8<<8; 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate if (WHIBYTE(status) != 0) { 6787c478bd9Sstevel@tonic-gate if (WHIBYTE(status) > exitstat) 6797c478bd9Sstevel@tonic-gate exitstat = WHIBYTE(status); 6807c478bd9Sstevel@tonic-gate while (*badlist != NULL) 6817c478bd9Sstevel@tonic-gate badlist = &(*badlist)->nxt; 6827c478bd9Sstevel@tonic-gate *badlist = bdp; 6837c478bd9Sstevel@tonic-gate bdp->nxt = NULL; 6847c478bd9Sstevel@tonic-gate } 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate 68708190127Sdh static void 68808190127Sdh print_badlist(struct devlist *lp) 6897c478bd9Sstevel@tonic-gate { 6907c478bd9Sstevel@tonic-gate int x, len; 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate printf( 6937c478bd9Sstevel@tonic-gate gettext("\nTHE FOLLOWING FILE SYSTEM(S) HAD AN UNEXPECTED INCONSISTENCY:")); 6947c478bd9Sstevel@tonic-gate for (x = 3; lp != NULL; lp = lp->nxt) { 6957c478bd9Sstevel@tonic-gate len = strlen(lp->name) + strlen(lp->fsname) + 5; 6967c478bd9Sstevel@tonic-gate x += len; 6977c478bd9Sstevel@tonic-gate if (x >= 80) { 6987c478bd9Sstevel@tonic-gate printf("\n "); 6997c478bd9Sstevel@tonic-gate x = len + 3; 7007c478bd9Sstevel@tonic-gate } else { 7017c478bd9Sstevel@tonic-gate printf(" "); 7027c478bd9Sstevel@tonic-gate } 7037c478bd9Sstevel@tonic-gate printf("%s (%s)%s", lp->name, lp->fsname, 7047c478bd9Sstevel@tonic-gate lp->nxt ? "," : "\n"); 7057c478bd9Sstevel@tonic-gate } 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate /* 7097c478bd9Sstevel@tonic-gate * allocate and initialize a `devlist' structure 7107c478bd9Sstevel@tonic-gate */ 7117c478bd9Sstevel@tonic-gate static 7127c478bd9Sstevel@tonic-gate struct devlist * 71308190127Sdh newdev(struct vfstab *vfsp) 7147c478bd9Sstevel@tonic-gate { 7157c478bd9Sstevel@tonic-gate struct devlist *dp; 7167c478bd9Sstevel@tonic-gate extern char *strdup(); 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate dp = (struct devlist *)malloc(sizeof (struct devlist)); 7197c478bd9Sstevel@tonic-gate if (dp == NULL) { 7207c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: out of memory\n"), myname); 7217c478bd9Sstevel@tonic-gate exit(1); 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate dp->name = strdup(vfsp->vfs_fsckdev); 7247c478bd9Sstevel@tonic-gate dp->fsname = strdup(vfsp->vfs_mountp); 7257c478bd9Sstevel@tonic-gate if (dp->name == NULL || dp->fsname == NULL) { 7267c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: out of memory\n"), myname); 7277c478bd9Sstevel@tonic-gate exit(1); 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate return (dp); 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate /* 7337c478bd9Sstevel@tonic-gate * locate the devlist structure in the given list that matches `name'. 7347c478bd9Sstevel@tonic-gate * If found, the structure is removed from the list, and a pointer to 7357c478bd9Sstevel@tonic-gate * it is returned. If not, NULL is returned. 7367c478bd9Sstevel@tonic-gate */ 7377c478bd9Sstevel@tonic-gate static 7387c478bd9Sstevel@tonic-gate struct devlist * 73908190127Sdh getdev(char *name, struct devlist **list) 7407c478bd9Sstevel@tonic-gate { 74108190127Sdh struct devlist *p, *lp; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate for (lp = NULL, p = *list; p != NULL; lp = p, p = p->nxt) { 7447c478bd9Sstevel@tonic-gate if (strcmp(p->name, name) == 0) 7457c478bd9Sstevel@tonic-gate break; 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate if (p != NULL) { 7497c478bd9Sstevel@tonic-gate if (lp != NULL) 7507c478bd9Sstevel@tonic-gate lp->nxt = p->nxt; 7517c478bd9Sstevel@tonic-gate else 7527c478bd9Sstevel@tonic-gate *list = p->nxt; 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate return (p); 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate /* see if all numbers */ 75808190127Sdh int 75908190127Sdh numbers(char *yp) 7607c478bd9Sstevel@tonic-gate { 7617c478bd9Sstevel@tonic-gate if (yp == NULL) 7627c478bd9Sstevel@tonic-gate return (0); 7637c478bd9Sstevel@tonic-gate while ('0' <= *yp && *yp <= '9') 7647c478bd9Sstevel@tonic-gate yp++; 7657c478bd9Sstevel@tonic-gate if (*yp) 7667c478bd9Sstevel@tonic-gate return (0); 7677c478bd9Sstevel@tonic-gate return (1); 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate 77008190127Sdh int 77108190127Sdh execute(char *fsckdev, char *fstype, int Vflg, FILE *fd) 7727c478bd9Sstevel@tonic-gate { 7737c478bd9Sstevel@tonic-gate int st; 7747c478bd9Sstevel@tonic-gate pid_t fk; 7757c478bd9Sstevel@tonic-gate char full_path[PATH_MAX]; 7767c478bd9Sstevel@tonic-gate char *vfs_path = VFS_PATH; 7777c478bd9Sstevel@tonic-gate int status = 0; 7787c478bd9Sstevel@tonic-gate 7797c478bd9Sstevel@tonic-gate nargv[nargc] = fsckdev; 7807c478bd9Sstevel@tonic-gate 7817c478bd9Sstevel@tonic-gate if (Vflg) { 7827c478bd9Sstevel@tonic-gate prnt_cmd(stdout, fstype); 7837c478bd9Sstevel@tonic-gate return (0); 7847c478bd9Sstevel@tonic-gate } 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate if (fd) 7877c478bd9Sstevel@tonic-gate fcntl(fileno(fd), F_SETFD, 1); /* close on exec */ 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate if ((fk = fork()) == (pid_t)-1) { 7907c478bd9Sstevel@tonic-gate fprintf(stderr, 7917c478bd9Sstevel@tonic-gate gettext("%s: cannot fork. Try again later\n"), 7927c478bd9Sstevel@tonic-gate myname); 7937c478bd9Sstevel@tonic-gate perror(myname); 7947c478bd9Sstevel@tonic-gate exit(1); 7957c478bd9Sstevel@tonic-gate } 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate if (fk == 0) { 7987c478bd9Sstevel@tonic-gate /* Try to exec the fstype dependent portion of the fsck. */ 7997c478bd9Sstevel@tonic-gate do_exec(fstype, nargv); 8007c478bd9Sstevel@tonic-gate } else { 8017c478bd9Sstevel@tonic-gate /* parent waits for child */ 8027c478bd9Sstevel@tonic-gate if (wait(&st) == (pid_t)-1) { 8037c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: bad wait\n"), myname); 8047c478bd9Sstevel@tonic-gate perror(myname); 8057c478bd9Sstevel@tonic-gate exit(1); 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate if ((st & 0xff) == 0x7f) { 8097c478bd9Sstevel@tonic-gate fprintf(stderr, 8107c478bd9Sstevel@tonic-gate gettext("%s: warning: the following command" 8117c478bd9Sstevel@tonic-gate " (process %d) was stopped by signal %d\n"), 8127c478bd9Sstevel@tonic-gate myname, fk, (st >> 8) & 0xff); 8137c478bd9Sstevel@tonic-gate prnt_cmd(stderr, fstype); 8147c478bd9Sstevel@tonic-gate status = ((st >> 8) & 0xff) | 0x80; 8157c478bd9Sstevel@tonic-gate } else if (st & 0xff) { 8167c478bd9Sstevel@tonic-gate if (st & 0x80) 8177c478bd9Sstevel@tonic-gate fprintf(stderr, 8187c478bd9Sstevel@tonic-gate gettext("%s: warning: the following command" 8197c478bd9Sstevel@tonic-gate " (process %d) was terminated by signal %d" 8207c478bd9Sstevel@tonic-gate " and dumped core\n"), 8217c478bd9Sstevel@tonic-gate myname, fk, st & 0x7f); 8227c478bd9Sstevel@tonic-gate else 8237c478bd9Sstevel@tonic-gate fprintf(stderr, 8247c478bd9Sstevel@tonic-gate gettext("%s: warning: the following command" 8257c478bd9Sstevel@tonic-gate " (process %d) was terminated by signal %d\n"), 8267c478bd9Sstevel@tonic-gate myname, fk, st & 0x7f); 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate prnt_cmd(stderr, fstype); 8297c478bd9Sstevel@tonic-gate status = ((st & 0xff) | 0x80); 8307c478bd9Sstevel@tonic-gate } else if (st & 0xff00) 8317c478bd9Sstevel@tonic-gate status = (st >> 8) & 0xff; 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate return (status); 8357c478bd9Sstevel@tonic-gate } 8367c478bd9Sstevel@tonic-gate 83708190127Sdh static void 83808190127Sdh do_exec(char *fstype, char *nargv[]) 8397c478bd9Sstevel@tonic-gate { 8407c478bd9Sstevel@tonic-gate char full_path[PATH_MAX]; 8417c478bd9Sstevel@tonic-gate char *vfs_path = VFS_PATH; 8427c478bd9Sstevel@tonic-gate 843355d6bb5Sswilcox if (strlen(fstype) > (size_t)FSTYPE_MAX) { 8447c478bd9Sstevel@tonic-gate fprintf(stderr, 8457c478bd9Sstevel@tonic-gate gettext("%s: Fstype %s exceeds %d characters\n"), 8467c478bd9Sstevel@tonic-gate myname, fstype, FSTYPE_MAX); 8477c478bd9Sstevel@tonic-gate exit(1); 8487c478bd9Sstevel@tonic-gate } 8497c478bd9Sstevel@tonic-gate /* build the full pathname of the fstype dependent command. */ 8507c478bd9Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", vfs_path, fstype, myname); 8517c478bd9Sstevel@tonic-gate 8527c478bd9Sstevel@tonic-gate /* set the new argv[0] to the filename */ 8537c478bd9Sstevel@tonic-gate nargv[1] = myname; 8547c478bd9Sstevel@tonic-gate /* Try to exec the fstype dependent portion of the fsck. */ 8557c478bd9Sstevel@tonic-gate execv(full_path, &nargv[1]); 8567c478bd9Sstevel@tonic-gate if (errno == EACCES) { 8577c478bd9Sstevel@tonic-gate fprintf(stderr, 8587c478bd9Sstevel@tonic-gate gettext("%s: cannot execute %s - permission denied\n"), 8597c478bd9Sstevel@tonic-gate myname, full_path); 8607c478bd9Sstevel@tonic-gate } 8617c478bd9Sstevel@tonic-gate if (errno == ENOEXEC) { 8627c478bd9Sstevel@tonic-gate nargv[0] = "sh"; 8637c478bd9Sstevel@tonic-gate nargv[1] = full_path; 8647c478bd9Sstevel@tonic-gate execv("/sbin/sh", &nargv[0]); 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate /* second path to try */ 8677c478bd9Sstevel@tonic-gate vfs_path = VFS_PATH2; 8687c478bd9Sstevel@tonic-gate /* build the full pathname of the fstype dependent command. */ 8697c478bd9Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", vfs_path, fstype, myname); 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate /* set the new argv[0] to the filename */ 8727c478bd9Sstevel@tonic-gate nargv[1] = myname; 8737c478bd9Sstevel@tonic-gate /* Try to exec the second fstype dependent portion of the fsck. */ 8747c478bd9Sstevel@tonic-gate execv(full_path, &nargv[1]); 8757c478bd9Sstevel@tonic-gate if (errno == EACCES) { 8767c478bd9Sstevel@tonic-gate fprintf(stderr, 8777c478bd9Sstevel@tonic-gate gettext("%s: cannot execute %s - permission denied\n"), 8787c478bd9Sstevel@tonic-gate myname, full_path); 8797c478bd9Sstevel@tonic-gate exit(1); 8807c478bd9Sstevel@tonic-gate } 8817c478bd9Sstevel@tonic-gate if (errno == ENOEXEC) { 8827c478bd9Sstevel@tonic-gate nargv[0] = "sh"; 8837c478bd9Sstevel@tonic-gate nargv[1] = full_path; 8847c478bd9Sstevel@tonic-gate execv("/sbin/sh", &nargv[0]); 8857c478bd9Sstevel@tonic-gate } 8867c478bd9Sstevel@tonic-gate fprintf(stderr, 8877c478bd9Sstevel@tonic-gate gettext("%s: operation not applicable to FSType %s\n"), 8887c478bd9Sstevel@tonic-gate myname, fstype); 8897c478bd9Sstevel@tonic-gate exit(1); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate 89208190127Sdh static void 89308190127Sdh prnt_cmd(FILE *fd, char *fstype) 8947c478bd9Sstevel@tonic-gate { 8957c478bd9Sstevel@tonic-gate char **argp; 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate fprintf(fd, "%s -F %s", myname, fstype); 8987c478bd9Sstevel@tonic-gate for (argp = &nargv[2]; *argp; argp++) 8997c478bd9Sstevel@tonic-gate fprintf(fd, " %s", *argp); 9007c478bd9Sstevel@tonic-gate fprintf(fd, "\n"); 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate 90308190127Sdh static void 90408190127Sdh vfserror(int flag) 9057c478bd9Sstevel@tonic-gate { 9067c478bd9Sstevel@tonic-gate switch (flag) { 9077c478bd9Sstevel@tonic-gate case VFS_TOOLONG: 9087c478bd9Sstevel@tonic-gate fprintf(stderr, 9097c478bd9Sstevel@tonic-gate gettext("%s: line in vfstab exceeds %d characters\n"), 9107c478bd9Sstevel@tonic-gate myname, VFS_LINE_MAX-2); 9117c478bd9Sstevel@tonic-gate break; 9127c478bd9Sstevel@tonic-gate case VFS_TOOFEW: 9137c478bd9Sstevel@tonic-gate fprintf(stderr, 9147c478bd9Sstevel@tonic-gate gettext("%s: line in vfstab has too few entries\n"), 9157c478bd9Sstevel@tonic-gate myname); 9167c478bd9Sstevel@tonic-gate break; 9177c478bd9Sstevel@tonic-gate case VFS_TOOMANY: 9187c478bd9Sstevel@tonic-gate fprintf(stderr, 9197c478bd9Sstevel@tonic-gate gettext("%s: line in vfstab has too many entries\n"), 9207c478bd9Sstevel@tonic-gate myname); 9217c478bd9Sstevel@tonic-gate break; 9227c478bd9Sstevel@tonic-gate } 9237c478bd9Sstevel@tonic-gate exit(1); 9247c478bd9Sstevel@tonic-gate } 9257c478bd9Sstevel@tonic-gate 92608190127Sdh static void 92708190127Sdh usage(void) 9287c478bd9Sstevel@tonic-gate { 9297c478bd9Sstevel@tonic-gate fprintf(stderr, 9307c478bd9Sstevel@tonic-gate gettext("Usage:\n%s [-F FSType] [-V] [-m] [special ...]\n" 9317c478bd9Sstevel@tonic-gate "%s [-F FSType] [-V] [-y|Y|n|N]" 9327c478bd9Sstevel@tonic-gate " [-o specific_options] [special ...]\n"), 9337c478bd9Sstevel@tonic-gate myname, myname); 9347c478bd9Sstevel@tonic-gate 9357c478bd9Sstevel@tonic-gate exit(1); 9367c478bd9Sstevel@tonic-gate } 937