[Ocfs2-tools-devel] [PATCH 4/4] Enable debugfs.ocfs2 to recognize image-file

Srinivas Eeda srinivas.eeda at oracle.com
Wed Mar 5 19:00:53 PST 2008


Signed-off-by: Srinivas Eeda <srinivas.eeda at oracle.com>
---
 debugfs.ocfs2/commands.c         |   54 ++++++++++++++++++++++++++++---------
 debugfs.ocfs2/debugfs.ocfs2.8.in |    5 +++
 debugfs.ocfs2/include/main.h     |    2 +
 debugfs.ocfs2/main.c             |   12 +++++++-
 4 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index ed93759..df07b9f 100644
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -24,6 +24,7 @@
  */
 
 #include "main.h"
+#include "ocfs2/o2image.h"
 #include "ocfs2/byteorder.h"
 
 #define SYSTEM_FILE_NAME_MAX	40
@@ -299,7 +300,8 @@ static int process_inodestr_args(char **args, int count, uint64_t *blkno)
 /* open the device, read the block from the device and get the
  * blocksize from the offset of the ocfs2_super_block.
  */
-static errcode_t get_blocksize(char* dev, uint64_t offset, uint64_t *blocksize)
+static errcode_t get_blocksize(char* dev, uint64_t offset, uint64_t *blocksize,
+		int super_no)
 {
 	errcode_t ret;
 	uint64_t blkno;
@@ -307,6 +309,7 @@ static errcode_t get_blocksize(char* dev, uint64_t offset, uint64_t *blocksize)
 	char *buf = NULL;
 	io_channel* channel = NULL;
 	struct ocfs2_dinode *di = NULL;
+	struct o2image_hdr *hdr;
 
 	ret = io_open(dev, OCFS2_FLAG_RO, &channel);
 	if (ret)
@@ -324,6 +327,19 @@ static errcode_t get_blocksize(char* dev, uint64_t offset, uint64_t *blocksize)
 	if (ret)
 		goto bail;
 
+	if (gbls.imagefile) {
+		ret = io_read_block(channel, 0, 1, buf);
+		if (ret)
+			goto bail;
+		hdr = (struct o2image_hdr *)buf;
+		o2image_swap_header(hdr);
+		if (super_no > hdr->hdr_superblkcnt) {
+			ret = OCFS2_ET_IO;
+			goto bail;
+		}
+		offset = hdr->hdr_superblocks[super_no-1]*hdr->hdr_fsblksz;
+	}
+
 	blkno = offset / OCFS2_MIN_BLOCKSIZE;
 	ret = io_read_block(channel, blkno, 1, buf);
 	if (ret)
@@ -347,23 +363,29 @@ static int process_open_args(char **args,
 			     uint64_t *superblock, uint64_t *blocksize)
 {
 	errcode_t ret = 0;
-	uint32_t s;
+	uint32_t s = 0;
 	char *ptr;
 	uint64_t byte_off[OCFS2_MAX_BACKUP_SUPERBLOCKS];
 	uint64_t blksize = 0;
-	int num, ind = 2;
+	int num, ind = 2, super = 0;
 
-	if (!args[ind])
-		return 0;
+	while (args[ind]) {
+		if (!strcmp(args[ind], "-i"))
+			gbls.imagefile = 1;
 
-	if (args[ind] && !strcmp(args[ind], "-s"))
+		if (!strcmp(args[ind], "-s")) {
+			if (args[ind + 1]) {
+				super = ind + 1;
+			} else
+				return -1;
+		}
 		ind++;
-	else
-		return -1;
+	}
 
-	if(!args[ind])
-		return -1;
+	if(!super)
+		return 0;
 
+	ind = super;
 	num = ocfs2_get_backup_super_offset(NULL,
 					    byte_off, ARRAY_SIZE(byte_off));
 	if (!num)
@@ -376,7 +398,7 @@ static int process_open_args(char **args,
 		return -1;
 	}
 
-	ret = get_blocksize(args[1], byte_off[s-1], &blksize);
+	ret = get_blocksize(args[1], byte_off[s-1], &blksize, s);
 	if (ret) {
 		com_err(args[0],ret, "Can't get the blocksize from the device"
 			" by the num %u\n", s);
@@ -602,15 +624,20 @@ static void do_open (char **args)
 		do_close (NULL);
 
 	if (dev == NULL || process_open_args(args, &superblock, &block_size)) {
-		fprintf (stderr, "usage: %s <device> [-s num]\n", args[0]);
+		fprintf (stderr, "usage: %s <device> [-i] [-s num]\n", args[0]);
+		gbls.imagefile = 0;
 		return ;
 	}
 
 	flags = gbls.allow_write ? OCFS2_FLAG_RW : OCFS2_FLAG_RO;
         flags |= OCFS2_FLAG_HEARTBEAT_DEV_OK;
+	if (gbls.imagefile)
+		flags |= OCFS2_FLAG_O2IMAGE_FILE;
+
 	ret = ocfs2_open(dev, flags, superblock, block_size, &gbls.fs);
 	if (ret) {
 		gbls.fs = NULL;
+		gbls.imagefile = 0;
 		com_err(args[0], ret, "while opening context for device %s",
 			dev);
 		return ;
@@ -681,6 +708,7 @@ static void do_close (char **args)
 	if (ret)
 		com_err(args[0], ret, "while closing context");
 	gbls.fs = NULL;
+	gbls.imagefile = 0;
 
 	if (gbls.blockbuf)
 		ocfs2_free(&gbls.blockbuf);
@@ -809,7 +837,7 @@ static void do_help (char **args)
 	printf ("logdump <slot#>\t\t\t\tPrints journal file for the node slot\n");
 	printf ("ls [-l] <filespec>\t\t\tList directory\n");
 	printf ("ncheck <block#> ...\t\t\tList all pathnames of the inode(s)/lockname(s)\n");
-	printf ("open <device> [-s backup#]\t\t\t\tOpen a device\n");
+	printf ("open <device> [-i] [-s backup#]\t\tOpen a device\n");
 	printf ("quit, q\t\t\t\t\tExit the program\n");
 	printf ("rdump [-v] <filespec> <outdir>\t\tRecursively dumps from src to a dir on a mounted filesystem\n");
 	printf ("slotmap\t\t\t\t\tShow slot map\n");
diff --git a/debugfs.ocfs2/debugfs.ocfs2.8.in b/debugfs.ocfs2/debugfs.ocfs2.8.in
index cebfeda..7c87269 100644
--- a/debugfs.ocfs2/debugfs.ocfs2.8.in
+++ b/debugfs.ocfs2/debugfs.ocfs2.8.in
@@ -30,6 +30,10 @@ Display the lockname obtained by encoding the lock type, inode number and the in
 Executes the debugfs commands in \fIcmdfile\fR.
 
 .TP
+\fB\-i, \-\-image\fR
+Specifies device is an o2image file created by \fIo2image\fR tool.
+
+.TP
 \fB\-l\fR [\fItracebit\fR ... [\fBallow\fR|\fBoff\fR|\fBdeny\fR]] ...
 Control \fBOCFS2\fR filesystem tracing by enabling and disabling trace bits.
 Do \fIdebugfs.ocfs2 -l\fR to get the list of all trace bits.
@@ -222,6 +226,7 @@ This tool has been modelled after \fBdebugfs\fR, a debugging tool for ext2.
 .BR mounted.ocfs2(8)
 .BR ocfs2console(8)
 .BR ocfs2cdsl(8)
+.BR o2image(8)
 
 .SH "AUTHOR"
 Oracle Corporation
diff --git a/debugfs.ocfs2/include/main.h b/debugfs.ocfs2/include/main.h
index f0e0c2b..8efcccf 100644
--- a/debugfs.ocfs2/include/main.h
+++ b/debugfs.ocfs2/include/main.h
@@ -68,6 +68,7 @@ enum {
 typedef struct _dbgfs_glbs {
 	char *progname;
 	int allow_write;
+	int imagefile;
 	int interactive;
 	char *device;
 	ocfs2_filesys *fs;
@@ -86,6 +87,7 @@ typedef struct _dbgfs_glbs {
 
 typedef struct _dbgfs_opts {
 	int allow_write;
+	int imagefile;
 	int no_prompt;
 	uint32_t sb_num;
 	char *cmd_file;
diff --git a/debugfs.ocfs2/main.c b/debugfs.ocfs2/main.c
index ecd7f70..90c2cdb 100644
--- a/debugfs.ocfs2/main.c
+++ b/debugfs.ocfs2/main.c
@@ -47,10 +47,11 @@ static void usage (char *progname)
 	g_print ("usage: %s -l [<logentry> ... [allow|off|deny]] ...\n", progname);
 	g_print ("usage: %s -d, --decode <lockres>\n", progname);
 	g_print ("usage: %s -e, --encode <lock type> <block num> <generation>\n", progname);
-	g_print ("usage: %s [-f cmdfile] [-R request] [-s backup#] [-V] [-w] [-n] [-?] [device]\n", progname);
+	g_print ("usage: %s [-f cmdfile] [-R request] [-i] [-s backup#] [-V] [-w] [-n] [-?] [device]\n", progname);
 	g_print ("\t-f, --file <cmdfile>\t\tExecute commands in cmdfile\n");
 	g_print ("\t-R, --request <command>\t\tExecute a single command\n");
 	g_print ("\t-s, --superblock <backup#>\tOpen the device using a backup superblock\n");
+	g_print ("\t-i, --image\t\t\tfile is an o2image file\n");
 	g_print ("\t-w, --write\t\t\tOpen in read-write mode instead of the default of read-only\n");
 	g_print ("\t-V, --version\t\t\tShow version\n");
 	g_print ("\t-n, --noprompt\t\t\tHide prompt\n");
@@ -189,6 +190,7 @@ static void get_options(int argc, char **argv, dbgfs_opts *opts)
 		{ "decode", 0, 0, 'd' },
 		{ "encode", 0, 0, 'e' },
 		{ "superblock", 0, 0, 's' },
+		{ "image", 0, 0, 'i' },
 		{ 0, 0, 0, 0}
 	};
 
@@ -196,7 +198,8 @@ static void get_options(int argc, char **argv, dbgfs_opts *opts)
 		if (decodemode || encodemode || logmode)
 			break;
 
-		c = getopt_long(argc, argv, "lf:R:deV?wns:", long_options, NULL);
+		c = getopt_long(argc, argv, "lf:R:deV?wns:i",
+				long_options, NULL);
 		if (c == -1)
 			break;
 
@@ -225,6 +228,10 @@ static void get_options(int argc, char **argv, dbgfs_opts *opts)
 			encodemode++;
 			break;
 
+		case 'i':
+			opts->imagefile = 1;
+			break;
+
 		case 'l':
 			logmode++;
 			break;
@@ -462,6 +469,7 @@ int main (int argc, char **argv)
 	}
 
 	gbls.allow_write = opts.allow_write;
+	gbls.imagefile = opts.imagefile;
 	if (!opts.cmd_file)
 		gbls.interactive++;
 
-- 
1.5.3.4




More information about the Ocfs2-tools-devel mailing list