aboutsummaryrefslogtreecommitdiffstats
path: root/fsck
diff options
context:
space:
mode:
authorrelan <relan@users.noreply.github.com>2009-11-11 18:14:09 +0000
committerrelan <relan@users.noreply.github.com>2015-08-24 08:26:10 +0300
commitdb801a262ee720409d0ab6999835ffe7c54df1c8 (patch)
treeaecf002deee0123d9715ac8fab6f373db363403e /fsck
parent33f510a9e0c9db400e080be78cac158fcc30e0a9 (diff)
downloadandroid_external_exfat-db801a262ee720409d0ab6999835ffe7c54df1c8.tar.gz
android_external_exfat-db801a262ee720409d0ab6999835ffe7c54df1c8.tar.bz2
android_external_exfat-db801a262ee720409d0ab6999835ffe7c54df1c8.zip
Add node clusters check in fsck.
Diffstat (limited to 'fsck')
-rw-r--r--fsck/main.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/fsck/main.c b/fsck/main.c
index 2867e10..fa26631 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -17,6 +17,8 @@
#define MB (1024 * 1024)
+#define BMAP_GET(bitmap, index) ((bitmap)[(index) / 8] & (1u << ((index) % 8)))
+
uint64_t files_count, directories_count;
static uint64_t bytes2mb(uint64_t bytes)
@@ -53,6 +55,34 @@ static void sbck(const struct exfat* ef)
printf("Used space %8hhu%%\n", ef->sb->allocated_percent);
}
+static void nodeck(struct exfat* ef, struct exfat_node* node)
+{
+ const cluster_t cluster_size = CLUSTER_SIZE(*ef->sb);
+ cluster_t clusters = (node->size + cluster_size - 1) / cluster_size;
+ cluster_t c = node->start_cluster;
+
+ while (clusters--)
+ {
+ if (CLUSTER_INVALID(c))
+ {
+ char name[EXFAT_NAME_MAX + 1];
+
+ exfat_get_name(node, name, EXFAT_NAME_MAX);
+ exfat_error("file `%s' has invalid cluster", name);
+ return;
+ }
+ if (BMAP_GET(ef->cmap.chunk, c - EXFAT_FIRST_DATA_CLUSTER) == 0)
+ {
+ char name[EXFAT_NAME_MAX + 1];
+
+ exfat_get_name(node, name, EXFAT_NAME_MAX);
+ exfat_error("cluster 0x%x of file `%s' already allocated "
+ "to another file", c, name);
+ }
+ c = exfat_next_cluster(ef, node, c);
+ }
+}
+
static void dirck(struct exfat* ef, const char* path)
{
struct exfat_node* parent;
@@ -89,6 +119,7 @@ static void dirck(struct exfat* ef, const char* path)
}
else
files_count++;
+ nodeck(ef, node);
exfat_put_node(node);
}
exfat_closedir(&it);