Skip to content

Commit

Permalink
fsck: repair unknown directory entries
Browse files Browse the repository at this point in the history
if unknown directory entries are found,
Clear InUse bit in EntryType field.

Signed-off-by: Hyunchul Lee <[email protected]>
  • Loading branch information
hclee committed Aug 25, 2022
1 parent b8cf757 commit 58a13e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
31 changes: 22 additions & 9 deletions fsck/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ static void usage(char *name)

#define repair_file_ask(iter, inode, code, fmt, ...) \
({ \
exfat_resolve_path_parent(&path_resolve_ctx, \
(iter)->parent, inode); \
exfat_repair_ask(&exfat_fsck, code, \
if (inode) \
exfat_resolve_path_parent(&path_resolve_ctx, \
(iter)->parent, inode); \
else \
exfat_resolve_path(&path_resolve_ctx, \
(iter)->parent); \
exfat_repair_ask(&exfat_fsck, code, \
"ERROR: %s: " fmt " at %#" PRIx64, \
path_resolve_ctx.local_path, \
##__VA_ARGS__, \
Expand Down Expand Up @@ -951,18 +955,27 @@ static int read_children(struct exfat_fsck *fsck, struct exfat_inode *dir)
} else
exfat_free_inode(node);
break;
case EXFAT_LAST:
goto out;
case EXFAT_VOLUME:
case EXFAT_BITMAP:
case EXFAT_UPCASE:
break;
case EXFAT_LAST:
goto out;
if (dir == exfat->root)
break;
/* fallthrough */
default:
if (IS_EXFAT_DELETED(dentry->type))
break;
exfat_err("unknown entry type. 0x%x\n", dentry->type);
ret = -EINVAL;
goto err;
if (repair_file_ask(de_iter, NULL, ER_DE_UNKNOWN,
"unknown entry type %#x at %07" PRIx64,
dentry->type,
exfat_de_iter_file_offset(de_iter))) {
struct exfat_dentry *dentry;

exfat_de_iter_get_dirty(de_iter, 0, &dentry);
dentry->type &= EXFAT_DELETE;
}
break;
}

exfat_de_iter_advance(de_iter, dentry_count);
Expand Down
1 change: 1 addition & 0 deletions fsck/repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static struct exfat_repair_problem problems[] = {
{ER_BS_CHECKSUM, ERF_PREEN_YES, ERP_FIX},
{ER_BS_BOOT_REGION, 0, ERP_FIX},
{ER_DE_CHECKSUM, ERF_PREEN_YES, ERP_FIX},
{ER_DE_UNKNOWN, ERF_PREEN_YES, ERP_FIX},
{ER_FILE_VALID_SIZE, ERF_PREEN_YES, ERP_FIX},
{ER_FILE_INVALID_CLUS, ERF_PREEN_YES, ERP_TRUNCATE},
{ER_FILE_FIRST_CLUS, ERF_PREEN_YES, ERP_TRUNCATE},
Expand Down
1 change: 1 addition & 0 deletions fsck/repair.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define ER_BS_CHECKSUM 0x00000001
#define ER_BS_BOOT_REGION 0x00000002
#define ER_DE_CHECKSUM 0x00001001
#define ER_DE_UNKNOWN 0x00001002
#define ER_FILE_VALID_SIZE 0x00002001
#define ER_FILE_INVALID_CLUS 0x00002002
#define ER_FILE_FIRST_CLUS 0x00002003
Expand Down

0 comments on commit 58a13e2

Please sign in to comment.