[Ocfs2-tools-devel] [PATCH 1/1] ocfs2-tools: issue cat command against some of the system files cause core dump V2

Jeff Liu jeff.liu at oracle.com
Wed Mar 18 02:19:31 PDT 2009


execute cat/dump/rdump against some of the system files cause core dump.
This patch add the system file flags check in do_dump()/do_rdump()/do_cat() functions
for debugfs.ocfs2.

Signed-off-by: jeff <jeff at jeff-laptop.(none)>
---
 debugfs.ocfs2/commands.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index 0dea23f..9935103 100644
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -1097,8 +1097,10 @@ static void do_dump (char **args)
 	const char *dump_usage = "usage: dump [-p] <filespec> <out_file>";
 	char *in_fn;
 	char *out_fn;
+	char *buf;
 	errcode_t ret;
 	int fd;
+	struct ocfs2_dinode *di;
 	
 	if (check_device_open())
 		return;
@@ -1129,6 +1131,19 @@ static void do_dump (char **args)
 		return ;
 	}
 
+	buf = gbls.blockbuf;
+	ret = ocfs2_read_inode(gbls.fs, blkno, buf);
+	if (ret) {
+		com_err(args[0], ret, "while reading inode %"PRIu64"", blkno);
+		return ;
+	}
+
+	di = (struct ocfs2_dinode *)buf;
+	if (di->i_flags & OCFS2_SYSTEM_FL) {
+		fprintf(stderr, "%s: is a system file\n", args[0]);
+		return ;
+	}
+
 	fd = open64(out_fn, O_CREAT | O_WRONLY | O_TRUNC, 0666);
 	if (fd < 0) {
 		com_err(args[0], errno, "'%s'", out_fn);
@@ -1164,7 +1179,7 @@ static void do_cat (char **args)
 	}
 
 	di = (struct ocfs2_dinode *)buf;
-	if (!S_ISREG(di->i_mode)) {
+	if (!S_ISREG(di->i_mode) || (di->i_flags & OCFS2_SYSTEM_FL)) {
 		fprintf(stderr, "%s: Not a regular file\n", args[0]);
 		return ;
 	}
@@ -1388,6 +1403,8 @@ static void do_rdump(char **args)
 	int ind = 1;
 	int verbose = 0;
 	char tmp_str[40];
+	char *buf;
+	struct ocfs2_dinode *di;
 
 	if (check_device_open())
 		return ;
@@ -1415,6 +1432,20 @@ static void do_rdump(char **args)
 		return ;
 	}
 
+	buf = gbls.blockbuf;
+	ret = ocfs2_read_inode(gbls.fs, blkno, buf);
+	if (ret) {
+		com_err(args[0], ret, "while reading inode %"PRIu64"", blkno);
+		return ;
+	}
+
+	di = (struct ocfs2_dinode *)buf;
+	if (di->i_flags & OCFS2_SYSTEM_FL) {
+		fprintf(stderr, "%s: is a system file\n", args[0]);
+		return ;
+	}
+
+
 	/* destination... has to be a dir on a mounted fs */
 	if (stat(args[ind+1], &st) == -1) {
 		com_err(args[0], errno, "'%s'", args[ind+1]);
-- 
1.5.4.3




More information about the Ocfs2-tools-devel mailing list