From cba9a43130e9d9a7f3168f640a460d45bbc6a898 Mon Sep 17 00:00:00 2001 From: resver Date: Mon, 8 Nov 2010 17:01:44 +0000 Subject: [PATCH] Added a small utility (sbdump) that prints exFAT super block contents in human-readable. git-svn-id: http://exfat.googlecode.com/svn/trunk@170 60bc1c72-a15a-11de-b98f-4500b42dc123 --- SConstruct | 3 +- sbdump/main.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 sbdump/main.c diff --git a/SConstruct b/SConstruct index 2b6c310..98915f7 100644 --- a/SConstruct +++ b/SConstruct @@ -41,6 +41,7 @@ env.Append(LINKFLAGS = '') env.Library('libexfat/exfat', Glob('libexfat/*.c')) mount = env.Program('fuse/mount.exfat-fuse', Glob('fuse/*.c'), LIBS = ['exfat', 'fuse'], LIBPATH = 'libexfat') +sbdump = env.Program('sbdump/sbdump', Glob('sbdump/*.c'), LIBS = ['exfat'], LIBPATH = 'libexfat') fsck = env.Program('fsck/exfatfsck', Glob('fsck/*.c'), LIBS = ['exfat'], LIBPATH = 'libexfat') def get_destdir(): @@ -66,4 +67,4 @@ Alias('install', Install(dir = get_destdir(), source = mount), symlink(dir = get_destdir())) -Default([mount, fsck]) +Default([mount, sbdump, fsck]) diff --git a/sbdump/main.c b/sbdump/main.c new file mode 100644 index 0000000..c87f1c5 --- /dev/null +++ b/sbdump/main.c @@ -0,0 +1,98 @@ +/* + main.c (08.11.10) + A small utility that prints exFAT super block contents in human-readable + format. Useless for end users. + + Copyright (C) 2009, 2010 Andrew Nayenko + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +static void dump_sb(const struct exfat_super_block* sb) +{ + printf("First block %8"PRIu64"\n", + le64_to_cpu(sb->block_start)); + printf("Blocks count %8"PRIu64"\n", + le64_to_cpu(sb->block_count)); + printf("FAT first block %8u\n", + le32_to_cpu(sb->fat_block_start)); + printf("FAT blocks count %8u\n", + le32_to_cpu(sb->fat_block_count)); + printf("First cluster block %8u\n", + le32_to_cpu(sb->cluster_block_start)); + printf("Clusters count %8u\n", + le32_to_cpu(sb->cluster_count)); + printf("Root directory cluster %8u\n", + le32_to_cpu(sb->rootdir_cluster)); + printf("Volume serial number 0x%08x\n", + le32_to_cpu(sb->volume_serial)); + printf("FS version %hu.%hu\n", + le16_to_cpu(sb->version) >> 8, le16_to_cpu(sb->version) & 0xff); + printf("Volume state 0x%04hx\n", + le16_to_cpu(sb->volume_state)); + printf("Block size %8u\n", + BLOCK_SIZE(*sb)); + printf("Cluster size %8u\n", + CLUSTER_SIZE(*sb)); + printf("FATs count %8hhu\n", + sb->fat_count); + printf("Drive number 0x%02hhx\n", + sb->drive_no); + printf("Allocated space %7hhu%%\n", + sb->allocated_percent); +} + +int main(int argc, char* argv[]) +{ + int fd; + struct exfat_super_block sb; + + if (argc != 2) + { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + fd = open(argv[1], O_RDONLY); + if (fd < 0) + { + fprintf(stderr, "failed to open `%s'\n", argv[1]); + 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]); + 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]); + return 1; + } + dump_sb(&sb); + close(fd); + return 0; +} -- 2.11.0