#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)
printf("Block size %8u bytes\n", block_size);
printf("Cluster size %8u bytes\n", cluster_size);
printf("Total space %8"PRIu64" MB\n", bytes2mb(total));
- printf("Used space %8"PRIu64" MB (%hhu%%)\n",
- bytes2mb(total * ef->sb->allocated_percent / 100),
- ef->sb->allocated_percent);
- printf("Free space %8"PRIu64" MB (%hhu%%)\n",
- bytes2mb(total * (100 - ef->sb->allocated_percent) / 100),
- 100 - ef->sb->allocated_percent);
+ 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)
rc = exfat_opendir(ef, parent, &it);
if (rc != 0)
{
- exfat_put_node(parent);
+ exfat_put_node(ef, parent);
exfat_error("failed to open directory `%s'", path);
return;
}
}
else
files_count++;
- exfat_put_node(node);
+ nodeck(ef, node);
+ exfat_put_node(ef, node);
}
- exfat_closedir(&it);
- exfat_put_node(parent);
+ exfat_closedir(ef, &it);
+ exfat_put_node(ef, parent);
}
static void fsck(struct exfat* ef)