Commit 457d08ee4fd91c8df17917ff2d32565e6adacbfc
Committed by
Jaegeuk Kim
1 parent
508198be3c
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
f2fs: introduce accessor to retrieve number of dentry slots
Simplify code by providing the accessor macro to retrieve the number of dentry slots for a given filename length. Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com> Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Showing 2 changed files with 8 additions and 8 deletions Side-by-side Diff
fs/f2fs/dir.c
... | ... | @@ -99,8 +99,7 @@ |
99 | 99 | NR_DENTRY_IN_BLOCK, 0); |
100 | 100 | while (bit_pos < NR_DENTRY_IN_BLOCK) { |
101 | 101 | de = &dentry_blk->dentry[bit_pos]; |
102 | - slots = (le16_to_cpu(de->name_len) + F2FS_NAME_LEN - 1) / | |
103 | - F2FS_NAME_LEN; | |
102 | + slots = GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); | |
104 | 103 | |
105 | 104 | if (early_match_name(name, namelen, namehash, de)) { |
106 | 105 | if (!memcmp(dentry_blk->filename[bit_pos], |
... | ... | @@ -130,7 +129,7 @@ |
130 | 129 | unsigned int level, const char *name, int namelen, |
131 | 130 | f2fs_hash_t namehash, struct page **res_page) |
132 | 131 | { |
133 | - int s = (namelen + F2FS_NAME_LEN - 1) / F2FS_NAME_LEN; | |
132 | + int s = GET_DENTRY_SLOTS(namelen); | |
134 | 133 | unsigned int nbucket, nblock; |
135 | 134 | unsigned int bidx, end_block; |
136 | 135 | struct page *dentry_page; |
... | ... | @@ -383,7 +382,7 @@ |
383 | 382 | int namelen = dentry->d_name.len; |
384 | 383 | struct page *dentry_page = NULL; |
385 | 384 | struct f2fs_dentry_block *dentry_blk = NULL; |
386 | - int slots = (namelen + F2FS_NAME_LEN - 1) / F2FS_NAME_LEN; | |
385 | + int slots = GET_DENTRY_SLOTS(namelen); | |
387 | 386 | int err = 0; |
388 | 387 | int i; |
389 | 388 | |
... | ... | @@ -465,8 +464,7 @@ |
465 | 464 | struct address_space *mapping = page->mapping; |
466 | 465 | struct inode *dir = mapping->host; |
467 | 466 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
468 | - int slots = (le16_to_cpu(dentry->name_len) + F2FS_NAME_LEN - 1) / | |
469 | - F2FS_NAME_LEN; | |
467 | + int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); | |
470 | 468 | void *kaddr = page_address(page); |
471 | 469 | int i; |
472 | 470 | |
... | ... | @@ -641,8 +639,7 @@ |
641 | 639 | file->f_pos += bit_pos - start_bit_pos; |
642 | 640 | goto success; |
643 | 641 | } |
644 | - slots = (le16_to_cpu(de->name_len) + F2FS_NAME_LEN - 1) | |
645 | - / F2FS_NAME_LEN; | |
642 | + slots = GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); | |
646 | 643 | bit_pos += slots; |
647 | 644 | } |
648 | 645 | bit_pos = 0; |
include/linux/f2fs_fs.h
... | ... | @@ -363,6 +363,9 @@ |
363 | 363 | |
364 | 364 | /* One directory entry slot covers 8bytes-long file name */ |
365 | 365 | #define F2FS_NAME_LEN 8 |
366 | +#define F2FS_NAME_LEN_BITS 3 | |
367 | + | |
368 | +#define GET_DENTRY_SLOTS(x) ((x + F2FS_NAME_LEN - 1) >> F2FS_NAME_LEN_BITS) | |
366 | 369 | |
367 | 370 | /* the number of dentry in a block */ |
368 | 371 | #define NR_DENTRY_IN_BLOCK 214 |