From f9c0f1b75b818b5a4f3ed65f65d6aa0fb529f24c Mon Sep 17 00:00:00 2001 From: relan Date: Thu, 23 Mar 2017 08:34:21 +0300 Subject: [PATCH] Repairing: implement unknown entry type fix. --- libexfat/exfat.h | 2 ++ libexfat/node.c | 3 ++- libexfat/repair.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libexfat/exfat.h b/libexfat/exfat.h index 00c903d0..2342be4f 100644 --- a/libexfat/exfat.h +++ b/libexfat/exfat.h @@ -238,5 +238,7 @@ bool exfat_fix_invalid_vbr_checksum(const struct exfat* ef, void* sector, uint32_t vbr_checksum); bool exfat_fix_invalid_node_checksum(const struct exfat* ef, struct exfat_node* node); +bool exfat_fix_unknown_entry(struct exfat* ef, struct exfat_node* dir, + const struct exfat_entry* entry, off_t offset); #endif /* ifndef EXFAT_H_INCLUDED */ diff --git a/libexfat/node.c b/libexfat/node.c index 9270ccfc..ab1d7d6d 100644 --- a/libexfat/node.c +++ b/libexfat/node.c @@ -517,7 +517,8 @@ static int readdir(struct exfat* ef, struct exfat_node* parent, break; /* deleted entry, ignore it */ exfat_error("unknown entry type %#hhx", entry.type); - return -EIO; + if (!EXFAT_REPAIR(unknown_entry, ef, parent, &entry, *offset)) + return -EIO; } *offset += sizeof(entry); } diff --git a/libexfat/repair.c b/libexfat/repair.c index 049ebd72..237ab3ac 100644 --- a/libexfat/repair.c +++ b/libexfat/repair.c @@ -86,3 +86,17 @@ bool exfat_fix_invalid_node_checksum(const struct exfat* ef, exfat_errors_fixed++; return true; } + +bool exfat_fix_unknown_entry(struct exfat* ef, struct exfat_node* dir, + const struct exfat_entry* entry, off_t offset) +{ + struct exfat_entry deleted = *entry; + + deleted.type &= ~EXFAT_ENTRY_VALID; + if (exfat_generic_pwrite(ef, dir, &deleted, sizeof(struct exfat_entry), + offset) != sizeof(struct exfat_entry)) + return false; + + exfat_errors_fixed++; + return true; +}