[Ocfs2-tools-devel] [PATCH 2/2] Ocfs2-tools: Apply joel's suggestion on fswreck's dir codes to solve a minor problem.

Tristan Ye tristan.ye at oracle.com
Thu Jul 2 20:41:35 PDT 2009


Since the patch '[PATCH 3/4] Ocfs2-tools: Fix bug for fswreck to
handle corruption of inlined directory correctly' has already been
committed, I therefore would like to generate this patch to apply
joel's suggestion on rename_dirent() to solve a potential bug.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 fswreck/dir.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fswreck/dir.c b/fswreck/dir.c
index 05ac985..489630d 100644
--- a/fswreck/dir.c
+++ b/fswreck/dir.c
@@ -91,6 +91,7 @@ struct dirent_corrupt_struct  {
 	const char	*oldname;
 	const char      *name;
 	int             namelen;
+	int		oldnamelen;
 	int             done;
 	int		reserved;
 };
@@ -101,7 +102,7 @@ static int corrupt_match_dirent(struct dirent_corrupt_struct *dcs,
 	if (!dcs->oldname)
 		return 1;
 
-	if (((dirent->name_len & 0xFF) != dcs->namelen))
+	if (((dirent->name_len & 0xFF) != dcs->oldnamelen))
 		return 0;
 
 	if (strncmp(dcs->oldname, dirent->name, dirent->name_len & 0xFF))
@@ -121,8 +122,13 @@ static int rename_dirent_proc(struct ocfs2_dir_entry *dirent,
 	if (!corrupt_match_dirent(dcs, dirent))
 		return 0;
 	
-	strcpy(dirent->name, dcs->name);
-
+	if (dcs->namelen <= (dirent->rec_len -
+			     offsetof(struct ocfs2_dir_entry, name))) {
+		strcpy(dirent->name, dcs->name);
+		dirent->name_len = dcs->namelen;
+	} else
+		FSWRK_FATAL("The lenght of new name for target dirent you"
+                            "want to rename didn't fit the old one.\n");
 	dcs->done++;
 
 	return OCFS2_DIRENT_ABORT|OCFS2_DIRENT_CHANGED;
@@ -139,7 +145,8 @@ static int rename_dirent(ocfs2_filesys *fs, uint64_t dir,
 
 	dcs.name = name;
 	dcs.oldname = oldname;
-	dcs.namelen = oldname ? strlen(oldname) : 0;
+	dcs.namelen = name ? strlen(name) : 0;
+	dcs.oldnamelen = oldname ? strlen(oldname) : 0;
 	dcs.done = 0;
 
 	rc = ocfs2_dir_iterate(fs, dir, 0, 0, rename_dirent_proc, &dcs);
@@ -179,7 +186,7 @@ static int corrupt_dirent_ino(ocfs2_filesys *fs, uint64_t dir,
 		return OCFS2_ET_RO_FILESYS;
 
 	dcs.oldname = name;
-	dcs.namelen = name ? strlen(name) : 0;
+	dcs.oldnamelen = name ? strlen(name) : 0;
 	dcs.done = 0;
 	dcs.reserved = inc;
 
@@ -223,7 +230,7 @@ static int corrupt_dirent_reclen(ocfs2_filesys *fs, uint64_t dir,
 		return OCFS2_ET_RO_FILESYS;
 
 	dcs.oldname = name;
-	dcs.namelen = name ? strlen(name) : 0;
+	dcs.oldnamelen = name ? strlen(name) : 0;
 	dcs.done = 0;
 	dcs.reserved = inc;
 
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list