242
240
"/sys/dev/block/%d:%d/queue/rotational",
243
241
major(disk), minor(disk));
245
if (rc < 0 || rc + 1 > sizeof(path))
243
if (rc < 0 || (unsigned int) (rc + 1) > sizeof(path))
248
246
f = fopen(path, "r");
252
rc = fscanf(f, "%u", &x);
250
rc = fscanf(f, "%d", &x);
253
warn(_("failed to read: %s"), path);
255
warnx(_("parse error: %s"), path);
255
259
return rc == 1 ? !x : 0;
258
262
static void lock_disk(struct fsck_instance *inst)
260
dev_t disk = inst->fs->disk ? : get_disk(inst->fs->device);
264
dev_t disk = inst->fs->disk ? inst->fs->disk : get_disk(inst->fs->device);
263
267
if (!disk || is_irrotational_disk(disk))
417
421
struct fs_info *fs;
419
423
if ((f = fopen(filename, "r")) == NULL) {
420
fprintf(stderr, _("WARNING: couldn't open %s: %s\n"),
421
filename, strerror(errno));
424
warn(_("WARNING: couldn't open %s"), filename);
424
427
while (!feof(f)) {
428
431
buf[sizeof(buf)-1] = 0;
429
432
if (parse_fstab_line(buf, &fs) < 0) {
430
fprintf(stderr, _("WARNING: bad format "
431
"on line %d of %s\n"), lineno, filename);
433
warnx(_("WARNING: bad format "
434
"on line %d of %s"), lineno, filename);
444
447
if (old_fstab && filesys_info) {
446
449
"WARNING: Your /etc/fstab does not contain the fsck passno\n"
447
450
" field. I will kludge around things for you, but you\n"
448
" should fix your /etc/fstab file as soon as you can.\n\n"), stderr);
451
" should fix your /etc/fstab file as soon as you can.\n"));
450
453
for (fs = filesys_info; fs; fs = fs->next) {
515
518
struct fsck_instance *inst, *p;
518
inst = malloc(sizeof(struct fsck_instance));
521
inst = xmalloc(sizeof(struct fsck_instance));
521
522
memset(inst, 0, sizeof(struct fsck_instance));
523
524
sprintf(prog, "fsck.%s", type);
693
692
if (sig == SIGINT) {
694
693
status = EXIT_UNCORRECTED;
696
printf(_("Warning... %s for device %s exited "
697
"with signal %d.\n"),
695
warnx(_("Warning... %s for device %s exited "
698
697
inst->prog, inst->fs->device, sig);
699
698
status = EXIT_ERROR;
702
printf(_("%s %s: status is %x, should never happen.\n"),
701
warnx(_("%s %s: status is %x, should never happen."),
703
702
inst->prog, inst->fs->device, status);
704
703
status = EXIT_ERROR;
799
798
retval = execute(type, fs, interactive);
801
fprintf(stderr, _("%s: Error %d while executing fsck.%s "
802
"for %s\n"), progname, retval, type, fs->device);
800
warnx(_("error %d while executing fsck.%s for %s"),
801
retval, type, fs->device);
804
803
return EXIT_ERROR;
840
cmp->list = malloc(num * sizeof(char *));
841
cmp->type = malloc(num * sizeof(int));
842
if (!cmp->list || !cmp->type) {
843
fputs(_("Couldn't allocate memory for filesystem types\n"),
835
cmp->list = xmalloc(num * sizeof(char *));
836
cmp->type = xmalloc(num * sizeof(int));
847
837
memset(cmp->list, 0, num * sizeof(char *));
848
838
memset(cmp->type, 0, num * sizeof(int));
878
868
if ((negate && !cmp->negate) ||
879
869
(!negate && cmp->negate)) {
880
fputs(_(fs_type_syntax_error), stderr);
871
_("Either all or none of the filesystem types passed to -t must be prefixed\n"
872
"with 'no' or '!'."));
885
876
printf("Adding %s to list (type %d).\n", s, cmp->type[num]);
887
cmp->list[num++] = string_copy(s);
878
cmp->list[num++] = string_copy(s);
888
879
s = strtok(NULL, ",");
978
969
* If this is a bind mount, ignore it.
980
971
if (opt_in_list("bind", fs->opts)) {
982
_("%s: skipping bad line in /etc/fstab: bind mount with nonzero fsck pass number\n"),
972
warnx(_("%s: skipping bad line in /etc/fstab: "
973
"bind mount with nonzero fsck pass number"),
1022
1013
/* See if the <fsck.fs> program is available. */
1023
1014
if (find_fsck(fs->type) == NULL) {
1025
fprintf(stderr, _("fsck: cannot check %s: fsck.%s not found\n"),
1016
warnx(_("cannot check %s: fsck.%s not found"),
1026
1017
fs->device, fs->type);
1220
static void usage(NOARGS)
1211
static void __attribute__((__noreturn__)) usage(void)
1222
fputs(_("Usage: fsck [-AMNPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr);
1213
printf(_("\nUsage:\n"
1214
" %s [fsck-options] [fs-options] [filesys ...]\n"),
1215
program_invocation_short_name);
1217
puts(_( "\nOptions:\n"
1218
" -A check all filesystems\n"
1219
" -R skip root filesystem; useful only with `-A'\n"
1220
" -M do not check mounted filesystems\n"
1221
" -t <type> specify filesystem types to be checked;\n"
1222
" type is allowed to be comma-separated list\n"
1223
" -P check filesystems in parallel, including root\n"
1224
" -s serialize fsck operations\n"
1225
" -l lock the device using flock()\n"
1226
" -N do not execute, just show what would be done\n"
1227
" -T do not show the title on startup\n"
1228
" -C <fd> display progress bar; file descriptor is for GUIs\n"
1229
" -V explain what is being done\n"
1230
" -? display this help and exit\n\n"
1231
"See fsck.* commands for fs-options."));
1223
1233
exit(EXIT_USAGE);
1250
1260
instance_list = 0;
1254
1262
for (i=1; i < argc; i++) {
1258
1266
if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
1259
if (num_devices >= MAX_DEVICES) {
1260
fprintf(stderr, _("%s: too many devices\n"),
1267
if (num_devices >= MAX_DEVICES)
1268
errx(EXIT_ERROR, _("too many devices"));
1264
1269
dev = fsprobe_get_devname_by_spec(arg);
1265
1270
if (!dev && strchr(arg, '=')) {
1268
1273
* /proc/partitions isn't found.
1270
1275
if (access(_PATH_PROC_PARTITIONS, R_OK) < 0) {
1271
fprintf(stderr, _("Couldn't open %s: %s\n"),
1272
_PATH_PROC_PARTITIONS, strerror(errno));
1273
fprintf(stderr, _("Is /proc mounted?\n"));
1276
warn(_("couldn't open %s"),
1277
_PATH_PROC_PARTITIONS);
1278
errx(EXIT_ERROR, _("Is /proc mounted?"));
1277
1281
* Check to see if this is because
1278
1282
* we're not running as root
1282
_("Must be root to scan for matching filesystems: %s\n"), arg);
1286
_("must be root to scan for matching filesystems: %s"),
1285
_("Couldn't find matching filesystem: %s\n"), arg);
1290
_("couldn't find matching filesystem: %s"),
1288
1293
devices[num_devices++] = dev ? dev : string_copy(arg);
1291
1296
if (arg[0] != '-' || opts_for_fsck) {
1292
if (num_args >= MAX_ARGS) {
1293
fprintf(stderr, _("%s: too many arguments\n"),
1297
if (num_args >= MAX_ARGS)
1298
errx(EXIT_ERROR, _("too many arguments"));
1297
1299
args[num_args++] = string_copy(arg);
1378
1380
options[0] = '-';
1379
1381
options[++opt] = '\0';
1380
if (num_args >= MAX_ARGS) {
1382
_("%s: too many arguments\n"),
1382
if (num_args >= MAX_ARGS)
1383
errx(EXIT_ERROR, _("too many arguments"));
1386
1384
args[num_args++] = string_copy(options);
1413
1411
PRS(argc, argv);
1416
printf(_("fsck from %s\n"), PACKAGE_STRING);
1414
printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING);
1418
1416
fstab = getenv("FSTAB_FILE");
1423
1421
/* Update our search path to include uncommon directories. */
1425
fsck_path = malloc (strlen (fsck_prefix_path) + 1 +
1423
fsck_path = xmalloc (strlen (fsck_prefix_path) + 1 +
1426
1424
strlen (oldpath) + 1);
1428
fprintf(stderr, _("%s: Unable to allocate memory for fsck_path\n"), progname);
1431
1425
strcpy (fsck_path, fsck_prefix_path);
1432
1426
strcat (fsck_path, ":");
1433
1427
strcat (fsck_path, oldpath);
1439
1433
interactive = 1;
1441
1435
if (lockdisk && (doall || num_devices > 1)) {
1442
fprintf(stderr, _("%s: the -l option can be used with one "
1443
"device only -- ignore\n"), progname);
1436
warnx(_("the -l option can be used with one "
1437
"device only -- ignore"));