[Ocfs2-tools-commits] smushran commits r440 - in trunk/debugfs.ocfs2: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Nov 30 18:57:44 CST 2004


Author: smushran
Date: 2004-11-30 18:57:42 -0600 (Tue, 30 Nov 2004)
New Revision: 440

Modified:
   trunk/debugfs.ocfs2/Cscope.make
   trunk/debugfs.ocfs2/Makefile
   trunk/debugfs.ocfs2/commands.c
   trunk/debugfs.ocfs2/dump.c
   trunk/debugfs.ocfs2/include/dump.h
   trunk/debugfs.ocfs2/include/main.h
   trunk/debugfs.ocfs2/journal.c
   trunk/debugfs.ocfs2/main.c
Log:
debugfs libocfs2-fied

Modified: trunk/debugfs.ocfs2/Cscope.make
===================================================================
--- trunk/debugfs.ocfs2/Cscope.make	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/Cscope.make	2004-12-01 00:57:42 UTC (rev 440)
@@ -6,4 +6,5 @@
 	find . -maxdepth 2 -name '*.c' -print >>cscope.files
 	find . -maxdepth 2 -name '*.h' -print >>cscope.files
 	find ../libocfs2/ -maxdepth 2 -name '*.h' -print >>cscope.files
+	find ../libocfs2/ -maxdepth 2 -name '*.c' -print >>cscope.files
 	cscope -b

Modified: trunk/debugfs.ocfs2/Makefile
===================================================================
--- trunk/debugfs.ocfs2/Makefile	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/Makefile	2004-12-01 00:57:42 UTC (rev 440)
@@ -16,12 +16,12 @@
 CFLAGS = -Wall -O2
 endif
 
-CFILES = main.c commands.c dump.c readfs.c utils.c journal.c
+CFILES = main.c commands.c dump.c utils.c journal.c
+
 HFILES =			\
 	include/main.h		\
 	include/commands.h	\
 	include/dump.h		\
-	include/readfs.h	\
 	include/utils.h		\
 	include/jbd.h		\
 	include/journal.h

Modified: trunk/debugfs.ocfs2/commands.c
===================================================================
--- trunk/debugfs.ocfs2/commands.c	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/commands.c	2004-12-01 00:57:42 UTC (rev 440)
@@ -24,6 +24,7 @@
  */
 
 #include <main.h>
+#define SYSTEM_FILE_NAME_MAX   40
 
 typedef void (*PrintFunc) (void *buf);
 typedef gboolean (*WriteFunc) (char **data, void *buf);
@@ -57,29 +58,14 @@
 static void do_curdev (char **args);
 static void do_super (char **args);
 static void do_inode (char **args);
-static void do_config (char **args);
-static void do_publish (char **args);
-static void do_vote (char **args);
+static void do_dlm (char **args);
 static void do_journal (char **args);
 static void do_group (char **args);
-static void do_header (char **args);
+static void do_extent (char **args);
 
 extern gboolean allow_write;
 
-dbgfs_gbls gbls = {
-	.device = NULL,
-	.raw_minor = 0,
-	.dev_fd = -1,
-	.blksz_bits = 0,
-	.clstrsz_bits = 0,
-	.root_blkno = 0,
-	.sysdir_blkno = 0,
-	.dlm_blkno = 0,
-	.curdir = NULL,
-	.superblk = NULL,
-	.rootin = NULL,
-	.sysdirin = NULL
-};
+dbgfs_gbls gbls;
 
 static Command commands[] =
 {
@@ -115,14 +101,14 @@
   { "show_inode_info", do_inode },
   { "stat", do_inode },
 
-  { "nodes", do_config },
-  { "publish", do_publish },
-  { "vote", do_vote },
+  { "nodes", do_dlm },
+  { "publish", do_dlm },
+  { "vote", do_dlm },
 
   { "logdump", do_journal },
 
   { "group", do_group },
-  { "header", do_header }
+  { "extent", do_extent }
 };
 
 
@@ -166,86 +152,161 @@
 }					/* do_command */
 
 /*
+ * get_blknum()
+ *
+ */
+static errcode_t get_blknum(char *blkstr, uint64_t *blkno)
+{
+	errcode_t ret = OCFS2_ET_INVALID_ARGUMENT;
+	char *endptr;
+
+	if (blkstr) {
+		*blkno = strtoull(blkstr, &endptr, 0);
+		if (!*endptr) {
+			if (*blkno < gbls.max_blocks)
+				ret = 0;
+			else
+				printf("Block number is too large\n");
+		} else
+			printf("Invalid block number\n");
+	} else
+		printf("No block number specified\n");
+
+	return ret;
+}
+
+/*
+ * get_nodenum()
+ *
+ */
+static errcode_t get_nodenum(char *nodestr, uint16_t *nodenum)
+{
+	errcode_t ret = OCFS2_ET_INVALID_ARGUMENT;
+	ocfs2_super_block *sb = OCFS2_RAW_SB(gbls.fs->fs_super);
+	char *endptr;
+
+	if (nodestr) {
+		*nodenum = strtoul(nodestr, &endptr, 0);
+		if (!*endptr) {
+			if (*nodenum < sb->s_max_nodes)
+				ret = 0;
+			else
+				printf("node number is too large\n");
+		} else
+			printf("Invalid node number\n");
+	} else
+		printf("no node number specified\n");
+
+	return ret;
+}
+
+/*
+ * traverse_extents()
+ *
+ */
+static int traverse_extents (ocfs2_filesys *fs, ocfs2_extent_list *el, FILE *out)
+{
+	ocfs2_extent_block *eb;
+	ocfs2_extent_rec *rec;
+	errcode_t ret = 0;
+	char *buf = NULL;
+	int i;
+
+	dump_extent_list (out, el);
+
+	for (i = 0; i < el->l_next_free_rec; ++i) {
+		rec = &(el->l_recs[i]);
+		if (el->l_tree_depth) {
+			ret = ocfs2_malloc_block(gbls.fs->fs_io, &buf);
+			if (ret) {
+				com_err(gbls.progname, ret, "while allocating a block");
+				goto bail;
+			}
+
+			ret = ocfs2_read_extent_block(fs, rec->e_blkno, buf);
+			if (ret)
+				goto bail;
+
+			eb = (ocfs2_extent_block *)buf;
+
+			dump_extent_block (out, eb);
+
+			traverse_extents (fs, &(eb->h_list), out);
+		}
+	}
+
+bail:
+	if (buf)
+		ocfs2_free(&buf);
+	return ret;
+}				/* traverse_extents */
+
+/*
  * do_open()
  *
  */
 static void do_open (char **args)
 {
 	char *dev = args[1];
+	int flags;
+	errcode_t ret = 0;
+	char sysfile[SYSTEM_FILE_NAME_MAX];
+	int i;
 	ocfs2_super_block *sb;
-	char *buf = NULL;
-	__u32 len;
-	ocfs2_dinode *inode;
-	int flags;
 
 	if (gbls.device)
 		do_close (NULL);
 
 	if (dev == NULL) {
-		printf ("open requires a device argument\n");
+		printf ("no device specified\n");
 		goto bail;
 	}
 
-	flags = O_DIRECT | (allow_write ? O_RDONLY : O_RDWR);
-	gbls.dev_fd = open (dev, flags);
-	if (gbls.dev_fd == -1) {
-		printf ("could not open device %s\n", dev);
+	flags = allow_write ? OCFS2_FLAG_RW : OCFS2_FLAG_RO;
+	ret = ocfs2_open(dev, flags, 0, 0, &gbls.fs);
+	if (ret) {
+		gbls.fs = NULL;
+		com_err(gbls.progname, ret, "while opening \"%s\"", dev);
 		goto bail;
 	}
 
-	gbls.device = g_strdup (dev);
-
-	if (read_super_block (gbls.dev_fd, (char **)&gbls.superblk) != -1)
-		gbls.curdir = g_strdup ("/");
-	else {
-		close (gbls.dev_fd);
-		gbls.dev_fd = -1;
+	/* allocate blocksize buffer */
+	ret = ocfs2_malloc_block(gbls.fs->fs_io, &gbls.blockbuf);
+	if (ret) {
+		com_err(gbls.progname, ret, "while allocating a block");
 		goto bail;
 	}
 
-	sb = &(gbls.superblk->id2.i_super);
+	sb = OCFS2_RAW_SB(gbls.fs->fs_super);
+
 	/* set globals */
-	gbls.clstrsz_bits = sb->s_clustersize_bits;
-	gbls.blksz_bits = sb->s_blocksize_bits;
+	gbls.device = g_strdup (dev);
+	gbls.max_clusters = gbls.fs->fs_super->i_clusters;
+	gbls.max_blocks = ocfs2_clusters_to_blocks(gbls.fs, gbls.max_clusters);
 	gbls.root_blkno = sb->s_root_blkno;
 	gbls.sysdir_blkno = sb->s_system_dir_blkno;
 
-	/* read root inode */
-	len = 1 << gbls.blksz_bits;
-	if (!(gbls.rootin = memalign(len, len)))
-		DBGFS_FATAL("%s", strerror(errno));
-	if ((pread64(gbls.dev_fd, (char *)gbls.rootin, len,
-		     (gbls.root_blkno << gbls.blksz_bits))) == -1)
-		DBGFS_FATAL("%s", strerror(errno));
+	/* lookup dlm file */
+	snprintf (sysfile, sizeof(sysfile),
+		  sysfile_info[DLM_SYSTEM_INODE].name);
+	ret = ocfs2_lookup(gbls.fs, gbls.sysdir_blkno, sysfile,
+			   strlen(sysfile), NULL, &gbls.dlm_blkno);
+	if (ret)
+		gbls.dlm_blkno = 0;
 
-	/* read sysdir inode */
-	len = 1 << gbls.blksz_bits;
-	if (!(gbls.sysdirin = memalign(len, len)))
-		DBGFS_FATAL("%s", strerror(errno));
-	if ((pread64(gbls.dev_fd, (char *)gbls.sysdirin, len,
-		     (gbls.sysdir_blkno << gbls.blksz_bits))) == -1)
-		DBGFS_FATAL("%s", strerror(errno));
-
-	/* load sysfiles blknums */
-	read_sysdir (gbls.dev_fd, (char *)gbls.sysdirin);
-
-	/* get the max clusters/blocks */
-	len = 1 << gbls.blksz_bits;
-	if (!(buf = memalign(len, len)))
-		DBGFS_FATAL("%s", strerror(errno));
-
-	if (!read_inode (gbls.dev_fd, gbls.gblbm_blkno, buf, len)) {
-		inode = (ocfs2_dinode *)buf;
-		if (inode->i_flags & OCFS2_BITMAP_FL) {
-			gbls.max_clusters = inode->id1.bitmap1.i_total;
-			gbls.max_blocks = gbls.max_clusters <<
-					(gbls.clstrsz_bits - gbls.blksz_bits);
-		}
+	/* lookup journal files */
+	for (i = 0; i < sb->s_max_nodes; ++i) {
+		snprintf (sysfile, sizeof(sysfile),
+			  sysfile_info[JOURNAL_SYSTEM_INODE].name, i);
+		ret = ocfs2_lookup(gbls.fs, gbls.sysdir_blkno, sysfile,
+				   strlen(sysfile), NULL, &gbls.jrnl_blkno[i]);
+		if (ret)
+			gbls.jrnl_blkno[i] = 0;
 	}
 
 bail:
-	safefree(buf);
 	return ;
+	
 }					/* do_open */
 
 /*
@@ -254,21 +315,24 @@
  */
 static void do_close (char **args)
 {
-	if (gbls.device) {
-		g_free (gbls.device);
-		gbls.device = NULL;
-		close (gbls.dev_fd);
-		gbls.dev_fd = -1;
+	errcode_t ret = 0;
 
-		g_free (gbls.curdir);
-		gbls.curdir = NULL;
-
-		safefree (gbls.superblk);
-		safefree (gbls.rootin);
-		safefree (gbls.sysdirin);
-	} else
+	if (!gbls.device) {
 		printf ("device not open\n");
+		return ;
+	}
 
+	ret = ocfs2_close(gbls.fs);
+	if (ret)
+		com_err(gbls.progname, ret, "while closing \"%s\"", gbls.device);
+	gbls.fs = NULL;
+
+	if (gbls.blockbuf)
+		ocfs2_free(&gbls.blockbuf);
+
+	g_free (gbls.device);
+	gbls.device = NULL;
+
 	return ;
 }					/* do_close */
 
@@ -287,58 +351,52 @@
  */
 static void do_ls (char **args)
 {
-	char *opts = args[1];
-	ocfs2_dinode *inode;
-	__u32 blknum;
+	ocfs2_dinode *di;
+	uint64_t blkno;
 	char *buf = NULL;
-	GArray *dirarr = NULL;
-	__u32 len;
-	FILE *out;
+	FILE *out = NULL;
+	errcode_t ret = 0;
 
-	if (gbls.dev_fd == -1) {
+	if (!gbls.fs) {
 		printf ("device not open\n");
 		goto bail;
 	}
 
-	len = 1 << gbls.blksz_bits;
-	if (!(buf = memalign(len, len)))
-		DBGFS_FATAL("%s", strerror(errno));
+	ret = get_blknum(args[1], &blkno);
+	if (ret)
+		goto bail;
 
-	if (opts) {
-		blknum = atoi(opts);
-		if (blknum > gbls.max_blocks) {
-			printf("block number is too large\n");
-			goto bail;
-		}
-		if ((read_inode (gbls.dev_fd, blknum, buf, len)) == -1) {
-			printf("Not an inode\n");
-			goto bail;
-		}
-		inode = (ocfs2_dinode *)buf;
-	} else {
-		inode = gbls.rootin;
+	buf = gbls.blockbuf;
+	ret = ocfs2_read_inode(gbls.fs, blkno, buf);
+	if (ret) {
+		com_err(gbls.progname, ret, "while reading inode %"PRIu64, blkno);
+		goto bail;
 	}
 
-	if (!S_ISDIR(inode->i_mode)) {
+	di = (ocfs2_dinode *)buf;
+
+	if (!S_ISDIR(di->i_mode)) {
 		printf("Not a dir\n");
 		goto bail;
 	}
 
-	dirarr = g_array_new(0, 1, sizeof(struct ocfs2_dir_entry));
+	out = open_pager ();
+	fprintf(out, "\t%-15s %-4s %-4s %-2s %-4s\n",
+		"Inode", "Rlen", "Nlen", "Ty", "Name");
 
-	read_dir (gbls.dev_fd, &(inode->id2.i_list), inode->i_size, dirarr);
+	ret = ocfs2_dir_iterate(gbls.fs, blkno, 0, NULL,
+				dump_dir_entry, out);
+	if (ret) {
+		com_err(gbls.progname, ret,
+			"while listing inode %"PRIu64" on \"%s\"\n",
+			blkno, gbls.device);
+		goto bail;
+	}
 
-	out = open_pager ();
-	dump_dir_entry (out, dirarr);
+bail:
 	close_pager (out);
-	
-bail:
-	safefree (buf);
 
-	if (dirarr)
-		g_array_free (dirarr, 1);
 	return ;
-
 }					/* do_ls */
 
 /*
@@ -414,6 +472,8 @@
 	printf ("publish\t\t\t\tPublish blocks\n");
 	printf ("vote\t\t\t\tVote blocks\n");
 	printf ("logdump <nodenum>\t\tPrints journal file for the node\n");
+	printf ("extent <blknum>\t\t\tShow extent block\n");
+	printf ("group <blknum>\t\t\tShow chain group\n");
 	printf ("help, ?\t\t\t\tThis information\n");
 	printf ("quit, q\t\t\t\tExit the program\n");
 }					/* do_help */
@@ -454,19 +514,18 @@
 static void do_super (char **args)
 {
 	char *opts = args[1];
+	FILE *out;
 	ocfs2_dinode *in;
 	ocfs2_super_block *sb;
-	FILE *out;
 
-	if (gbls.dev_fd == -1) {
+	if (!gbls.fs) {
 		printf ("device not open\n");
 		goto bail;
 	}
 
 	out = open_pager ();
-
-	in = gbls.superblk;
-	sb = &(in->id2.i_super);
+	in = gbls.fs->fs_super;
+	sb = OCFS2_RAW_SB(gbls.fs->fs_super);
 	dump_super_block(out, sb);
 
 	if (!opts || strncmp(opts, "-h", 2))
@@ -484,37 +543,31 @@
  */
 static void do_inode (char **args)
 {
-	char *opts = args[1];
 	ocfs2_dinode *inode;
-	__u32 blknum;
+	uint64_t blkno;
 	char *buf = NULL;
-	__u32 buflen;
 	FILE *out;
+	errcode_t ret = 0;
 
-	if (gbls.dev_fd == -1) {
+	if (!gbls.fs) {
 		printf ("device not open\n");
 		goto bail;
 	}
 
-	buflen = 1 << gbls.blksz_bits;
-	if (!(buf = memalign(buflen, buflen)))
-		DBGFS_FATAL("%s", strerror(errno));
+	ret = get_blknum(args[1], &blkno);
+	if (ret)
+		goto bail;
 
-	if (opts) {
-		blknum = atoi(opts);
-		if (blknum > gbls.max_blocks) {
-			printf("block number is too large\n");
-			goto bail;
-		}
-		if ((read_inode (gbls.dev_fd, blknum, buf, buflen)) == -1) {
-			printf("Not an inode\n");
-			goto bail;
-		}
-		inode = (ocfs2_dinode *)buf;
-	} else {
-		inode = gbls.rootin;
+	buf = gbls.blockbuf;
+	ret = ocfs2_read_inode(gbls.fs, blkno, buf);
+	if (ret) {
+		com_err(gbls.progname, ret,
+			"while reading inode in block %"PRIu64, blkno);
+		goto bail;
 	}
 
+	inode = (ocfs2_dinode *)buf;
+
 	out = open_pager();
 	dump_inode(out, inode);
 
@@ -523,86 +576,57 @@
 	else if ((inode->i_flags & OCFS2_CHAIN_FL))
 		dump_chain_list(out, &(inode->id2.i_chain));
 	else
-		traverse_extents(gbls.dev_fd, &(inode->id2.i_list), NULL, 1, out);
+		traverse_extents(gbls.fs, &(inode->id2.i_list), out);
 
-	close_pager (out);
+	close_pager(out);
 
 bail:
-	safefree (buf);
+
 	return ;
 }					/* do_inode */
 
 /*
- * do_config()
+ * do_dlm()
  *
  */
-static void do_config (char **args)
+static void do_dlm (char **args)
 {
 	char *dlmbuf = NULL;
 	FILE *out;
+	int len;
+	errcode_t ret;
+	void (*dump_func) (FILE *out, char *buf);
 
-	if (gbls.dev_fd == -1)
+	if (!gbls.fs) {
 		printf ("device not open\n");
-	else {
-		if (read_file (gbls.dev_fd, gbls.dlm_blkno, -1, &dlmbuf) == -1)
-			goto bail;
-		out = open_pager ();
-		dump_config (out, dlmbuf);
-		close_pager (out);
+		goto bail;
 	}
 
-bail:
-	safefree (dlmbuf);
-	return ;
-}					/* do_config */
+	if (!strcasecmp(args[0], "nodes"))
+		dump_func = dump_config;
+	else if (!strcasecmp(args[0], "publish"))
+		dump_func = dump_publish;
+	else if (!strcasecmp(args[0], "vote"))
+		dump_func = dump_vote;
+	else
+		DBGFS_FATAL("internal");
 
-/*
- * do_publish()
- *
- */
-static void do_publish (char **args)
-{
-	char *dlmbuf = NULL;
-	FILE *out;
-
-	if (gbls.dev_fd == -1)
-		printf ("device not open\n");
-	else {
-		if (read_file (gbls.dev_fd, gbls.dlm_blkno, -1, &dlmbuf) == -1)
-			goto bail;
-		out = open_pager ();
-		dump_publish (out, dlmbuf);
-		close_pager (out);
+	ret = ocfs2_read_whole_file(gbls.fs, gbls.dlm_blkno, &dlmbuf, &len);
+	if (ret) {
+		com_err(gbls.progname, ret, "while reading dlm file");
+		goto bail;
 	}
 
+	out = open_pager();
+	dump_func(out, dlmbuf);
+	close_pager(out);
+
 bail:
-	safefree (dlmbuf);
-	return ;
-}					/* do_publish */
+	if (dlmbuf)
+		ocfs2_free(&dlmbuf);
 
-/*
- * do_vote()
- *
- */
-static void do_vote (char **args)
-{
-	char *dlmbuf = NULL;
-	FILE *out;
-	
-	if (gbls.dev_fd == -1)
-		printf ("device not open\n");
-	else {
-		if (read_file (gbls.dev_fd, gbls.dlm_blkno, -1, &dlmbuf) == -1)
-			goto bail;
-		out = open_pager ();
-		dump_vote (out, dlmbuf);
-		close_pager (out);
-	}
-
-bail:
-	safefree (dlmbuf);
 	return ;
-}					/* do_vote */
+}					/* do_dlm */
 
 /*
  * do_dump()
@@ -610,14 +634,15 @@
  */
 static void do_dump (char **args)
 {
-	__u64 blknum = 0;
-	__s32 outfd = -1;
+	uint64_t blkno = 0;
+	int32_t outfd = -1;
 	FILE *out = NULL;
 	int flags;
 	int op = 0;  /* 0 = dump, 1 = cat */
 	char *outfile = NULL;
+	errcode_t ret;
 
-	if (gbls.dev_fd == -1) {
+	if (!gbls.fs == -1) {
 		printf ("device not open\n");
 		goto bail;
 	}
@@ -628,10 +653,8 @@
 		op = 1;
 	}
 
-	if (args[1])
-		blknum = strtoull (args[1], NULL, 0);
-
-	if (!blknum)
+	ret = get_blknum(args[1], &blkno);
+	if (ret)
 		goto bail;
 
 	if (args[2]) {
@@ -643,8 +666,10 @@
 			goto bail;
 		}
 	}
-
+#if 0
+	/* TODO */
 	read_file (gbls.dev_fd, blknum, outfd, NULL);
+#endif
 
 bail:
 	if (out) {
@@ -665,40 +690,37 @@
 static void do_journal (char **args)
 {
 	char *logbuf = NULL;
-	__u64 blknum = 0;
-	__s32 len = 0;
+	uint64_t blkno = 0;
+	int32_t len = 0;
 	FILE *out;
-	__u32 nodenum;
-	ocfs2_super_block *sb = &(gbls.superblk->id2.i_super);
+	uint16_t nodenum;
+	errcode_t ret = 0;
 
-	if (gbls.dev_fd == -1) {
+	if (!gbls.fs) {
 		printf ("device not open\n");
 		goto bail;
 	}
 
-	if (args[1])
-		nodenum = strtoull (args[1], NULL, 0);
-	else {
-		printf ("No node number specified\n");
+	ret = get_nodenum(args[1], &nodenum);
+	if (ret)
 		goto bail;
-	}
 
-	if (nodenum >= sb->s_max_nodes) {
-		printf ("Invalid node number specified\n");
+	blkno = gbls.jrnl_blkno[nodenum];
+
+	ret = ocfs2_read_whole_file(gbls.fs, blkno, &logbuf, &len);
+	if (ret) {
+		com_err(gbls.progname, ret, "while reading journal file");
 		goto bail;
 	}
 
-	blknum = gbls.journal_blkno[nodenum];
-
-	if ((len = read_file (gbls.dev_fd, blknum, -1, &logbuf)) == -1)
-		goto bail;
-
 	out = open_pager ();
-	read_journal (out, logbuf, (__u64)len);
+	read_journal (out, logbuf, (uint64_t)len);
 	close_pager (out);
 
 bail:
-	safefree (logbuf);
+	if (logbuf)
+		ocfs2_free(&logbuf);
+
 	return ;
 }					/* do_journal */
 
@@ -708,90 +730,69 @@
  */
 static void do_group (char **args)
 {
-	char *opts = args[1];
 	ocfs2_group_desc *bg;
-	__u32 blknum;
+	uint64_t blkno;
 	char *buf = NULL;
-	__u32 buflen;
 	FILE *out;
+	errcode_t ret = 0;
 
-	if (gbls.dev_fd == -1) {
+	if (!gbls.fs) {
 		printf ("device not open\n");
 		goto bail;
 	}
 
-	buflen = 1 << gbls.blksz_bits;
-	if (!(buf = memalign(buflen, buflen)))
-		DBGFS_FATAL("%s", strerror(errno));
+	ret = get_blknum(args[1], &blkno);
+	if (ret)
+		goto bail;
 
-	if (!opts) {
-		printf("no block number specified\n");
+	buf = gbls.blockbuf;
+	ret = ocfs2_read_group_desc(gbls.fs, blkno, buf);
+	if (ret) {
+		com_err(gbls.progname, ret,
+			"while reading chain group in block %"PRIu64, blkno);
 		goto bail;
 	}
 
-	blknum = atoi(opts);
-	if (blknum > gbls.max_blocks) {
-		printf("block number is too large\n");
-		goto bail;
-	}
-	if ((read_group (gbls.dev_fd, blknum, buf, buflen)) == -1) {
-		printf("Not a group descriptor\n");
-		goto bail;
-	}
 	bg = (ocfs2_group_desc *)buf;
 
 	out = open_pager();
 	dump_group_descriptor(out, bg);
-
 	close_pager (out);
 
 bail:
-	safefree (buf);
+
 	return ;
 }					/* do_group */
 
 /*
- * do_header()
+ * do_extent()
  *
  */
-static void do_header (char **args)
+static void do_extent (char **args)
 {
-	char *opts = args[1];
 	ocfs2_extent_block *eb;
-	__u32 blknum;
+	uint64_t blkno;
 	char *buf = NULL;
-	__u32 buflen;
 	FILE *out;
-	__u64 off;
+	errcode_t ret = 0;
 
-	if (gbls.dev_fd == -1) {
+	if (!gbls.fs) {
 		printf ("device not open\n");
 		goto bail;
 	}
 
-	buflen = 1 << gbls.blksz_bits;
-	if (!(buf = memalign(buflen, buflen)))
-		DBGFS_FATAL("%s", strerror(errno));
-
-	if (!opts) {
-		printf("no block number specified\n");
+	ret = get_blknum(args[1], &blkno);
+	if (ret)
 		goto bail;
-	}
 
-	blknum = atoi(opts);
-	if (blknum > gbls.max_blocks) {
-		printf("block number is too large\n");
+	buf = gbls.blockbuf;
+	ret = ocfs2_read_extent_block(gbls.fs, blkno, buf);
+	if (ret) {
+		com_err(gbls.progname, ret,
+			"while reading extent in block %"PRIu64, blkno);
 		goto bail;
 	}
 
-	off = blknum << gbls.blksz_bits;
-	if ((pread64 (gbls.dev_fd, buf, buflen, off)) == -1) {
-		printf("error reading block!\n");
-		goto bail;
-	}
-
-	out = open_pager();
-
 	eb = (ocfs2_extent_block *)buf;
 	if (memcmp(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE,
 		   sizeof(OCFS2_EXTENT_BLOCK_SIGNATURE))) {
@@ -799,15 +800,15 @@
 		goto bail;
 	}
 
+	out = open_pager();
 	dump_extent_block(out, eb);
 	dump_extent_list(out, &eb->h_list);
+	close_pager(out);
 
-	close_pager (out);
+bail:
 
-bail:
-	safefree (buf);
 	return ;
-}					/* do_header */
+}					/* do_extent */
 
 /*
  * handle_signal()

Modified: trunk/debugfs.ocfs2/dump.c
===================================================================
--- trunk/debugfs.ocfs2/dump.c	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/dump.c	2004-12-01 00:57:42 UTC (rev 440)
@@ -24,7 +24,6 @@
  */
 
 #include <main.h>
-#include <inttypes.h>
 
 extern dbgfs_gbls gbls;
 
@@ -198,7 +197,7 @@
 }				/* dump_disk_lock */
 
 /*
- * dump_extent_list()
+ * dump_chain_list()
  *
  */
 void dump_chain_list (FILE *out, ocfs2_chain_list *cl)
@@ -267,28 +266,40 @@
 	return ;
 }				/* dump_extent_block */
 
-void traverse_chain(FILE *out, __u64 blknum)
+/*
+ * traverse_chain()
+ *
+ */
+void traverse_chain(FILE *out, __u64 blkno)
 {
 	ocfs2_group_desc *bg;
 	char *buf = NULL;
-	__u32 buflen;
+	errcode_t ret = 0;
 
-	buflen = 1 << gbls.blksz_bits;
-	if (!(buf = memalign(buflen, buflen)))
-		DBGFS_FATAL("%s", strerror(errno));
+	ret = ocfs2_malloc_block(gbls.fs->fs_io, &buf);
+	if (ret) {
+		com_err(gbls.progname, ret, "while allocating a block");
+		goto bail;
+	}
 
 	do {
-		if ((read_group (gbls.dev_fd, blknum, buf, buflen)) == -1) {
-			printf("Not a group descriptor\n");
+		ret = ocfs2_read_group_desc(gbls.fs, blkno, buf);
+		if (ret) {
+			com_err(gbls.progname, ret,
+				"while reading chain group in block %"PRIu64, blkno);
 			goto bail;
 		}
+
 		bg = (ocfs2_group_desc *)buf;
+
 		dump_group_descriptor(out, bg);
-		blknum = bg->bg_next_group;
-	} while (blknum);
+		blkno = bg->bg_next_group;
+	} while (blkno);
 	
 bail:
-	safefree (buf);
+	if (buf)
+		ocfs2_free(&buf);
+
 	return ;
 }
 
@@ -322,23 +333,20 @@
  * dump_dir_entry()
  *
  */
-void dump_dir_entry (FILE *out, GArray *arr)
+int  dump_dir_entry (struct ocfs2_dir_entry *rec, int offset, int blocksize,
+		     char *buf, void *priv_data)
 {
-	struct ocfs2_dir_entry *rec;
-	int i;
+	FILE *out = priv_data;
+	char tmp = rec->name[rec->name_len];
 
-	fprintf(out, "\t%-15s %-4s %-4s %-2s %-4s\n",
-		"Inode", "Rlen", "Nlen", "Ty", "Name");
-
-	for (i = 0; i < arr->len; ++i) {
-		rec = &(g_array_index(arr, struct ocfs2_dir_entry, i));
-		fprintf(out, "\t%-15"PRIu64" %-4u %-4u %-2u %s\n",
+	rec->name[rec->name_len] = '\0';
+	fprintf(out, "\t%-15"PRIu64" %-4u %-4u %-2u %s\n",
 			rec->inode, rec->rec_len,
 			rec->name_len, rec->file_type, rec->name);
-	}
+	rec->name[rec->name_len] = tmp;
 
-	return ;
-}				/* dump_dir_entry */
+	return 0;
+}
 
 /*
  * dump_config()
@@ -349,7 +357,7 @@
 	char *p;
 	ocfs_node_config_hdr *hdr;
 	ocfs_node_config_info *node;
-	ocfs2_super_block *sb = &((gbls.superblk)->id2.i_super);
+	ocfs2_super_block *sb = OCFS2_RAW_SB(gbls.fs->fs_super);
 	__u16 port;
 	char addr[32];
 	struct in_addr ina;
@@ -366,7 +374,7 @@
 	fprintf(out, "\t%-3s %-32s %-15s %-6s %s\n",
 		"###", "Name", "IP Address", "Port", "UUID");
 
-	p = buf + (2 << gbls.blksz_bits);
+	p = buf + (2 << sb->s_blocksize_bits);
 	for (i = 0; i < sb->s_max_nodes; ++i) {
 		node = (ocfs_node_config_info *)p;
 		if (!*node->node_name)
@@ -382,7 +390,7 @@
 		for (j = 0; j < OCFS2_GUID_LEN; j++)
 			fprintf(out, "%c", node->guid.guid[j]);
 		fprintf(out, "\n");
-		p += (1 << gbls.blksz_bits);
+		p += (1 << sb->s_blocksize_bits);
 	}
 
 	return ;
@@ -397,14 +405,14 @@
 	ocfs_publish *pub;
 	char *p;
 	GString *pub_flag;
-	ocfs2_super_block *sb = &((gbls.superblk)->id2.i_super);
+	ocfs2_super_block *sb = OCFS2_RAW_SB(gbls.fs->fs_super);
 	__u32 i, j;
 
 	fprintf(out, "\t%-3s %-3s %-3s %-3s %-15s %-15s %-15s %-15s %-*s %-s\n",
 		"###", "Mnt", "Vot", "Dty", "LockId", "Seq", "Comm Seq", "Time",
 		sb->s_max_nodes, "Map", "Type");
 
-	p = buf + ((2 + 4 + sb->s_max_nodes) << gbls.blksz_bits);
+	p = buf + ((2 + 4 + sb->s_max_nodes) << sb->s_blocksize_bits);
 	for (i = 0; i < sb->s_max_nodes; ++i) {
 		pub = (ocfs_publish *)p;
 
@@ -425,10 +433,10 @@
 
 		g_string_free (pub_flag, 1);
 
-		p += (1 << gbls.blksz_bits);
+		p += (1 << sb->s_blocksize_bits);
 	}
 
-	return ;	
+	return ;
 }				/* dump_publish */
 
 /*
@@ -440,13 +448,13 @@
 	ocfs_vote *vote;
 	char *p;
 	GString *vote_flag;
-	ocfs2_super_block *sb = &((gbls.superblk)->id2.i_super);
+	ocfs2_super_block *sb = OCFS2_RAW_SB(gbls.fs->fs_super);
 	__u32 i;
 
 	fprintf(out, "\t%-3s %-2s %-1s %-15s %-15s %-s\n",
 		"###", "NV", "O", "LockId", "Seq", "Type");
 
-	p = buf + ((2 + 4 + sb->s_max_nodes + sb->s_max_nodes) << gbls.blksz_bits);
+	p = buf + ((2 + 4 + sb->s_max_nodes + sb->s_max_nodes) << sb->s_blocksize_bits);
 	for (i = 0; i < sb->s_max_nodes; ++i) {
 		vote = (ocfs_vote *)p;
 
@@ -458,7 +466,7 @@
 			vote->vote_seq_num, vote_flag->str);
 
 		g_string_free (vote_flag, 1);
-		p += (1 << gbls.blksz_bits);
+		p += (1 << sb->s_blocksize_bits);
 	}
 
 	return ;
@@ -540,6 +548,7 @@
 	char *blk = (char *) header;
 	__u32 *blocknr;
 	char *uuid;
+	ocfs2_super_block *sb = OCFS2_RAW_SB(gbls.fs->fs_super);
 
 	tagflg = g_string_new (NULL);
 
@@ -552,7 +561,7 @@
 
 		fprintf (out, "\t%3s %-15s %-s\n", "No.", "Blocknum", "Flags");
 
-		for (i = sizeof(journal_header_t); i < (1 << gbls.blksz_bits);
+		for (i = sizeof(journal_header_t); i < (1 << sb->s_blocksize_bits);
 		     i+=sizeof(journal_block_tag_t)) {
 			tag = (journal_block_tag_t *) &blk[i];
 

Modified: trunk/debugfs.ocfs2/include/dump.h
===================================================================
--- trunk/debugfs.ocfs2/include/dump.h	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/include/dump.h	2004-12-01 00:57:42 UTC (rev 440)
@@ -34,7 +34,8 @@
 void dump_chain_list (FILE *out, ocfs2_chain_list *cl);
 void dump_extent_block (FILE *out, ocfs2_extent_block *blk);
 void dump_group_descriptor (FILE *out, ocfs2_group_desc *blk);
-void dump_dir_entry (FILE *out, GArray *arr);
+int  dump_dir_entry (struct ocfs2_dir_entry *rec, int offset, int blocksize,
+		     char *buf, void *priv_data);
 void dump_config (FILE *out, char *buf);
 void dump_publish (FILE *out, char *buf);
 void dump_vote (FILE *out, char *buf);

Modified: trunk/debugfs.ocfs2/include/main.h
===================================================================
--- trunk/debugfs.ocfs2/include/main.h	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/include/main.h	2004-12-01 00:57:42 UTC (rev 440)
@@ -46,6 +46,7 @@
 #include <signal.h>
 #include <sys/raw.h>
 #include <linux/kdev_t.h>
+#include <inttypes.h>
 
 #include <glib.h>
 
@@ -54,6 +55,7 @@
 
 #include <linux/types.h>
 
+#include "ocfs2.h"
 #include "ocfs2_fs.h"
 #include "ocfs2_disk_dlm.h"
 #include "ocfs1_fs_compat.h"
@@ -65,28 +67,20 @@
 };
 
 typedef struct _dbgfs_glbs {
+	char *progname;
 	char *device;
-	int raw_minor;
-	int dev_fd;
-	__u32 blksz_bits;
-	__u32 clstrsz_bits;
-	__u64 root_blkno;
-	__u64 sysdir_blkno;
-	__u64 dlm_blkno;
-	__u64 gblbm_blkno;
-	__u64 journal_blkno[256];
-	__u64 max_clusters;
-	__u64 max_blocks;
+	ocfs2_filesys *fs;
 	char *curdir;
-	ocfs2_dinode *superblk;
-	ocfs2_dinode *rootin;
-	ocfs2_dinode *sysdirin;
+	char *blockbuf;
+	uint64_t max_clusters;
+	uint64_t max_blocks;
+	uint64_t root_blkno;
+	uint64_t sysdir_blkno;
+	uint64_t dlm_blkno;
+	uint64_t gblbm_blkno;
+	uint64_t jrnl_blkno[256];
 } dbgfs_gbls;
 
-void *memalign(size_t boundary, size_t size);
-
-#define safefree(_p)	do {if (_p) { free(_p); (_p) = NULL; } } while (0)
-
 #define DBGFS_FATAL(fmt, arg...)	({ fprintf(stderr, "ERROR at %s, %d: " fmt ".  EXITING!!!\n", \
 						   __FILE__, __LINE__, ##arg);  \
 					   raise (SIGTERM);	\
@@ -149,7 +143,7 @@
 
 /* remaining headers */
 #include <commands.h>
-#include <readfs.h>
+#include <kernel-list.h>
 #include <utils.h>
 #include <journal.h>
 #include <dump.h>

Modified: trunk/debugfs.ocfs2/journal.c
===================================================================
--- trunk/debugfs.ocfs2/journal.c	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/journal.c	2004-12-01 00:57:42 UTC (rev 440)
@@ -36,7 +36,7 @@
 	char *block;
 	__u64 blocknum;
 	journal_header_t *header;
-	__u32 blksize = 1 << gbls.blksz_bits;
+	__u32 blksize = 1 << OCFS2_RAW_SB(gbls.fs->fs_super)->s_blocksize_bits;
 	__u64 len;
 	char *p;
 	__u64 last_unknown = 0;

Modified: trunk/debugfs.ocfs2/main.c
===================================================================
--- trunk/debugfs.ocfs2/main.c	2004-11-25 08:14:22 UTC (rev 439)
+++ trunk/debugfs.ocfs2/main.c	2004-12-01 00:57:42 UTC (rev 440)
@@ -32,6 +32,7 @@
 static char *get_line      (void);
 
 gboolean allow_write = FALSE;
+extern dbgfs_gbls gbls;
 
 /*
  * usage()
@@ -83,7 +84,6 @@
 	char *device = NULL;
 	char *arg;
 	gboolean seen_device = FALSE;
-	char *progname;
 
 #define INSTALL_SIGNAL(sig)					\
 	do {							\
@@ -96,8 +96,10 @@
 	INSTALL_SIGNAL(SIGTERM);
 	INSTALL_SIGNAL(SIGINT);
 
-	progname = basename(argv[0]);
-	
+	memset(&gbls, 0, sizeof(gbls));
+
+	gbls.progname = basename(argv[0]);
+
 	for (i = 1; i < argc; i++) {
 		arg = argv[i];
 		if ((strcmp (arg, "--write") == 0) ||
@@ -105,7 +107,7 @@
 			allow_write = TRUE;
 		} else if ((strcmp (arg, "--version") == 0) ||
 			   (strcmp (arg, "-V") == 0)) {
-			print_version (progname);
+			print_version (gbls.progname);
 			exit (0);
 		} else if ((strcmp (arg, "--help") == 0) ||
 			   (strcmp (arg, "-?") == 0)) {
@@ -120,7 +122,7 @@
 		}
 	}
 
-	print_version (progname);
+	print_version (gbls.progname);
 
 	if (device) {
 		line = g_strdup_printf ("open %s", device);



More information about the Ocfs2-tools-commits mailing list