Skip to content

Commit

Permalink
Merge pull request #190 from hclee/for-next
Browse files Browse the repository at this point in the history
For next
  • Loading branch information
namjaejeon authored Dec 13, 2021
2 parents 7817243 + c0c2025 commit 5a589af
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dump/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ static int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd)
goto free_ppbr;
}

if (memcmp(ppbr->bpb.oem_name, "EXFAT ", 8) != 0) {
exfat_err("Bad fs_name in boot sector, which does not describe a valid exfat filesystem\n");
ret = -EINVAL;
goto free_ppbr;
}

pbsx = &ppbr->bsx;

if (pbsx->sect_size_bits < EXFAT_MIN_SECT_SIZE_BITS ||
Expand Down
17 changes: 16 additions & 1 deletion fsck/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static struct option opts[] = {
{"verbose", no_argument, NULL, 'v' },
{"help", no_argument, NULL, 'h' },
{"?", no_argument, NULL, '?' },
{"ignore-bad-fs", no_argument, NULL, 'b' },
{NULL, 0, NULL, 0 }
};

Expand All @@ -88,6 +89,7 @@ static void usage(char *name)
fprintf(stderr, "\t-n | --repair-no No repair\n");
fprintf(stderr, "\t-p | --repair-auto Repair automatically\n");
fprintf(stderr, "\t-a Repair automatically\n");
fprintf(stderr, "\t-b | --ignore-bad-fs Try to recover even if exfat is not found\n");
fprintf(stderr, "\t-V | --version Show version\n");
fprintf(stderr, "\t-v | --verbose Print debug\n");
fprintf(stderr, "\t-h | --help Show help\n");
Expand Down Expand Up @@ -796,9 +798,17 @@ static int exfat_boot_region_check(struct exfat *exfat, struct pbr **bs)
if (exfat_read(exfat->blk_dev->dev_fd, boot_sect,
sizeof(*boot_sect), 0) != (ssize_t)sizeof(*boot_sect)) {
exfat_err("failed to read Main boot sector\n");
free(boot_sect);
return -EIO;
}

if (memcmp(boot_sect->bpb.oem_name, "EXFAT ", 8) != 0 &&
!(exfat->options & FSCK_OPTS_IGNORE_BAD_FS_NAME)) {
exfat_err("Bad fs_name in boot sector, which does not describe a valid exfat filesystem\n");
free(boot_sect);
return -ENOTSUP;
}

sect_size = 1 << boot_sect->bsx.sect_size_bits;
free(boot_sect);

Expand Down Expand Up @@ -1530,7 +1540,7 @@ int main(int argc, char * const argv[])
exfat_err("failed to init locale/codeset\n");

opterr = 0;
while ((c = getopt_long(argc, argv, "arynpVvh", opts, NULL)) != EOF) {
while ((c = getopt_long(argc, argv, "arynpbVvh", opts, NULL)) != EOF) {
switch (c) {
case 'n':
if (ui.options & FSCK_OPTS_REPAIR_ALL)
Expand All @@ -1553,6 +1563,9 @@ int main(int argc, char * const argv[])
usage(argv[0]);
ui.options |= FSCK_OPTS_REPAIR_AUTO;
break;
case 'b':
ui.options |= FSCK_OPTS_IGNORE_BAD_FS_NAME;
break;
case 'V':
version_only = true;
break;
Expand All @@ -1576,6 +1589,8 @@ int main(int argc, char * const argv[])
if (ui.options & FSCK_OPTS_REPAIR_WRITE)
ui.ei.writeable = true;
else {
if (ui.options & FSCK_OPTS_IGNORE_BAD_FS_NAME)
usage(argv[0]);
ui.options |= FSCK_OPTS_REPAIR_NO;
ui.ei.writeable = false;
}
Expand Down
1 change: 1 addition & 0 deletions fsck/fsck.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum fsck_ui_options {
FSCK_OPTS_REPAIR_AUTO = 0x08,
FSCK_OPTS_REPAIR_WRITE = 0x0b,
FSCK_OPTS_REPAIR_ALL = 0x0f,
FSCK_OPTS_IGNORE_BAD_FS_NAME = 0x10,
};

struct exfat {
Expand Down
18 changes: 18 additions & 0 deletions lib/libexfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ off_t exfat_get_root_entry_offset(struct exfat_blk_dev *bd)
return -1;
}

if (memcmp(bs->bpb.oem_name, "EXFAT ", 8) != 0) {
exfat_err("Bad fs_name in boot sector, which does not describe a valid exfat filesystem\n");
free(bs);
return -1;
}

sector_size = 1 << bs->bsx.sect_size_bits;
cluster_size = (1 << bs->bsx.sect_per_clus_bits) * sector_size;
root_clu_off = le32_to_cpu(bs->bsx.clu_offset) * sector_size +
Expand Down Expand Up @@ -546,6 +552,12 @@ int exfat_show_volume_serial(int fd)
goto free_ppbr;
}

if (memcmp(ppbr->bpb.oem_name, "EXFAT ", 8) != 0) {
exfat_err("Bad fs_name in boot sector, which does not describe a valid exfat filesystem\n");
ret = -1;
goto free_ppbr;
}

exfat_info("volume serial : 0x%x\n", ppbr->bsx.vol_serial);

free_ppbr:
Expand Down Expand Up @@ -614,6 +626,12 @@ int exfat_set_volume_serial(struct exfat_blk_dev *bd,
goto free_ppbr;
}

if (memcmp(ppbr->bpb.oem_name, "EXFAT ", 8) != 0) {
exfat_err("Bad fs_name in boot sector, which does not describe a valid exfat filesystem\n");
ret = -1;
goto free_ppbr;
}

bd->sector_size = 1 << ppbr->bsx.sect_size_bits;
ppbr->bsx.vol_serial = ui->volume_serial;

Expand Down
5 changes: 5 additions & 0 deletions manpages/fsck.exfat.8
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ fsck.exfat \- check an exFAT filesystem
] [
.B \-y
] [
.B \-b
] [
.B \-v
]
.I device
Expand Down Expand Up @@ -46,6 +48,9 @@ Prints the version number and exits.
.TP
.B \-y
Repair the filesystem answering yes to all questions.
.TP
.B \-b
Try to repair the filesystem even if the exFAT filesystem is not found.
.SH SEE ALSO
.BR fsck (8),
.BR fstab (5),

0 comments on commit 5a589af

Please sign in to comment.