OSDN Git Service

Rename sbdump to dumpexfat.
[android-x86/external-exfat.git] / dump / main.c
1 /*
2         main.c (08.11.10)
3         Prints detailed information about exFAT volume.
4
5         Copyright (C) 2010  Andrew Nayenko
6
7         This program is free software: you can redistribute it and/or modify
8         it under the terms of the GNU General Public License as published by
9         the Free Software Foundation, either version 3 of the License, or
10         (at your option) any later version.
11
12         This program is distributed in the hope that it will be useful,
13         but WITHOUT ANY WARRANTY; without even the implied warranty of
14         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15         GNU General Public License for more details.
16
17         You should have received a copy of the GNU General Public License
18         along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <inttypes.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <exfat.h>
27
28 static void dump_sb(const struct exfat_super_block* sb)
29 {
30         printf("First block               %8"PRIu64"\n",
31                         le64_to_cpu(sb->block_start));
32         printf("Blocks count              %8"PRIu64"\n",
33                         le64_to_cpu(sb->block_count));
34         printf("FAT first block           %8u\n",
35                         le32_to_cpu(sb->fat_block_start));
36         printf("FAT blocks count          %8u\n",
37                         le32_to_cpu(sb->fat_block_count));
38         printf("First cluster block       %8u\n",
39                         le32_to_cpu(sb->cluster_block_start));
40         printf("Clusters count            %8u\n",
41                         le32_to_cpu(sb->cluster_count));
42         printf("Root directory cluster    %8u\n",
43                         le32_to_cpu(sb->rootdir_cluster));
44         printf("Volume serial number    0x%08x\n",
45                         le32_to_cpu(sb->volume_serial));
46         printf("FS version                     %hhu.%hhu\n",
47                         sb->version.major, sb->version.minor);
48         printf("Volume state                0x%04hx\n",
49                         le16_to_cpu(sb->volume_state));
50         printf("Block size                %8u\n",
51                         BLOCK_SIZE(*sb));
52         printf("Cluster size              %8u\n",
53                         CLUSTER_SIZE(*sb));
54         printf("FATs count                %8hhu\n",
55                         sb->fat_count);
56         printf("Drive number                  0x%02hhx\n",
57                         sb->drive_no);
58         printf("Allocated space           %7hhu%%\n",
59                         sb->allocated_percent);
60 }
61
62 int main(int argc, char* argv[])
63 {
64         int fd;
65         struct exfat_super_block sb;
66
67         if (argc != 2)
68         {
69                 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
70                 return 1;
71         }
72
73         fd = open(argv[1], O_RDONLY);
74         if (fd < 0)
75         {
76                 fprintf(stderr, "failed to open `%s'\n", argv[1]);
77                 return 1;
78         }
79         if (read(fd, &sb, sizeof(struct exfat_super_block))
80                         != sizeof(struct exfat_super_block))
81         {
82                 close(fd);
83                 fprintf(stderr, "failed to read from `%s'.\n", argv[1]);
84                 return 1;
85         }
86         if (memcmp(sb.oem_name, "EXFAT   ", sizeof(sb.oem_name)) != 0)
87         {
88                 close(fd);
89                 fprintf(stderr, "exFAT file system is not found on `%s'.\n", argv[1]);
90                 return 1;
91         }
92         dump_sb(&sb);
93         close(fd);
94         return 0;
95 }