Make the library when building dist and normal targets
[omfsprogs.git] / dump.c
blobe26629564c19a83784503aacfe6396fc86547a8c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <string.h>
5 #include <ctype.h>
6 #include "omfs.h"
7 #include "dirscan.h"
8 #include "check.h"
9 #include "crc.h"
10 #include "fix.h"
11 #include "bits.h"
12 #include "io.h"
14 static int on_node(dirscan_t *d, dirscan_entry_t *entry, void *user)
16 char *name = escape(entry->inode->i_name);
18 printf("inode: %*c%s%c s:%llx h:%d c:%d p:%llx b:%llx\n",
19 entry->level*2, ' ', name,
20 (entry->inode->i_type == OMFS_DIR) ? '/' : ' ',
21 swap_be64(entry->inode->i_head.h_self), entry->hindex,
22 swap_be16(entry->inode->i_head.h_crc),
23 entry->parent, entry->block);
24 free(name);
26 return 0;
29 int dump_fs(FILE *fp)
31 int bsize;
32 omfs_super_t super;
33 omfs_root_t root;
34 omfs_info_t info = {
35 .dev = fp,
36 .super = &super,
37 .root = &root
40 if (omfs_read_super(&info))
42 printf ("Could not read super block\n");
43 return 0;
45 printf("Filesystem volume name: %s\n", super.s_name);
46 printf("Filesystem magic number: 0x%x\n", swap_be32(super.s_magic));
47 printf("First block: 0x%llx\n", swap_be64(super.s_root_block));
48 printf("Block count: 0x%llx\n", swap_be64(super.s_num_blocks));
49 printf("Block size: %d\n", swap_be32(super.s_blocksize));
50 printf("Inode block size: %d\n", swap_be32(super.s_sys_blocksize));
51 printf("Mirrors: %d\n", swap_be32(super.s_mirrors));
52 putchar('\n');
54 if (omfs_read_root_block(&info))
56 printf ("Could not read root block\n");
57 return 0;
59 printf("Root block size: %d\n", swap_be32(info.root->r_blocksize));
60 printf("Cluster size: %d\n", swap_be32(info.root->r_clustersize));
61 printf("Root mirrors: %d\n", swap_be32(info.root->r_mirrors));
63 bsize = (swap_be64(info.super->s_num_blocks) + 7) / 8;
65 if (dirscan_begin(&info, on_node, NULL) != 0)
67 printf("Dirscan failed\n");
68 return 0;
70 return 1;