diff options
author | relan <relan@users.noreply.github.com> | 2011-01-24 17:57:38 +0000 |
---|---|---|
committer | relan <relan@users.noreply.github.com> | 2015-08-24 08:26:13 +0300 |
commit | 35f9a6e77de6a7ad5a270ae9ccea0180efd7d196 (patch) | |
tree | eb8300363ca7bd3f1cd0b8d5db46d09e62d62d9e /dump | |
parent | 8d984a6a46cc690d2dc5947b370ecfd6d5782fc3 (diff) | |
download | android_external_exfat-35f9a6e77de6a7ad5a270ae9ccea0180efd7d196.tar.gz android_external_exfat-35f9a6e77de6a7ad5a270ae9ccea0180efd7d196.tar.bz2 android_external_exfat-35f9a6e77de6a7ad5a270ae9ccea0180efd7d196.zip |
Improve dumpexfat.
Now it also prints volume label, free sectors and free clusters count.
Diffstat (limited to 'dump')
-rw-r--r-- | dump/main.c | 115 |
1 files changed, 90 insertions, 25 deletions
diff --git a/dump/main.c b/dump/main.c index 1561048..ede95f3 100644 --- a/dump/main.c +++ b/dump/main.c @@ -25,32 +25,44 @@ #include <string.h> #include <exfat.h> -static void dump_sb(const struct exfat_super_block* sb) +static void print_generic_info(const struct exfat_super_block* sb) +{ + printf("Volume serial number 0x%08x\n", + le32_to_cpu(sb->volume_serial)); + printf("FS version %hhu.%hhu\n", + sb->version.major, sb->version.minor); + printf("Block size %10u\n", + BLOCK_SIZE(*sb)); + printf("Cluster size %10u\n", + CLUSTER_SIZE(*sb)); +} + +static void print_block_info(const struct exfat_super_block* sb) { - printf("First block %10"PRIu64"\n", - le64_to_cpu(sb->block_start)); printf("Blocks count %10"PRIu64"\n", le64_to_cpu(sb->block_count)); +} + +static void print_cluster_info(const struct exfat_super_block* sb) +{ + printf("Clusters count %10u\n", + le32_to_cpu(sb->cluster_count)); +} + +static void print_other_info(const struct exfat_super_block* sb) +{ + printf("First block %10"PRIu64"\n", + le64_to_cpu(sb->block_start)); printf("FAT first block %10u\n", le32_to_cpu(sb->fat_block_start)); printf("FAT blocks count %10u\n", le32_to_cpu(sb->fat_block_count)); printf("First cluster block %10u\n", le32_to_cpu(sb->cluster_block_start)); - printf("Clusters count %10u\n", - le32_to_cpu(sb->cluster_count)); printf("Root directory cluster %10u\n", le32_to_cpu(sb->rootdir_cluster)); - printf("Volume serial number 0x%08x\n", - le32_to_cpu(sb->volume_serial)); - printf("FS version %hhu.%hhu\n", - sb->version.major, sb->version.minor); printf("Volume state 0x%04hx\n", le16_to_cpu(sb->volume_state)); - printf("Block size %10u\n", - BLOCK_SIZE(*sb)); - printf("Cluster size %10u\n", - CLUSTER_SIZE(*sb)); printf("FATs count %10hhu\n", sb->fat_count); printf("Drive number 0x%02hhx\n", @@ -59,37 +71,90 @@ static void dump_sb(const struct exfat_super_block* sb) sb->allocated_percent); } -int main(int argc, char* argv[]) +static int dump_sb(const char* spec) { int fd; struct exfat_super_block sb; - if (argc != 2) - { - fprintf(stderr, "Usage: %s <device>\n", argv[0]); - return 1; - } - - fd = open(argv[1], O_RDONLY); + fd = open(spec, O_RDONLY); if (fd < 0) { - fprintf(stderr, "failed to open `%s'\n", argv[1]); + exfat_error("failed to open `%s'", spec); return 1; } if (read(fd, &sb, sizeof(struct exfat_super_block)) != sizeof(struct exfat_super_block)) { close(fd); - fprintf(stderr, "failed to read from `%s'.\n", argv[1]); + exfat_error("failed to read from `%s'", spec); return 1; } if (memcmp(sb.oem_name, "EXFAT ", sizeof(sb.oem_name)) != 0) { close(fd); - fprintf(stderr, "exFAT file system is not found on `%s'.\n", argv[1]); + exfat_error("exFAT file system is not found on `%s'", spec); return 1; } - dump_sb(&sb); + + print_generic_info(&sb); + print_block_info(&sb); + print_cluster_info(&sb); + print_other_info(&sb); + close(fd); return 0; } + +static int dump_full(const char* spec) +{ + struct exfat ef; + uint32_t free_clusters; + uint64_t free_blocks; + + if (exfat_mount(&ef, spec, "ro") != 0) + return 1; + + free_clusters = exfat_count_free_clusters(&ef); + free_blocks = (uint64_t) free_clusters << ef.sb->bpc_bits; + + printf("Volume label %15s\n", exfat_get_label(&ef)); + print_generic_info(ef.sb); + print_block_info(ef.sb); + printf("Free blocks %10"PRIu64"\n", free_blocks); + print_cluster_info(ef.sb); + printf("Free clusters %10u\n", free_clusters); + print_other_info(ef.sb); + + exfat_unmount(&ef); + return 0; +} + +static void usage(const char* prog) +{ + fprintf(stderr, "Usage: %s [-s] <device>\n", prog); + exit(1); +} + +int main(int argc, char* argv[]) +{ + char** pp; + const char* spec = NULL; + int sb_only = 0; + + for (pp = argv + 1; *pp; pp++) + { + if (strcmp(*pp, "-s") == 0) + sb_only = 1; + else if (spec == NULL) + spec = *pp; + else + usage(argv[0]); + } + if (spec == NULL) + usage(argv[0]); + + if (sb_only) + return dump_sb(spec); + else + return dump_full(spec); +} |