From da83c964d3a7cc597ce1b0b0a1c4a28dd4df6e6e Mon Sep 17 00:00:00 2001 From: Bob Copeland Date: Fri, 19 Sep 2008 21:18:03 -0400 Subject: [PATCH] Add dump program to the repo --- dump.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dump.h | 6 ++++++ omfsdump.c | 26 +++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 dump.c create mode 100644 dump.h create mode 100644 omfsdump.c diff --git a/dump.c b/dump.c new file mode 100644 index 0000000..e266295 --- /dev/null +++ b/dump.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include "omfs.h" +#include "dirscan.h" +#include "check.h" +#include "crc.h" +#include "fix.h" +#include "bits.h" +#include "io.h" + +static int on_node(dirscan_t *d, dirscan_entry_t *entry, void *user) +{ + char *name = escape(entry->inode->i_name); + + printf("inode: %*c%s%c s:%llx h:%d c:%d p:%llx b:%llx\n", + entry->level*2, ' ', name, + (entry->inode->i_type == OMFS_DIR) ? '/' : ' ', + swap_be64(entry->inode->i_head.h_self), entry->hindex, + swap_be16(entry->inode->i_head.h_crc), + entry->parent, entry->block); + free(name); + + return 0; +} + +int dump_fs(FILE *fp) +{ + int bsize; + omfs_super_t super; + omfs_root_t root; + omfs_info_t info = { + .dev = fp, + .super = &super, + .root = &root + }; + + if (omfs_read_super(&info)) + { + printf ("Could not read super block\n"); + return 0; + } + printf("Filesystem volume name: %s\n", super.s_name); + printf("Filesystem magic number: 0x%x\n", swap_be32(super.s_magic)); + printf("First block: 0x%llx\n", swap_be64(super.s_root_block)); + printf("Block count: 0x%llx\n", swap_be64(super.s_num_blocks)); + printf("Block size: %d\n", swap_be32(super.s_blocksize)); + printf("Inode block size: %d\n", swap_be32(super.s_sys_blocksize)); + printf("Mirrors: %d\n", swap_be32(super.s_mirrors)); + putchar('\n'); + + if (omfs_read_root_block(&info)) + { + printf ("Could not read root block\n"); + return 0; + } + printf("Root block size: %d\n", swap_be32(info.root->r_blocksize)); + printf("Cluster size: %d\n", swap_be32(info.root->r_clustersize)); + printf("Root mirrors: %d\n", swap_be32(info.root->r_mirrors)); + + bsize = (swap_be64(info.super->s_num_blocks) + 7) / 8; + + if (dirscan_begin(&info, on_node, NULL) != 0) + { + printf("Dirscan failed\n"); + return 0; + } + return 1; +} diff --git a/dump.h b/dump.h new file mode 100644 index 0000000..53e1d51 --- /dev/null +++ b/dump.h @@ -0,0 +1,6 @@ +#ifndef _DUMP_H +#define _DUMP_H +#include + +int dump_fs(FILE *fp); +#endif diff --git a/omfsdump.c b/omfsdump.c new file mode 100644 index 0000000..615e9d1 --- /dev/null +++ b/omfsdump.c @@ -0,0 +1,26 @@ +/* + * Filesystem check for OMFS + */ +#include +#include "dump.h" + +int main(int argc, char *argv[]) +{ + FILE *fp; + + if (argc < 2) + { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + fp = fopen(argv[1], "rb"); + if (!fp) + { + perror("omfsdump: "); + exit(2); + } + + dump_fs(fp); + return 0; +} -- 2.11.4.GIT