[Ocfs-tools-commits] smushran commits r121 - in trunk/ocfs2/debugfs.ocfs2: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Jun 30 16:46:20 CDT 2004


Author: smushran
Date: 2004-06-30 15:46:18 -0500 (Wed, 30 Jun 2004)
New Revision: 121

Modified:
   trunk/ocfs2/debugfs.ocfs2/commands.c
   trunk/ocfs2/debugfs.ocfs2/dump.c
   trunk/ocfs2/debugfs.ocfs2/include/readfs.h
   trunk/ocfs2/debugfs.ocfs2/readfs.c
Log:
dump working

Modified: trunk/ocfs2/debugfs.ocfs2/commands.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/commands.c	2004-06-30 19:01:59 UTC (rev 120)
+++ trunk/ocfs2/debugfs.ocfs2/commands.c	2004-06-30 20:46:18 UTC (rev 121)
@@ -65,7 +65,6 @@
 static void do_config (char **args);
 static void do_publish (char **args);
 static void do_vote (char **args);
-static void do_cat (char **args);
 
 extern gboolean allow_write;
 
@@ -106,7 +105,7 @@
   { "q",      do_quit   },
 
   { "dump",   do_dump   },
-  { "cat",    do_cat   },
+  { "cat",    do_dump   },
 
   { "curdev", do_curdev },
 
@@ -191,6 +190,11 @@
 
 	if (read_super_block (dev_fd, &superblk) != -1)
 		curdir = g_strdup ("/");
+	else {
+		close (dev_fd);
+		dev_fd = -1;
+		goto bail;
+	}
 
 	inode = (ocfs2_dinode *)superblk;
 	sb = &(inode->id2.i_super);
@@ -400,15 +404,6 @@
 }					/* do_quit */
 
 /*
- * do_dump()
- *
- */
-static void do_dump (char **args)
-{
-
-}					/* do_dump */
-
-/*
  * do_lcd()
  *
  */
@@ -511,11 +506,18 @@
  */
 static void do_config (char **args)
 {
+	char *dlmbuf = NULL;
+
 	if (dev_fd == -1)
 		printf ("device not open\n");
-	else
-		process_dlm (dev_fd, CONFIG);
+	else {
+		if (read_file (dev_fd, dlm_blkno, -1, &dlmbuf) == -1)
+			goto bail;
+		dump_config (dlmbuf);
+	}
 
+bail:
+	safefree (dlmbuf);
 	return ;
 }					/* do_config */
 
@@ -525,11 +527,18 @@
  */
 static void do_publish (char **args)
 {
+	char *dlmbuf = NULL;
+
 	if (dev_fd == -1)
 		printf ("device not open\n");
-	else
-		process_dlm (dev_fd, PUBLISH);
+	else {
+		if (read_file (dev_fd, dlm_blkno, -1, &dlmbuf) == -1)
+			goto bail;
+		dump_publish (dlmbuf);
+	}
 
+bail:
+	safefree (dlmbuf);
 	return ;
 }					/* do_publish */
 
@@ -539,49 +548,64 @@
  */
 static void do_vote (char **args)
 {
+	char *dlmbuf = NULL;
+	
 	if (dev_fd == -1)
 		printf ("device not open\n");
-	else
-		process_dlm (dev_fd, VOTE);
+	else {
+		if (read_file (dev_fd, dlm_blkno, -1, &dlmbuf) == -1)
+			goto bail;
+		dump_vote (dlmbuf);
+	}
 
+bail:
+	safefree (dlmbuf);
 	return ;
 }					/* do_vote */
 
 /*
- * do_cat()
+ * do_dump()
  *
  */
-static void do_cat (char **args)
+static void do_dump (char **args)
 {
-	char *opts = args[1];
-	ocfs2_dinode *inode;
-	__u32 blknum = 0;
-	char *buf = NULL;
-	__u32 buflen;
+	__u64 blknum = 0;
+	__s32 outfd = -1;
+	int flags;
+	int op = 0;  /* 0 = dump, 1 = cat */
+	char *outfile = NULL;
 
 	if (dev_fd == -1) {
 		printf ("device not open\n");
 		goto bail;
 	}
 
-	if (opts)
-		blknum = atoi(opts);
+	if (!strncasecmp (args[0], "cat", 3)) {
+		outfd = 1;
+		op = 1;
+	}
 
+	if (args[1])
+		blknum = strtoull (args[1], NULL, 0);
+
 	if (!blknum)
 		goto bail;
 
-	buflen = 1 << blksz_bits;
-	if (!(buf = malloc(buflen)))
-		DBGFS_FATAL("%s", strerror(errno));
-
-	if ((read_inode (dev_fd, blknum, buf, buflen)) == -1) {
-		printf("Not an inode\n");
-		goto bail;
+	if (args[2]) {
+		outfile = args[2];
+		flags = O_WRONLY| O_CREAT | O_LARGEFILE;
+		flags |= ((op) ? O_APPEND : O_TRUNC);
+		if ((outfd = open (outfile, flags)) == -1) {
+			printf ("unable to open file %s\n", outfile);
+			goto bail;
+		}
 	}
-	inode = (ocfs2_dinode *)buf;
 
-	read_file (dev_fd, &(inode->id2.i_list), inode->i_size, NULL, 1);
+	read_file (dev_fd, blknum, outfd, NULL);
 
 bail:
+	if (outfd > 2)
+		close (outfd);
+
 	return ;
-}					/* do_cat */
+}					/* do_dump */

Modified: trunk/ocfs2/debugfs.ocfs2/dump.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/dump.c	2004-06-30 19:01:59 UTC (rev 120)
+++ trunk/ocfs2/debugfs.ocfs2/dump.c	2004-06-30 20:46:18 UTC (rev 121)
@@ -282,7 +282,7 @@
 	__u16 port;
 	char addr[32];
 	struct in_addr ina;
-	int i;
+	int i, j;
 
 	hdr = (ocfs_node_config_hdr *)buf;
 
@@ -306,11 +306,13 @@
 		strcpy (addr, inet_ntoa(ina));
 
 		printf("%-4u %-32s %-15s %-6u ", i, node->node_name, addr, port);
-		for (i = 0; i < 16; i++)
-			printf("%02X", sb->s_uuid[i]);
+		for (j = 0; j < OCFS2_GUID_LEN; j++)
+			printf("%c", node->guid.guid[j]);
 		printf("\n");
 		p += (1 << blksz_bits);
 	}
+
+	return ;
 }				/* dump_config */
 
 /*

Modified: trunk/ocfs2/debugfs.ocfs2/include/readfs.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/readfs.h	2004-06-30 19:01:59 UTC (rev 120)
+++ trunk/ocfs2/debugfs.ocfs2/include/readfs.h	2004-06-30 20:46:18 UTC (rev 121)
@@ -27,12 +27,11 @@
 #define __READFS_H__
 
 int read_super_block (int fd, char **buf);
-int read_inode (int fd, __u32 blknum, char *buf, int buflen);
+int read_inode (int fd, __u64 blknum, char *buf, int buflen);
 int traverse_extents (int fd, ocfs2_extent_list *ext, GArray *arr, int dump);
 void read_dir_block (struct ocfs2_dir_entry *dir, int len, GArray *arr);
 void read_dir (int fd, ocfs2_extent_list *ext, __u64 size, GArray *dirarr);
 void read_sysdir (int fd, char *sysdir);
-void read_file (int fd, ocfs2_extent_list *ext, __u64 size, char *buf, int fdo);
-void process_dlm (int fd, int type);
+int read_file (int fd, __u64 blknum, int fdo, char **buf);
 
 #endif		/* __READFS_H__ */

Modified: trunk/ocfs2/debugfs.ocfs2/readfs.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/readfs.c	2004-06-30 19:01:59 UTC (rev 120)
+++ trunk/ocfs2/debugfs.ocfs2/readfs.c	2004-06-30 20:46:18 UTC (rev 121)
@@ -51,7 +51,7 @@
 	if (!(*buf = malloc(buflen)))
 		DBGFS_FATAL("%s", strerror(errno));
 
-	if ((ret = pread64(fd, *buf, buflen, 0)) == -1)
+	if ((pread64(fd, *buf, buflen, 0)) == -1)
 		DBGFS_FATAL("%s", strerror(errno));
 
 	hdr = (ocfs1_vol_disk_hdr *)*buf;
@@ -75,13 +75,12 @@
 		}
 
 		off = OCFS2_SUPER_BLOCK_BLKNO << bits;
-		if ((ret = pread64(fd, *buf, buflen, off)) == -1)
+		if ((pread64(fd, *buf, buflen, off)) == -1)
 			DBGFS_FATAL("%s", strerror(errno));
 
 		di = (ocfs2_dinode *) *buf;
-		if (!memcmp(di->i_signature,
-                            OCFS2_SUPER_BLOCK_SIGNATURE,
-			   strlen(OCFS2_SUPER_BLOCK_SIGNATURE))) {
+		if (!memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
+			    strlen(OCFS2_SUPER_BLOCK_SIGNATURE))) {
 			ret = 0;
 			break;
 		}
@@ -89,7 +88,7 @@
 	}
 
         if (bits >= 13)
-            printf("Not an OCFS2 volume");
+            printf("Not an OCFS2 volume\n");
 
 bail:
 	return ret;
@@ -99,21 +98,21 @@
  * read_inode()
  *
  */
-int read_inode (int fd, __u32 blknum, char *buf, int buflen)
+int read_inode (int fd, __u64 blknum, char *buf, int buflen)
 {
 	__u64 off;
 	ocfs2_dinode *inode;
 	int ret = 0;
 
-	off = (__u64)(blknum << blksz_bits);
+	off = blknum << blksz_bits;
 
 	if ((pread64(fd, buf, buflen, off)) == -1)
 		DBGFS_FATAL("%s", strerror(errno));
 
 	inode = (ocfs2_dinode *)buf;
 
-	if (memcmp(inode->i_signature, OCFS2_FILE_ENTRY_SIGNATURE,
-		   sizeof(OCFS2_FILE_ENTRY_SIGNATURE)))
+	if (memcmp(inode->i_signature, OCFS2_INODE_SIGNATURE,
+		   sizeof(OCFS2_INODE_SIGNATURE)))
 		ret = -1;
 
 	return ret;
@@ -268,31 +267,54 @@
  * read_file()
  *
  */
-void read_file (int fd, ocfs2_extent_list *ext, __u64 size, char *buf, int fdo)
+int read_file (int fd, __u64 blknum, int fdo, char **buf)
 {
+	ocfs2_dinode *inode = NULL;
 	GArray *arr = NULL;
 	ocfs2_extent_rec *rec;
-	char *p;
+	char *p = NULL;
 	__u64 off, foff, len;
 	int i;
 	char *newbuf = NULL;
 	__u32 newlen = 0;
+	char *inode_buf = NULL;
+	int buflen = 0;
+	int ret = -1;
 
 	arr = g_array_new(0, 1, sizeof(ocfs2_extent_rec));
 
-	traverse_extents (fd, ext, arr, 0);
+	buflen = 1 << blksz_bits;
+	if (!(inode_buf = malloc(buflen)))
+		DBGFS_FATAL("%s", strerror(errno));
 
-	p = buf;
+	if ((read_inode (fd, blknum, inode_buf, buflen)) == -1) {
+		printf("Not an inode\n");
+		goto bail;
+	}
+	inode = (ocfs2_dinode *)inode_buf;
 
+	traverse_extents (fd, &(inode->id2.i_list), arr, 0);
+
+	if (fdo == -1) {
+		if (!(*buf = malloc (inode->i_size)))
+			DBGFS_FATAL("%s", strerror(errno));
+		p = *buf;
+	} else {
+		if (fdo > 2) {
+			fchmod (fdo, inode->i_mode);
+			fchown (fdo, inode->i_uid, inode->i_gid);
+		}
+	}
+
 	for (i = 0; i < arr->len; ++i) {
 		rec = &(g_array_index(arr, ocfs2_extent_rec, i));
 		off = rec->e_blkno << blksz_bits;
 		foff = rec->e_cpos << clstrsz_bits;
 		len = rec->e_clusters << clstrsz_bits;
-		if ((foff + len) > size)
-			len = size - foff;
+		if ((foff + len) > inode->i_size)
+			len = inode->i_size - foff;
 
-		if (fd != -1) {
+		if (fdo != -1) {
 			if (newlen <= len) {
 				safefree (newbuf);
 				if (!(newbuf = malloc (len)))
@@ -305,7 +327,7 @@
 		if ((pread64(fd, p, len, off)) == -1)
 			DBGFS_FATAL("%s", strerror(errno));
 
-		if (fd != -1) {
+		if (fdo != -1) {
 			if (len)
 				if (!(write (fdo, p, len)))
 					DBGFS_FATAL("%s", strerror(errno));
@@ -313,64 +335,14 @@
 			p += len;
 	}
 
+	ret = 0;
+
+bail:
+	safefree (inode_buf);
 	safefree (newbuf);
 
 	if (arr)
 		g_array_free (arr, 1);
 
-	return ;
+	return ret;
 }				/* read_file */
-
-/*
- * process_dlm()
- *
- */
-void process_dlm (int fd, int type)
-{
-	char *buf = NULL;
-	__u32 buflen;
-	char *dlmbuf = NULL;
-	ocfs2_dinode *inode;
-	ocfs2_super_block *sb = &(((ocfs2_dinode *)superblk)->id2.i_super);
-
-	/* get the dlm inode */
-	buflen = 1 << blksz_bits;
-	if (!(buf = malloc(buflen)))
-		DBGFS_FATAL("%s", strerror(errno));
-
-	if ((read_inode (fd, dlm_blkno, buf, buflen)) == -1) {
-		printf("Invalid dlm system file\n");
-		goto bail;
-	}
-	inode = (ocfs2_dinode *)buf;
-
-	/* length of file to read */
-	buflen = 2 + 4 + (3 * sb->s_max_nodes);
-	buflen <<= blksz_bits;
-
-	/* alloc the buffer */
-	if (!(dlmbuf = malloc (buflen)))
-		DBGFS_FATAL("%s", strerror(errno));
-
-	read_file (fd, &(inode->id2.i_list), buflen, dlmbuf, -1);
-
-	switch (type) {
-	case CONFIG:
-		dump_config (dlmbuf);
-		break;
-	case PUBLISH:
-		dump_publish (dlmbuf);
-		break;
-	case VOTE:
-		dump_vote (dlmbuf);
-		break;
-	default:
-		break;
-	}
-
-bail:
-	safefree (buf);
-	safefree (dlmbuf);
-
-	return ;
-}				/* process_dlm */



More information about the Ocfs-tools-commits mailing list