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

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Dec 14 18:27:17 CST 2004


Author: smushran
Date: 2004-12-14 18:27:15 -0600 (Tue, 14 Dec 2004)
New Revision: 491

Modified:
   trunk/debugfs.ocfs2/commands.c
   trunk/debugfs.ocfs2/include/utils.h
   trunk/debugfs.ocfs2/utils.c
Log:
'cat' added in debugfs

Modified: trunk/debugfs.ocfs2/commands.c
===================================================================
--- trunk/debugfs.ocfs2/commands.c	2004-12-14 23:59:14 UTC (rev 490)
+++ trunk/debugfs.ocfs2/commands.c	2004-12-15 00:27:15 UTC (rev 491)
@@ -54,6 +54,7 @@
 static void do_quit (char **args);
 static void do_help (char **args);
 static void do_dump (char **args);
+static void do_cat (char **args);
 static void do_lcd (char **args);
 static void do_curdev (char **args);
 static void do_super (char **args);
@@ -93,14 +94,12 @@
   { "q",      do_quit   },
 
   { "dump",   do_dump   },
-  { "cat",    do_dump   },
+  { "cat",    do_cat   },
 
   { "curdev", do_curdev },
 
-  { "show_super_stats", do_super },
   { "stats", do_super },
 
-  { "show_inode_info", do_inode },
   { "stat", do_inode },
 
   { "nodes", do_hb },
@@ -586,11 +585,8 @@
 	printf ("ls <filepath>\t\t\t\tList directory\n");
 	printf ("cd <filepath>\t\t\t\tChange directory\n");
 	printf ("chroot <filepath>\t\t\tChange root\n");
-//	printf ("cat <blknum> [outfile]\t\tPrints or concatenates file to stdout/outfile\n");
+	printf ("cat <filepath>\t\t\t\tPrints file on stdout\n");
 	printf ("dump [-p] <filepath> <outfile>\t\tDumps file to outfile on a mounted fs\n");
-//	printf ("nodes\t\t\t\tList of nodes\n");
-//	printf ("publish\t\t\t\tPublish blocks\n");
-//	printf ("vote\t\t\t\tVote blocks\n");
 	printf ("logdump <node#>\t\t\t\tPrints journal file for the node\n");
 	printf ("extent <inode#>\t\t\t\tShow extent block\n");
 	printf ("group <inode#>\t\t\t\tShow chain group\n");
@@ -744,6 +740,7 @@
 	char *in_fn;
 	char *out_fn;
 	errcode_t ret;
+	int fd;
 	
 	if (check_device_open())
 		return;
@@ -774,7 +771,13 @@
 		return ;
 	}
 
-	ret = dump_file(gbls.fs, blkno, out_fn, preserve);
+	fd = open(out_fn, O_CREAT | O_WRONLY | O_TRUNC, 0666);
+	if (fd < 0) {
+		com_err(args[0], errno, "'%s'", out_fn);
+		return ;
+	}
+
+	ret = dump_file(gbls.fs, blkno, fd, out_fn, preserve);
 	if (ret)
 		com_err(args[0], ret, " ");
 
@@ -782,6 +785,40 @@
 }
 
 /*
+ * do_cat()
+ *
+ */
+static void do_cat (char **args)
+{
+	uint64_t blkno;
+	errcode_t ret;
+	char *buf;
+	ocfs2_dinode *di;
+
+	if (process_inode_args(args, &blkno))
+		return ;
+
+	buf = gbls.blockbuf;
+	ret = ocfs2_read_inode(gbls.fs, blkno, buf);
+	if (ret) {
+		com_err(args[0], ret, " ");
+		return ;
+	}
+
+	di = (ocfs2_dinode *)buf;
+	if (!S_ISREG(di->i_mode)) {
+		fprintf(stderr, "%s: Not a regular file\n", args[0]);
+		return ;
+	}
+
+	ret = dump_file(gbls.fs, blkno, fileno(stdout),  NULL, 0);
+	if (ret)
+		com_err(args[0], ret, " ");
+
+	return ;
+}
+
+/*
  * do_journal()
  *
  */

Modified: trunk/debugfs.ocfs2/include/utils.h
===================================================================
--- trunk/debugfs.ocfs2/include/utils.h	2004-12-14 23:59:14 UTC (rev 490)
+++ trunk/debugfs.ocfs2/include/utils.h	2004-12-15 00:27:15 UTC (rev 491)
@@ -35,7 +35,7 @@
 int inodestr_to_inode(char *str, uint64_t *blkno);
 errcode_t string_to_inode(ocfs2_filesys *fs, uint64_t root_blkno,
 			  uint64_t cwd_blkno, char *str, uint64_t *blkno);
-errcode_t dump_file(ocfs2_filesys *fs, uint64_t ino, char *out_file,
+errcode_t dump_file(ocfs2_filesys *fs, uint64_t ino, int fd, char *out_file,
 		    int preserve);
 
 #endif		/* __UTILS_H__ */

Modified: trunk/debugfs.ocfs2/utils.c
===================================================================
--- trunk/debugfs.ocfs2/utils.c	2004-12-14 23:59:14 UTC (rev 490)
+++ trunk/debugfs.ocfs2/utils.c	2004-12-15 00:27:15 UTC (rev 491)
@@ -320,7 +320,8 @@
  * dump_file()
  *
  */
-errcode_t dump_file(ocfs2_filesys *fs, uint64_t ino, char *out_file, int preserve)
+errcode_t dump_file(ocfs2_filesys *fs, uint64_t ino, int fd, char *out_file,
+		    int preserve)
 {
 	errcode_t ret;
 	char *buf = NULL;
@@ -330,14 +331,7 @@
 	ocfs2_cached_inode *ci = NULL;
 	uint64_t offset = 0;
 	uint64_t filesize;
-	int fd = -1;
 
-	fd = open(out_file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
-	if (fd < 0) {
-		ret = errno;
-		goto bail;
-	}
-
 	ret = ocfs2_read_cached_inode(fs, ino, &ci);
 	if (ret)
 		goto bail;
@@ -378,7 +372,7 @@
 		ret = fix_perms(ci->ci_inode, &fd, out_file);
 
 bail:
-	if (fd > 0)
+	if (fd > 0 && fd != fileno(stdout))
 		close(fd);
 	if (buf)
 		ocfs2_free(&buf);



More information about the Ocfs2-tools-commits mailing list