From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [PATCH 2/3] lib: fix test_bit_le functions
Date: Tue, 15 Dec 2015 13:19:33 -0800 [thread overview]
Message-ID: <1450214374-65696-2-git-send-email-jaegeuk@kernel.org> (raw)
In-Reply-To: <1450214374-65696-1-git-send-email-jaegeuk@kernel.org>
This patch fixes test_bit_le functions for dentry bit operations.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/fsck.c | 12 ++++++------
include/f2fs_fs.h | 6 +++---
lib/libf2fs.c | 26 ++++++++++----------------
mkfs/f2fs_format.c | 3 ++-
4 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 58786f2..38391a9 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -955,7 +955,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
/* readahead inode blocks */
for (i = 0; i < max; i++) {
- if (test_bit(i, bitmap) == 0)
+ if (test_bit_le(i, bitmap) == 0)
continue;
ino = le32_to_cpu(dentry[i].ino);
@@ -975,7 +975,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
}
for (i = 0; i < max;) {
- if (test_bit(i, bitmap) == 0) {
+ if (test_bit_le(i, bitmap) == 0) {
i++;
continue;
}
@@ -985,7 +985,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
if (config.fix_on) {
FIX_MSG("Clear bad dentry 0x%x with bad ino 0x%x",
i, le32_to_cpu(dentry[i].ino));
- clear_bit(i, bitmap);
+ test_and_clear_bit_le(i, bitmap);
fixed = 1;
}
i++;
@@ -998,7 +998,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
if (config.fix_on) {
FIX_MSG("Clear bad dentry 0x%x with bad ftype 0x%x",
i, ftype);
- clear_bit(i, bitmap);
+ test_and_clear_bit_le(i, bitmap);
fixed = 1;
}
i++;
@@ -1011,7 +1011,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
ASSERT_MSG("Bad dentry 0x%x with zero name_len", i);
if (config.fix_on) {
FIX_MSG("Clear bad dentry 0x%x", i);
- clear_bit(i, bitmap);
+ test_and_clear_bit_le(i, bitmap);
fixed = 1;
}
i++;
@@ -1053,7 +1053,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, struct child_info *child,
int j;
for (j = 0; j < slots; j++)
- clear_bit(i + j, bitmap);
+ test_and_clear_bit_le(i + j, bitmap);
FIX_MSG("Unlink [0x%x] - %s len[0x%x], type[0x%x]",
le32_to_cpu(dentry[i].ino),
name, name_len,
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 4927d24..decc7f4 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -855,9 +855,9 @@ extern int log_base_2(u_int32_t);
extern unsigned int addrs_per_inode(struct f2fs_inode *);
extern int get_bits_in_byte(unsigned char n);
-extern int set_bit(unsigned int nr,void * addr);
-extern int clear_bit(unsigned int nr, void * addr);
-extern int test_bit(unsigned int nr, const void * addr);
+extern int test_and_set_bit_le(unsigned int, unsigned char *);
+extern int test_and_clear_bit_le(unsigned int, unsigned char*);
+extern int test_bit_le(unsigned int, const unsigned char *);
extern int f2fs_test_bit(unsigned int, const char *);
extern int f2fs_set_bit(unsigned int, char *);
extern int f2fs_clear_bit(unsigned int, char *);
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 1802d9c..ab98a11 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -234,37 +234,31 @@ int get_bits_in_byte(unsigned char n)
return bits_in_byte[n];
}
-int set_bit(unsigned int nr, void *addr)
+int test_and_set_bit_le(unsigned int nr, unsigned char *addr)
{
int mask, retval;
- unsigned char *ADDR = (unsigned char *)addr;
- ADDR += nr >> 3;
+ addr += nr >> 3;
mask = 1 << ((nr & 0x07));
- retval = mask & *ADDR;
- *ADDR |= mask;
+ retval = mask & *addr;
+ *addr |= mask;
return retval;
}
-int clear_bit(unsigned int nr, void *addr)
+int test_and_clear_bit_le(unsigned int nr, unsigned char *addr)
{
int mask, retval;
- unsigned char *ADDR = (unsigned char *)addr;
- ADDR += nr >> 3;
+ addr += nr >> 3;
mask = 1 << ((nr & 0x07));
- retval = mask & *ADDR;
- *ADDR &= ~mask;
+ retval = mask & *addr;
+ *addr &= ~mask;
return retval;
}
-int test_bit(unsigned int nr, const void *addr)
+int test_bit_le(unsigned int nr, const unsigned char *addr)
{
- const __u32 *p = (const __u32 *)addr;
-
- nr = nr ^ 0;
-
- return ((1 << (nr & 31)) & (p[nr >> 5])) != 0;
+ return ((1 << (nr & 7)) & (addr[nr >> 3]));
}
int f2fs_test_bit(unsigned int nr, const char *p)
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 98a6bce..cb5379a 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -862,7 +862,8 @@ static int f2fs_add_default_dentry_root(void)
memcpy(dent_blk->filename[1], "..", 2);
/* bitmap for . and .. */
- dent_blk->dentry_bitmap[0] = (1 << 1) | (1 << 0);
+ test_and_set_bit_le(0, dent_blk->dentry_bitmap);
+ test_and_set_bit_le(1, dent_blk->dentry_bitmap);
blk_size_bytes = 1 << get_sb(log_blocksize);
data_blk_offset = get_sb(main_blkaddr);
data_blk_offset += config.cur_seg[CURSEG_HOT_DATA] *
--
2.5.4 (Apple Git-61)
------------------------------------------------------------------------------
next prev parent reply other threads:[~2015-12-15 21:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-15 21:19 [PATCH 1/3] mkfs.f2fs: remove extent_cache entry for parent directory Jaegeuk Kim
2015-12-15 21:19 ` Jaegeuk Kim [this message]
2015-12-15 21:19 ` [PATCH 3/3] lib: use u8/u32/u64 for bit operations Jaegeuk Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1450214374-65696-2-git-send-email-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).