11 static struct sufs_superblock sb;
13 #define print(sb, field) do_print (#field, (sb).field)
14 static void do_print (const char *name, uint64_t value)
16 printf ("%s: %"PRIu64"\n", name, value);
19 static void read_block (uint64_t blkno)
22 if (lseek (fd, blkno * sb.bsize, SEEK_SET) < 0)
23 err (1, "read_block(%"PRIu64"): lseek()", blkno);
24 x = read (fd, block, sb.bsize);
26 err (1, "read_block(%"PRIu64"): read(): %zd", blkno, x);
29 static uint64_t count (uint64_t begin, uint64_t num)
32 uint64_t n = (num + 7) / 8;
34 for (uint64_t i = 0; i < n; i += sb.bsize) {
35 read_block (begin + i);
36 for (uint64_t j = 0; j < sb.bsize && j < n; ++j) {
37 for (unsigned k = 0; k < 8 && (((i + j) * 8 + k) < num); ++k) {
38 if ((block[j] >> k) & 1)
47 int main (int argc, char *argv[])
50 errx (1, "usage: dumpfs_sufs file");
52 fd = open (argv[1], O_RDONLY);
56 if (read (fd, &sb, sizeof (sb)) != sizeof (sb))
59 if (sb.magic != SUFS_MAGIC) {
60 if (lseek (fd, SUFS_BOOTSIZE, SEEK_SET) < 0)
63 if (read (fd, &sb, sizeof (sb)) != sizeof (sb))
67 block = malloc (sb.bsize);
69 printf ("magic: %#08"PRIx32" (%s)\n", sb.magic, sb.magic == SUFS_MAGIC ? "OK" : "INVAL");
78 do_print ("ifree", count (sb.ibmoff, sb.nino));
79 do_print ("dfree", count (sb.dbmoff, sb.ndata));