1 1.53 mlelstv /* $NetBSD: fsck.c,v 1.53 2023/01/24 08:09:37 mlelstv Exp $ */ 2 1.1 christos 3 1.1 christos /* 4 1.33 christos * Copyright (c) 1996 Christos Zoulas. All rights reserved. 5 1.1 christos * Copyright (c) 1980, 1989, 1993, 1994 6 1.1 christos * The Regents of the University of California. All rights reserved. 7 1.1 christos * 8 1.1 christos * Redistribution and use in source and binary forms, with or without 9 1.1 christos * modification, are permitted provided that the following conditions 10 1.1 christos * are met: 11 1.1 christos * 1. Redistributions of source code must retain the above copyright 12 1.1 christos * notice, this list of conditions and the following disclaimer. 13 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 14 1.1 christos * notice, this list of conditions and the following disclaimer in the 15 1.1 christos * documentation and/or other materials provided with the distribution. 16 1.30 agc * 3. Neither the name of the University nor the names of its contributors 17 1.30 agc * may be used to endorse or promote products derived from this software 18 1.30 agc * without specific prior written permission. 19 1.30 agc * 20 1.30 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 1.30 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 1.30 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 1.30 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 1.30 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 1.30 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 1.30 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 1.30 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 1.30 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 1.30 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 1.30 agc * SUCH DAMAGE. 31 1.30 agc * 32 1.30 agc * From: @(#)mount.c 8.19 (Berkeley) 4/19/94 33 1.30 agc * From: NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp 34 1.30 agc * 35 1.30 agc */ 36 1.30 agc 37 1.12 lukem #include <sys/cdefs.h> 38 1.12 lukem #ifndef lint 39 1.53 mlelstv __RCSID("$NetBSD: fsck.c,v 1.53 2023/01/24 08:09:37 mlelstv Exp $"); 40 1.12 lukem #endif /* not lint */ 41 1.1 christos 42 1.1 christos #include <sys/param.h> 43 1.1 christos #include <sys/mount.h> 44 1.1 christos #include <sys/queue.h> 45 1.1 christos #include <sys/wait.h> 46 1.20 christos #define FSTYPENAMES 47 1.20 christos #define FSCKNAMES 48 1.36 thorpej #include <sys/disk.h> 49 1.8 christos #include <sys/disklabel.h> 50 1.8 christos #include <sys/ioctl.h> 51 1.1 christos 52 1.1 christos #include <err.h> 53 1.1 christos #include <errno.h> 54 1.1 christos #include <fstab.h> 55 1.8 christos #include <fcntl.h> 56 1.21 abs #include <paths.h> 57 1.1 christos #include <signal.h> 58 1.1 christos #include <stdio.h> 59 1.1 christos #include <stdlib.h> 60 1.1 christos #include <string.h> 61 1.1 christos #include <unistd.h> 62 1.43 christos #include <util.h> 63 1.1 christos 64 1.1 christos #include "pathnames.h" 65 1.4 christos #include "fsutil.h" 66 1.47 christos #include "exitvalues.h" 67 1.1 christos 68 1.2 christos static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST; 69 1.1 christos 70 1.48 christos TAILQ_HEAD(fstypelist, entry) opthead, selhead, omhead; 71 1.1 christos 72 1.1 christos struct entry { 73 1.1 christos char *type; 74 1.2 christos char *options; 75 1.1 christos TAILQ_ENTRY(entry) entries; 76 1.1 christos }; 77 1.1 christos 78 1.4 christos static int maxrun = 0; 79 1.2 christos static char *options = NULL; 80 1.4 christos static int flags = 0; 81 1.2 christos 82 1.25 lukem static int checkfs(const char *, const char *, const char *, void *, pid_t *); 83 1.25 lukem static int selected(const char *); 84 1.48 christos static int omitted(const char *); 85 1.25 lukem static void addoption(char *); 86 1.25 lukem static const char *getoptions(const char *); 87 1.25 lukem static void addentry(struct fstypelist *, const char *, const char *); 88 1.25 lukem static void maketypelist(char *); 89 1.25 lukem static void catopt(char **, const char *); 90 1.44 christos static void mangle(char *, int *, const char ** volatile *, int *); 91 1.25 lukem static const char *getfslab(const char *); 92 1.50 joerg __dead static void usage(void); 93 1.25 lukem static void *isok(struct fstab *); 94 1.1 christos 95 1.1 christos int 96 1.25 lukem main(int argc, char *argv[]) 97 1.1 christos { 98 1.1 christos struct fstab *fs; 99 1.47 christos int i, rval; 100 1.17 mycroft const char *vfstype = NULL; 101 1.7 christos char globopt[3]; 102 1.47 christos int ret = FSCK_EXIT_OK; 103 1.51 christos char buf[MAXPATHLEN]; 104 1.7 christos 105 1.7 christos globopt[0] = '-'; 106 1.7 christos globopt[2] = '\0'; 107 1.1 christos 108 1.2 christos TAILQ_INIT(&selhead); 109 1.2 christos TAILQ_INIT(&opthead); 110 1.48 christos TAILQ_INIT(&omhead); 111 1.2 christos 112 1.48 christos while ((i = getopt(argc, argv, "dfl:nPpqT:t:vx:y")) != -1) { 113 1.1 christos switch (i) { 114 1.1 christos case 'd': 115 1.4 christos flags |= CHECK_DEBUG; 116 1.31 dsl continue; 117 1.31 dsl 118 1.31 dsl case 'f': 119 1.31 dsl flags |= CHECK_FORCE; 120 1.1 christos break; 121 1.1 christos 122 1.31 dsl case 'n': 123 1.38 christos flags |= CHECK_NOFIX; 124 1.1 christos break; 125 1.1 christos 126 1.7 christos case 'p': 127 1.31 dsl flags |= CHECK_PREEN; 128 1.31 dsl break; 129 1.31 dsl 130 1.37 christos case 'P': 131 1.37 christos flags |= CHECK_PROGRESS; 132 1.37 christos break; 133 1.37 christos 134 1.31 dsl case 'q': 135 1.2 christos break; 136 1.2 christos 137 1.2 christos case 'l': 138 1.2 christos maxrun = atoi(optarg); 139 1.31 dsl continue; 140 1.1 christos 141 1.2 christos case 'T': 142 1.1 christos if (*optarg) 143 1.2 christos addoption(optarg); 144 1.31 dsl continue; 145 1.1 christos 146 1.1 christos case 't': 147 1.24 lukem if (TAILQ_FIRST(&selhead) != NULL) 148 1.1 christos errx(1, "only one -t option may be specified."); 149 1.2 christos 150 1.1 christos maketypelist(optarg); 151 1.1 christos vfstype = optarg; 152 1.31 dsl continue; 153 1.31 dsl 154 1.31 dsl case 'v': 155 1.31 dsl flags |= CHECK_VERBOSE; 156 1.31 dsl continue; 157 1.31 dsl 158 1.48 christos case 'x': 159 1.48 christos addentry(&omhead, optarg, ""); 160 1.49 hannken continue; 161 1.48 christos 162 1.31 dsl case 'y': 163 1.1 christos break; 164 1.1 christos 165 1.1 christos case '?': 166 1.1 christos default: 167 1.1 christos usage(); 168 1.1 christos /* NOTREACHED */ 169 1.1 christos } 170 1.1 christos 171 1.31 dsl /* Pass option to fsck_xxxfs */ 172 1.31 dsl globopt[1] = i; 173 1.31 dsl catopt(&options, globopt); 174 1.31 dsl } 175 1.31 dsl 176 1.37 christos /* Don't do progress meters if we're debugging. */ 177 1.37 christos if (flags & CHECK_DEBUG) 178 1.37 christos flags &= ~CHECK_PROGRESS; 179 1.37 christos 180 1.37 christos /* 181 1.37 christos * If progress meters are being used, force max parallel to 1 182 1.37 christos * so the progress meter outputs don't interfere with one another. 183 1.37 christos */ 184 1.37 christos if (flags & CHECK_PROGRESS) 185 1.37 christos maxrun = 1; 186 1.37 christos 187 1.1 christos argc -= optind; 188 1.1 christos argv += optind; 189 1.1 christos 190 1.2 christos if (argc == 0) 191 1.4 christos return checkfstab(flags, maxrun, isok, checkfs); 192 1.2 christos 193 1.1 christos #define BADTYPE(type) \ 194 1.1 christos (strcmp(type, FSTAB_RO) && \ 195 1.1 christos strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ)) 196 1.1 christos 197 1.1 christos 198 1.1 christos for (; argc--; argv++) { 199 1.52 mlelstv const char *spec, *spec2, *mntpt, *type, *cp; 200 1.21 abs char device[MAXPATHLEN]; 201 1.1 christos 202 1.52 mlelstv spec = mntpt = *argv; 203 1.52 mlelstv spec2 = getfsspecname(buf, sizeof(buf), spec); 204 1.52 mlelstv if (spec2 == NULL) 205 1.52 mlelstv spec2 = spec; 206 1.52 mlelstv 207 1.52 mlelstv cp = strrchr(spec2, '/'); 208 1.21 abs if (cp == 0) { 209 1.21 abs (void)snprintf(device, sizeof(device), "%s%s", 210 1.52 mlelstv _PATH_DEV, spec2); 211 1.52 mlelstv spec2 = device; 212 1.21 abs } 213 1.52 mlelstv 214 1.52 mlelstv fs = getfsfile(spec); 215 1.52 mlelstv if (fs == NULL) 216 1.52 mlelstv fs = getfsspec(spec); 217 1.52 mlelstv if (fs == NULL && spec != spec2) { 218 1.52 mlelstv fs = getfsspec(spec2); 219 1.52 mlelstv spec = spec2; 220 1.1 christos } 221 1.52 mlelstv 222 1.52 mlelstv if (fs) { 223 1.51 christos spec = getfsspecname(buf, sizeof(buf), fs->fs_spec); 224 1.51 christos if (spec == NULL) 225 1.51 christos err(FSCK_EXIT_CHECK_FAILED, "%s", buf); 226 1.1 christos type = fs->fs_vfstype; 227 1.1 christos if (BADTYPE(fs->fs_type)) 228 1.47 christos errx(FSCK_EXIT_CHECK_FAILED, 229 1.47 christos "%s has unknown file system type.", 230 1.21 abs spec); 231 1.52 mlelstv } else { 232 1.52 mlelstv if (vfstype == NULL) 233 1.52 mlelstv vfstype = getfslab(spec); 234 1.52 mlelstv type = vfstype; 235 1.1 christos } 236 1.1 christos 237 1.47 christos rval = checkfs(type, blockcheck(spec), *argv, NULL, NULL); 238 1.47 christos if (rval > ret) 239 1.47 christos ret = rval; 240 1.1 christos } 241 1.1 christos 242 1.47 christos return ret; 243 1.1 christos } 244 1.1 christos 245 1.2 christos 246 1.4 christos static void * 247 1.25 lukem isok(struct fstab *fs) 248 1.2 christos { 249 1.25 lukem 250 1.2 christos if (fs->fs_passno == 0) 251 1.4 christos return NULL; 252 1.2 christos 253 1.2 christos if (BADTYPE(fs->fs_type)) 254 1.4 christos return NULL; 255 1.2 christos 256 1.2 christos if (!selected(fs->fs_vfstype)) 257 1.4 christos return NULL; 258 1.2 christos 259 1.48 christos if (omitted(fs->fs_file)) 260 1.48 christos return NULL; 261 1.48 christos 262 1.4 christos return fs; 263 1.2 christos } 264 1.2 christos 265 1.2 christos 266 1.1 christos static int 267 1.45 christos checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg, 268 1.25 lukem pid_t *pidp) 269 1.1 christos { 270 1.1 christos /* List of directories containing fsck_xxx subcommands. */ 271 1.1 christos static const char *edirs[] = { 272 1.35 christos #ifdef RESCUEDIR 273 1.35 christos RESCUEDIR, 274 1.29 lukem #endif 275 1.1 christos _PATH_SBIN, 276 1.1 christos _PATH_USRSBIN, 277 1.1 christos NULL 278 1.1 christos }; 279 1.44 christos const char ** volatile argv, **edir; 280 1.45 christos const char * volatile vfstype = vfst; 281 1.1 christos pid_t pid; 282 1.15 mycroft int argc, i, status, maxargc; 283 1.45 christos char *optb; 284 1.45 christos char *volatile optbuf; 285 1.45 christos char execname[MAXPATHLEN + 1], execbase[MAXPATHLEN]; 286 1.2 christos const char *extra = getoptions(vfstype); 287 1.1 christos 288 1.15 mycroft if (!strcmp(vfstype, "ufs")) 289 1.3 cgd vfstype = MOUNT_UFS; 290 1.3 cgd 291 1.45 christos optb = NULL; 292 1.16 mycroft if (options) 293 1.45 christos catopt(&optb, options); 294 1.16 mycroft if (extra) 295 1.45 christos catopt(&optb, extra); 296 1.45 christos optbuf = optb; 297 1.2 christos 298 1.15 mycroft maxargc = 64; 299 1.15 mycroft argv = emalloc(sizeof(char *) * maxargc); 300 1.15 mycroft 301 1.15 mycroft (void) snprintf(execbase, sizeof(execbase), "fsck_%s", vfstype); 302 1.15 mycroft argc = 0; 303 1.15 mycroft argv[argc++] = execbase; 304 1.2 christos if (optbuf) 305 1.7 christos mangle(optbuf, &argc, &argv, &maxargc); 306 1.2 christos argv[argc++] = spec; 307 1.7 christos argv[argc] = NULL; 308 1.1 christos 309 1.4 christos if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) { 310 1.8 christos (void)printf("start %s %swait", mntpt, 311 1.8 christos pidp ? "no" : ""); 312 1.8 christos for (i = 0; i < argc; i++) 313 1.1 christos (void)printf(" %s", argv[i]); 314 1.1 christos (void)printf("\n"); 315 1.1 christos } 316 1.1 christos 317 1.1 christos switch (pid = vfork()) { 318 1.1 christos case -1: /* Error. */ 319 1.1 christos warn("vfork"); 320 1.1 christos if (optbuf) 321 1.1 christos free(optbuf); 322 1.42 christos free(argv); 323 1.47 christos return FSCK_EXIT_CHECK_FAILED; 324 1.1 christos 325 1.1 christos case 0: /* Child. */ 326 1.26 lukem if ((flags & CHECK_FORCE) == 0) { 327 1.34 christos struct statvfs sfs; 328 1.26 lukem 329 1.26 lukem /* 330 1.26 lukem * if mntpt is a mountpoint of a mounted file 331 1.26 lukem * system and it's mounted read-write, skip it 332 1.26 lukem * unless -f is given. 333 1.26 lukem */ 334 1.34 christos if ((statvfs(mntpt, &sfs) == 0) && 335 1.26 lukem (strcmp(mntpt, sfs.f_mntonname) == 0) && 336 1.34 christos ((sfs.f_flag & MNT_RDONLY) == 0)) { 337 1.26 lukem printf( 338 1.26 lukem "%s: file system is mounted read-write on %s; not checking\n", 339 1.26 lukem spec, mntpt); 340 1.26 lukem if ((flags & CHECK_PREEN) && auxarg != NULL) 341 1.47 christos _exit(FSCK_EXIT_OK); /* fsck -p */ 342 1.26 lukem else 343 1.47 christos _exit(FSCK_EXIT_CHECK_FAILED); /* fsck [[-p] ...] */ 344 1.26 lukem } 345 1.26 lukem } 346 1.26 lukem 347 1.4 christos if (flags & CHECK_DEBUG) 348 1.47 christos _exit(FSCK_EXIT_OK); 349 1.2 christos 350 1.1 christos /* Go find an executable. */ 351 1.1 christos edir = edirs; 352 1.1 christos do { 353 1.1 christos (void)snprintf(execname, 354 1.8 christos sizeof(execname), "%s/%s", *edir, execbase); 355 1.41 christos execv(execname, (char * const *)__UNCONST(argv)); 356 1.19 ross if (errno != ENOENT) { 357 1.1 christos if (spec) 358 1.1 christos warn("exec %s for %s", execname, spec); 359 1.1 christos else 360 1.1 christos warn("exec %s", execname); 361 1.19 ross } 362 1.1 christos } while (*++edir != NULL); 363 1.1 christos 364 1.19 ross if (errno == ENOENT) { 365 1.1 christos if (spec) 366 1.1 christos warn("exec %s for %s", execname, spec); 367 1.1 christos else 368 1.1 christos warn("exec %s", execname); 369 1.19 ross } 370 1.47 christos _exit(FSCK_EXIT_CHECK_FAILED); 371 1.1 christos /* NOTREACHED */ 372 1.1 christos 373 1.1 christos default: /* Parent. */ 374 1.1 christos if (optbuf) 375 1.1 christos free(optbuf); 376 1.42 christos free(argv); 377 1.1 christos 378 1.2 christos if (pidp) { 379 1.2 christos *pidp = pid; 380 1.47 christos return FSCK_EXIT_OK; 381 1.2 christos } 382 1.2 christos 383 1.1 christos if (waitpid(pid, &status, 0) < 0) { 384 1.1 christos warn("waitpid"); 385 1.47 christos return FSCK_EXIT_CHECK_FAILED; 386 1.1 christos } 387 1.1 christos 388 1.1 christos if (WIFEXITED(status)) { 389 1.1 christos if (WEXITSTATUS(status) != 0) 390 1.47 christos return WEXITSTATUS(status); 391 1.1 christos } 392 1.1 christos else if (WIFSIGNALED(status)) { 393 1.1 christos warnx("%s: %s", spec, strsignal(WTERMSIG(status))); 394 1.47 christos return FSCK_EXIT_CHECK_FAILED; 395 1.1 christos } 396 1.1 christos break; 397 1.1 christos } 398 1.1 christos 399 1.47 christos return FSCK_EXIT_OK; 400 1.1 christos } 401 1.1 christos 402 1.1 christos 403 1.1 christos static int 404 1.25 lukem selected(const char *type) 405 1.1 christos { 406 1.1 christos struct entry *e; 407 1.1 christos 408 1.1 christos /* If no type specified, it's always selected. */ 409 1.24 lukem TAILQ_FOREACH(e, &selhead, entries) 410 1.46 christos if (!strcmp(e->type, type)) 411 1.1 christos return which == IN_LIST ? 1 : 0; 412 1.1 christos 413 1.1 christos return which == IN_LIST ? 0 : 1; 414 1.1 christos } 415 1.1 christos 416 1.1 christos 417 1.48 christos static int 418 1.48 christos omitted(const char *mountedon) 419 1.48 christos { 420 1.48 christos struct entry *e; 421 1.48 christos 422 1.48 christos /* If no type specified, it's always selected. */ 423 1.48 christos TAILQ_FOREACH(e, &omhead, entries) 424 1.48 christos if (!strcmp(e->type, mountedon)) 425 1.48 christos return 1; 426 1.48 christos 427 1.48 christos return 0; 428 1.48 christos } 429 1.48 christos 430 1.48 christos 431 1.2 christos static const char * 432 1.25 lukem getoptions(const char *type) 433 1.1 christos { 434 1.1 christos struct entry *e; 435 1.1 christos 436 1.24 lukem TAILQ_FOREACH(e, &opthead, entries) 437 1.46 christos if (!strcmp(e->type, type)) 438 1.2 christos return e->options; 439 1.2 christos return ""; 440 1.1 christos } 441 1.1 christos 442 1.1 christos 443 1.1 christos static void 444 1.25 lukem addoption(char *optstr) 445 1.1 christos { 446 1.2 christos char *newoptions; 447 1.1 christos struct entry *e; 448 1.1 christos 449 1.2 christos if ((newoptions = strchr(optstr, ':')) == NULL) 450 1.2 christos errx(1, "Invalid option string"); 451 1.2 christos 452 1.2 christos *newoptions++ = '\0'; 453 1.2 christos 454 1.24 lukem TAILQ_FOREACH(e, &opthead, entries) 455 1.46 christos if (!strcmp(e->type, optstr)) { 456 1.16 mycroft catopt(&e->options, newoptions); 457 1.1 christos return; 458 1.1 christos } 459 1.2 christos addentry(&opthead, optstr, newoptions); 460 1.1 christos } 461 1.1 christos 462 1.1 christos 463 1.1 christos static void 464 1.25 lukem addentry(struct fstypelist *list, const char *type, const char *opts) 465 1.1 christos { 466 1.2 christos struct entry *e; 467 1.2 christos 468 1.2 christos e = emalloc(sizeof(struct entry)); 469 1.2 christos e->type = estrdup(type); 470 1.2 christos e->options = estrdup(opts); 471 1.2 christos TAILQ_INSERT_TAIL(list, e, entries); 472 1.1 christos } 473 1.1 christos 474 1.1 christos 475 1.1 christos static void 476 1.25 lukem maketypelist(char *fslist) 477 1.1 christos { 478 1.1 christos char *ptr; 479 1.1 christos 480 1.1 christos if ((fslist == NULL) || (fslist[0] == '\0')) 481 1.1 christos errx(1, "empty type list"); 482 1.1 christos 483 1.1 christos if (fslist[0] == 'n' && fslist[1] == 'o') { 484 1.1 christos fslist += 2; 485 1.1 christos which = NOT_IN_LIST; 486 1.1 christos } 487 1.1 christos else 488 1.1 christos which = IN_LIST; 489 1.1 christos 490 1.1 christos while ((ptr = strsep(&fslist, ",")) != NULL) 491 1.2 christos addentry(&selhead, ptr, ""); 492 1.1 christos 493 1.1 christos } 494 1.1 christos 495 1.1 christos 496 1.16 mycroft static void 497 1.25 lukem catopt(char **sp, const char *o) 498 1.1 christos { 499 1.16 mycroft char *s; 500 1.16 mycroft size_t i, j; 501 1.1 christos 502 1.16 mycroft s = *sp; 503 1.16 mycroft if (s) { 504 1.16 mycroft i = strlen(s); 505 1.16 mycroft j = i + 1 + strlen(o) + 1; 506 1.16 mycroft s = erealloc(s, j); 507 1.16 mycroft (void)snprintf(s + i, j, ",%s", o); 508 1.15 mycroft } else 509 1.16 mycroft s = estrdup(o); 510 1.16 mycroft *sp = s; 511 1.1 christos } 512 1.1 christos 513 1.1 christos 514 1.1 christos static void 515 1.44 christos mangle(char *opts, int *argcp, const char ** volatile *argvp, int *maxargcp) 516 1.1 christos { 517 1.1 christos char *p, *s; 518 1.15 mycroft int argc, maxargc; 519 1.15 mycroft const char **argv; 520 1.1 christos 521 1.1 christos argc = *argcp; 522 1.15 mycroft argv = *argvp; 523 1.7 christos maxargc = *maxargcp; 524 1.7 christos 525 1.27 lukem for (s = opts; (p = strsep(&s, ",")) != NULL;) { 526 1.15 mycroft /* Always leave space for one more argument and the NULL. */ 527 1.7 christos if (argc >= maxargc - 3) { 528 1.15 mycroft maxargc <<= 1; 529 1.7 christos argv = erealloc(argv, maxargc * sizeof(char *)); 530 1.7 christos } 531 1.19 ross if (*p != '\0') { 532 1.1 christos if (*p == '-') { 533 1.1 christos argv[argc++] = p; 534 1.1 christos p = strchr(p, '='); 535 1.1 christos if (p) { 536 1.1 christos *p = '\0'; 537 1.1 christos argv[argc++] = p+1; 538 1.1 christos } 539 1.15 mycroft } else { 540 1.1 christos argv[argc++] = "-o"; 541 1.1 christos argv[argc++] = p; 542 1.1 christos } 543 1.19 ross } 544 1.7 christos } 545 1.1 christos 546 1.1 christos *argcp = argc; 547 1.7 christos *argvp = argv; 548 1.7 christos *maxargcp = maxargc; 549 1.1 christos } 550 1.8 christos 551 1.44 christos static const char * 552 1.25 lukem getfslab(const char *str) 553 1.8 christos { 554 1.36 thorpej static struct dkwedge_info dkw; 555 1.8 christos struct disklabel dl; 556 1.8 christos int fd; 557 1.17 mycroft char p; 558 1.17 mycroft const char *vfstype; 559 1.8 christos u_char t; 560 1.53 mlelstv char buf[MAXPATHLEN]; 561 1.8 christos 562 1.26 lukem /* deduce the file system type from the disk label */ 563 1.53 mlelstv if ((fd = opendisk(str, O_RDONLY, buf, sizeof(buf), 0)) == -1) 564 1.53 mlelstv err(1, "cannot open `%s'", buf); 565 1.8 christos 566 1.36 thorpej /* First check to see if it's a wedge. */ 567 1.36 thorpej if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == 0) { 568 1.36 thorpej /* Yup, this is easy. */ 569 1.36 thorpej (void) close(fd); 570 1.36 thorpej return (dkw.dkw_ptype); 571 1.36 thorpej } 572 1.36 thorpej 573 1.8 christos if (ioctl(fd, DIOCGDINFO, &dl) == -1) 574 1.53 mlelstv err(1, "cannot get disklabel for `%s'", buf); 575 1.8 christos 576 1.8 christos (void) close(fd); 577 1.8 christos 578 1.53 mlelstv p = buf[strlen(buf) - 1]; 579 1.8 christos 580 1.8 christos if ((p - 'a') >= dl.d_npartitions) 581 1.53 mlelstv errx(1, "partition `%s' is not defined on disk", buf); 582 1.8 christos 583 1.13 bouyer if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES) 584 1.8 christos errx(1, "partition `%s' is not of a legal vfstype", 585 1.53 mlelstv buf); 586 1.8 christos 587 1.8 christos if ((vfstype = fscknames[t]) == NULL) 588 1.8 christos errx(1, "vfstype `%s' on partition `%s' is not supported", 589 1.53 mlelstv fstypenames[t], buf); 590 1.8 christos 591 1.8 christos return vfstype; 592 1.8 christos } 593 1.1 christos 594 1.1 christos 595 1.1 christos static void 596 1.25 lukem usage(void) 597 1.1 christos { 598 1.2 christos static const char common[] = 599 1.48 christos "[-dfnPpqvy] [-x excludemount] [-l maxparallel] [-T fstype:fsoptions]\n\t\t[-t fstype]"; 600 1.1 christos 601 1.32 jmmv (void)fprintf(stderr, "usage: %s %s [special|node]...\n", 602 1.23 cgd getprogname(), common); 603 1.47 christos exit(FSCK_EXIT_USAGE); 604 1.1 christos } 605