/* * read_options() * */ static int read_options(int argc, char **argv) { int c; int ret = 0; progname = basename(argv[0]); if (argc < 2) { usage(progname); return 1; } while(1) { c = getopt(argc, argv, "c:n:"); if (c == -1) break; switch (c) { case 'c': /* corrupt */ ret = parse_corrupt_codes(optarg); break; case 'n': /* slotnum */ slotnum = strtoul(optarg, NULL, 0); break; default: break; } } if (optind < argc && argv[optind]) device = argv[optind]; if (ret < 0) usage(progname); return ret; }
/* * read_options() * */ static int read_options(int argc, char **argv) { int i, c, listcode = 0, showmkfs = 0; int ret = 0; progname = basename(argv[0]); if (argc < 2) usage(); while (1) { c = getopt(argc, argv, "lnc:C:N:L:M"); if (c == -1) break; switch (c) { case 'c': /* corrupt code string */ ret = parse_corrupt_codes(optarg); break; case 'l': print_codes(); break; case 'L': listcode = 1; case 'C': /* corrupt code number */ ret = atoi(optarg); if (ret < NUM_FSCK_TYPE) corrupt[ret] = 1; else { fprintf(stderr, "Corrupt code \"%d\" is not " "supported.\n", ret); exit(-1); } break; case 'M': /* mkfs features */ showmkfs = 1; break; case 'n': fprintf(stdout, "%d\n", NUM_FSCK_TYPE); exit(NUM_FSCK_TYPE); case 'N': /* slotnum */ slotnum = strtoul(optarg, NULL, 0); break; default: ret = -1; goto out; } } if (listcode) { for (i = 0; i < NUM_FSCK_TYPE; i++) { if (corrupt[i]) { fprintf(stdout, "%s\n", prompt_codes[i].pc_codestr); listcode = 0; break; } } exit(listcode); } #define MKFS_PARAMS_FIX \ "-b 4096 -C 4096 --fs-feature-level=max-features -J size=16M " \ "-L fswreck -M local" if (showmkfs) { for (i = 0; i < NUM_FSCK_TYPE; i++) { if (corrupt[i]) { fprintf(stdout, MKFS_PARAMS_FIX); fprintf(stdout, " -N %d", prompt_codes[i].pc_slots); if (strlen(prompt_codes[i].pc_fsfeat)) fprintf(stdout, " --fs-features=%s", prompt_codes[i].pc_fsfeat); fprintf(stdout, "\n"); showmkfs = 0; break; } } exit(showmkfs); } if (optind >= argc || !argv[optind]) { ret = -1; goto out; } device = argv[optind]; out: if (ret < 0) usage(); return ret; }