diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-10-15 21:29:51 -0700 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-11-03 16:07:34 -0800 |
commit | 38594de767b32db62b7213631772d050690d3803 (patch) | |
tree | 5f83dc3156cde9431b2f9c2fa813993d9bafbdc8 /fs/f2fs/dir.c | |
parent | e7a2bf2283d368ada40ae52152b7ab2304a76d95 (diff) | |
download | op-kernel-dev-38594de767b32db62b7213631772d050690d3803.zip op-kernel-dev-38594de767b32db62b7213631772d050690d3803.tar.gz |
f2fs: reuse core function in f2fs_readdir for inline_dentry
This patch introduces a core function, f2fs_fill_dentries, to remove
redundant code in f2fs_readdir and f2fs_read_inline_dir.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/dir.c')
-rw-r--r-- | fs/f2fs/dir.c | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index e5439dd..23a5da8 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -706,23 +706,50 @@ bool f2fs_empty_dir(struct inode *dir) return true; } +bool f2fs_fill_dentries(struct dir_context *ctx, + const void *bitmap, struct f2fs_dir_entry *dentry, + __u8 (*filenames)[F2FS_SLOT_LEN], int max, + unsigned int start_pos) +{ + unsigned char d_type = DT_UNKNOWN; + unsigned int bit_pos; + struct f2fs_dir_entry *de = NULL; + + bit_pos = ((unsigned long)ctx->pos % max); + + while (bit_pos < max) { + bit_pos = find_next_bit_le(bitmap, max, bit_pos); + if (bit_pos >= max) + break; + + de = &dentry[bit_pos]; + if (de->file_type < F2FS_FT_MAX) + d_type = f2fs_filetype_table[de->file_type]; + else + d_type = DT_UNKNOWN; + if (!dir_emit(ctx, filenames[bit_pos], + le16_to_cpu(de->name_len), + le32_to_cpu(de->ino), d_type)) + return true; + + bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); + ctx->pos = start_pos + bit_pos; + } + return false; +} + static int f2fs_readdir(struct file *file, struct dir_context *ctx) { struct inode *inode = file_inode(file); unsigned long npages = dir_blocks(inode); - unsigned int bit_pos = 0; struct f2fs_dentry_block *dentry_blk = NULL; - struct f2fs_dir_entry *de = NULL; struct page *dentry_page = NULL; struct file_ra_state *ra = &file->f_ra; unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK); - unsigned char d_type = DT_UNKNOWN; if (f2fs_has_inline_dentry(inode)) return f2fs_read_inline_dir(file, ctx); - bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK); - /* readahead for multi pages of dir */ if (npages - n > 1 && !ra_has_index(ra, n)) page_cache_sync_readahead(inode->i_mapping, ra, file, n, @@ -734,28 +761,13 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) continue; dentry_blk = kmap(dentry_page); - while (bit_pos < NR_DENTRY_IN_BLOCK) { - bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, - NR_DENTRY_IN_BLOCK, - bit_pos); - if (bit_pos >= NR_DENTRY_IN_BLOCK) - break; - - de = &dentry_blk->dentry[bit_pos]; - if (de->file_type < F2FS_FT_MAX) - d_type = f2fs_filetype_table[de->file_type]; - else - d_type = DT_UNKNOWN; - if (!dir_emit(ctx, - dentry_blk->filename[bit_pos], - le16_to_cpu(de->name_len), - le32_to_cpu(de->ino), d_type)) - goto stop; - bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); - ctx->pos = n * NR_DENTRY_IN_BLOCK + bit_pos; - } - bit_pos = 0; + if (f2fs_fill_dentries(ctx, + &dentry_blk->dentry_bitmap, dentry_blk->dentry, + dentry_blk->filename, + NR_DENTRY_IN_BLOCK, n * NR_DENTRY_IN_BLOCK)) + goto stop; + ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK; kunmap(dentry_page); f2fs_put_page(dentry_page, 1); |