[Ocfs2-tools-devel] [PATCH 1/1] Ocfs2-tools: Let debugfs.ocfs2 correctly dump the fast symlink.

Tristan Ye tristan.ye at oracle.com
Tue Jun 2 23:18:39 PDT 2009


Currently dump and rdump command in debugfs.ocfs2 didn't handle the
fast symlink correctly but a error encountered.

To improve the current situation, I'm going to follow up the symlink
recursively until its real target get reached, we got the target's content
when dumping symlink with debugfs.ocfs2 just like read(2) operation on a symlink.

Not sure if it was a expected behaviour, or we just only need the symlink's content
(a path info for its target) when doing dump cmd instead of a follow-up?

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 debugfs.ocfs2/commands.c |   73 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index 143fc96..df73fe5 100644
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -1102,6 +1102,9 @@ static void do_dump (char **args)
 	char *out_fn;
 	errcode_t ret;
 	int fd;
+
+	char *ino_buf;
+	struct ocfs2_dinode *inode;
 	
 	if (check_device_open())
 		return;
@@ -1125,12 +1128,33 @@ static void do_dump (char **args)
 		return ;
 	}
 
-	ret = string_to_inode(gbls.fs, gbls.root_blkno, gbls.cwd_blkno,
-			      in_fn, &blkno);
-	if (ret) {
-		com_err(args[0], ret, "'%s'", in_fn);
-		return ;
-	}
+	ino_buf = gbls.blockbuf;
+
+	/* 
+           Follow up source recursively if symlinked until reach the real target
+           to let it correctly handled by dump_file().
+        */
+	do {
+		ret = string_to_inode(gbls.fs, gbls.root_blkno, gbls.cwd_blkno,
+				      in_fn, &blkno);
+		if (ret) {
+			com_err(args[0], ret, "'%s'", in_fn);
+			return ;
+		}
+
+		ret = ocfs2_read_inode(gbls.fs, blkno, ino_buf);
+		if (ret) {
+			com_err(args[0], ret, "while reading inode %"PRIu64"",
+				blkno);
+			return ;
+		}
+
+		inode = (struct ocfs2_dinode *)ino_buf;
+
+		if (S_ISLNK(inode->i_mode) && !inode->i_clusters)
+			in_fn = (char *)inode->id2.i_symlink;
+
+        } while (S_ISLNK(inode->i_mode) && !inode->i_clusters);
 
 	fd = open64(out_fn, O_CREAT | O_WRONLY | O_TRUNC, 0666);
 	if (fd < 0) {
@@ -1392,6 +1416,9 @@ static void do_rdump(char **args)
 	int verbose = 0;
 	char tmp_str[40];
 
+	char *ino_buf, *in_dn;
+	struct ocfs2_dinode *inode;
+
 	if (check_device_open())
 		return ;
 
@@ -1410,13 +1437,33 @@ static void do_rdump(char **args)
 		return ;
 	}
 
-	/* source */
-	ret = string_to_inode(gbls.fs, gbls.root_blkno, gbls.cwd_blkno,
-			      args[ind], &blkno);
-	if (ret) {
-		com_err(args[0], ret, "while translating %s", args[ind]);
-		return ;
-	}
+	in_dn = args[ind];
+	ino_buf = gbls.blockbuf;
+
+	/* 
+	   Follow up recursively if symlinked until reach the real target 
+	   to let the source correctly handled by rdump_inode().
+	*/
+	do {
+		ret = string_to_inode(gbls.fs, gbls.root_blkno, gbls.cwd_blkno,
+				      in_dn, &blkno);
+		if (ret) {
+			com_err(args[0], ret, "while translating %s", in_dn);
+			return ;
+		}
+
+		ret = ocfs2_read_inode(gbls.fs, blkno, ino_buf);
+		if (ret) {
+			com_err(args[0], ret, "while reading inode %"PRIu64"", blkno);
+			return ;
+		}
+
+		inode = (struct ocfs2_dinode *)ino_buf;
+
+		if (S_ISLNK(inode->i_mode) && !inode->i_clusters)
+			in_dn = (char *)inode->id2.i_symlink;
+
+        } while (S_ISLNK(inode->i_mode) && !inode->i_clusters);
 
 	/* destination... has to be a dir on a mounted fs */
 	if (stat(args[ind+1], &st) == -1) {
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list