linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/17] f2fs_dentry_hash: avoid casting unsigned char to singed char
@ 2014-08-30  0:28 Jaegeuk Kim
  2014-08-30  0:28 ` [PATCH 02/17] fsck.f2fs: retry to fix corrupted image Jaegeuk Kim
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: Jaegeuk Kim @ 2014-08-30  0:28 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Jaegeuk Kim

This can hurt when calculating hash value, resulting in false alarm.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fsck/fsck.c       |  5 +++--
 include/f2fs_fs.h |  2 +-
 lib/libf2fs.c     | 31 ++++++++++++-------------------
 3 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 2d8dffb..303ba8d 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -542,11 +542,12 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi,
 			continue;
 		}
 
-		name_len = le32_to_cpu(de_blk->dentry[i].name_len);
+		name_len = le16_to_cpu(de_blk->dentry[i].name_len);
 		name = calloc(name_len + 1, 1);
 		memcpy(name, de_blk->filename[i], name_len);
+		hash_code = f2fs_dentry_hash((const unsigned char *)name,
+								name_len);
 
-		hash_code = f2fs_dentry_hash((const char *)name, name_len);
 		ASSERT(le32_to_cpu(de_blk->dentry[i].hash_code) == hash_code);
 
 		ftype = de_blk->dentry[i].file_type;
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 9ade334..aebb1d2 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -679,7 +679,7 @@ extern int dev_fill(void *, __u64, size_t);
 extern int dev_read_block(void *, __u64);
 extern int dev_read_blocks(void *, __u64, __u32 );
 
-f2fs_hash_t f2fs_dentry_hash(const char *, int);
+f2fs_hash_t f2fs_dentry_hash(const unsigned char *, int);
 
 extern struct f2fs_configuration config;
 
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 6168c5c..01ef4e9 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -235,7 +235,8 @@ static void TEA_transform(unsigned int buf[4], unsigned int const in[])
 
 }
 
-static void str2hashbuf(const char *msg, int len, unsigned int *buf, int num)
+static void str2hashbuf(const unsigned char *msg, int len,
+					unsigned int *buf, int num)
 {
 	unsigned pad, val;
 	int i;
@@ -269,24 +270,17 @@ static void str2hashbuf(const char *msg, int len, unsigned int *buf, int num)
  * @param len           name lenth
  * @return              return on success hash value, errno on failure
  */
-f2fs_hash_t f2fs_dentry_hash(const char *name, int len)
+f2fs_hash_t f2fs_dentry_hash(const unsigned char *name, int len)
 {
 	__u32 hash;
 	f2fs_hash_t	f2fs_hash;
-	const char	*p;
+	const unsigned char	*p;
 	__u32 in[8], buf[4];
 
 	/* special hash codes for special dentries */
-	if (name[0] == '.') {
-		if (name[1] == '\0') {
-			f2fs_hash = F2FS_DOT_HASH;
-			goto exit;
-		}
-		if (name[1] == '.' && name[2] == '\0') {
-			f2fs_hash = F2FS_DDOT_HASH;
-			goto exit;
-		}
-	}
+	if ((len <= 2) && (name[0] == '.') &&
+		(name[1] == '.' || name[1] == '\0'))
+		return 0;
 
 	/* Initialize the default seed for the hash checksum functions */
 	buf[0] = 0x67452301;
@@ -295,18 +289,17 @@ f2fs_hash_t f2fs_dentry_hash(const char *name, int len)
 	buf[3] = 0x10325476;
 
 	p = name;
-	while (len > 0) {
+	while (1) {
 		str2hashbuf(p, len, in, 4);
 		TEA_transform(buf, in);
-		len -= 16;
 		p += 16;
+		if (len <= 16)
+			break;
+		len -= 16;
 	}
 	hash = buf[0];
 
-	f2fs_hash = hash;
-exit:
-	f2fs_hash &= ~F2FS_HASH_COL_BIT;
-
+	f2fs_hash = cpu_to_le32(hash & ~F2FS_HASH_COL_BIT);
 	return f2fs_hash;
 }
 
-- 
1.8.5.2 (Apple Git-48)


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-08-30  0:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-30  0:28 [PATCH 01/17] f2fs_dentry_hash: avoid casting unsigned char to singed char Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 02/17] fsck.f2fs: retry to fix corrupted image Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 03/17] fsck.f2fs: clean up codes Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 04/17] fsck.f2fs: handle IS_VALID_BLK_ADDR Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 05/17] fsck.f2fs: remove return value of get_node_info Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 06/17] fsck.f2fs: handle error cases Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 07/17] fsck.f2fs: cleanup mount.c Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 08/17] fsck.f2fs: give a chance to recover sit entries Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 09/17] fsck.f2fs: fix inode block inconsistency Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 10/17] fsck.f2fs: add fixing messeages Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 11/17] fsck.f2fs: remove dentry if its inode block is corrupted Jaegeuk Kim
2014-08-30  0:28 ` [PATCH 12/17] fsck.f2fs: corrupted orphan inode will be removed Jaegeuk Kim
2014-08-30  0:29 ` [PATCH 13/17] fsck.f2fs: remove corrupted xattr block Jaegeuk Kim
2014-08-30  0:29 ` [PATCH 14/17] fsck.f2fs: handle correctly segment summary entries Jaegeuk Kim
2014-08-30  0:29 ` [PATCH 15/17] fsck.f2fs: fix checkpoint Jaegeuk Kim
2014-08-30  0:29 ` [PATCH 16/17] fsck.f2fs: check next block is free or not Jaegeuk Kim
2014-08-30  0:29 ` [PATCH 17/17] fsck.f2fs: remove list.h Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).