aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/dir.c
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2014-10-19 01:52:52 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2014-11-03 19:07:34 -0500
commit7b3cd7d6f026784b1a2a74b6e207b26253d9d780 (patch)
tree25d134417cd0a8cedb380af01c252e8f127f4c8d /fs/f2fs/dir.c
parent5ab18570b85cf3071875a36b88bc5ed27d0b6ef7 (diff)
f2fs: introduce f2fs_dentry_ptr structure for code clean-up
This patch introduces f2fs_dentry_ptr structure for the use of a function parameter in inline_dentry operations. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/dir.c')
-rw-r--r--fs/f2fs/dir.c61
1 files changed, 29 insertions, 32 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 23a5da88ba66..4f029a1b0cf0 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -95,13 +95,13 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page,
95{ 95{
96 struct f2fs_dentry_block *dentry_blk; 96 struct f2fs_dentry_block *dentry_blk;
97 struct f2fs_dir_entry *de; 97 struct f2fs_dir_entry *de;
98 98 struct f2fs_dentry_ptr d;
99 *max_slots = NR_DENTRY_IN_BLOCK;
100 99
101 dentry_blk = (struct f2fs_dentry_block *)kmap(dentry_page); 100 dentry_blk = (struct f2fs_dentry_block *)kmap(dentry_page);
102 de = find_target_dentry(name, max_slots, &dentry_blk->dentry_bitmap, 101
103 dentry_blk->dentry, 102 make_dentry_ptr(&d, (void *)dentry_blk, 1);
104 dentry_blk->filename); 103 de = find_target_dentry(name, max_slots, &d);
104
105 if (de) 105 if (de)
106 *res_page = dentry_page; 106 *res_page = dentry_page;
107 else 107 else
@@ -111,50 +111,49 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page,
111 * For the most part, it should be a bug when name_len is zero. 111 * For the most part, it should be a bug when name_len is zero.
112 * We stop here for figuring out where the bugs has occurred. 112 * We stop here for figuring out where the bugs has occurred.
113 */ 113 */
114 f2fs_bug_on(F2FS_P_SB(dentry_page), *max_slots < 0); 114 f2fs_bug_on(F2FS_P_SB(dentry_page), d.max < 0);
115 return de; 115 return de;
116} 116}
117 117
118struct f2fs_dir_entry *find_target_dentry(struct qstr *name, int *max_slots, 118struct f2fs_dir_entry *find_target_dentry(struct qstr *name, int *max_slots,
119 const void *bitmap, struct f2fs_dir_entry *dentry, 119 struct f2fs_dentry_ptr *d)
120 __u8 (*filenames)[F2FS_SLOT_LEN])
121{ 120{
122 struct f2fs_dir_entry *de; 121 struct f2fs_dir_entry *de;
123 unsigned long bit_pos = 0; 122 unsigned long bit_pos = 0;
124 f2fs_hash_t namehash = f2fs_dentry_hash(name); 123 f2fs_hash_t namehash = f2fs_dentry_hash(name);
125 int max_bits = *max_slots;
126 int max_len = 0; 124 int max_len = 0;
127 125
128 *max_slots = 0; 126 if (max_slots)
129 while (bit_pos < max_bits) { 127 *max_slots = 0;
130 if (!test_bit_le(bit_pos, bitmap)) { 128 while (bit_pos < d->max) {
129 if (!test_bit_le(bit_pos, d->bitmap)) {
131 if (bit_pos == 0) 130 if (bit_pos == 0)
132 max_len = 1; 131 max_len = 1;
133 else if (!test_bit_le(bit_pos - 1, bitmap)) 132 else if (!test_bit_le(bit_pos - 1, d->bitmap))
134 max_len++; 133 max_len++;
135 bit_pos++; 134 bit_pos++;
136 continue; 135 continue;
137 } 136 }
138 de = &dentry[bit_pos]; 137 de = &d->dentry[bit_pos];
139 if (early_match_name(name->len, namehash, de) && 138 if (early_match_name(name->len, namehash, de) &&
140 !memcmp(filenames[bit_pos], name->name, name->len)) 139 !memcmp(d->filename[bit_pos], name->name, name->len))
141 goto found; 140 goto found;
142 141
143 if (*max_slots >= 0 && max_len > *max_slots) { 142 if (max_slots && *max_slots >= 0 && max_len > *max_slots) {
144 *max_slots = max_len; 143 *max_slots = max_len;
145 max_len = 0; 144 max_len = 0;
146 } 145 }
147 146
148 /* remain bug on condition */ 147 /* remain bug on condition */
149 if (unlikely(!de->name_len)) 148 if (unlikely(!de->name_len))
150 *max_slots = -1; 149 d->max = -1;
151 150
152 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 151 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
153 } 152 }
154 153
155 de = NULL; 154 de = NULL;
156found: 155found:
157 if (max_len > *max_slots) 156 if (max_slots && max_len > *max_slots)
158 *max_slots = max_len; 157 *max_slots = max_len;
159 return de; 158 return de;
160} 159}
@@ -706,28 +705,26 @@ bool f2fs_empty_dir(struct inode *dir)
706 return true; 705 return true;
707} 706}
708 707
709bool f2fs_fill_dentries(struct dir_context *ctx, 708bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
710 const void *bitmap, struct f2fs_dir_entry *dentry, 709 unsigned int start_pos)
711 __u8 (*filenames)[F2FS_SLOT_LEN], int max,
712 unsigned int start_pos)
713{ 710{
714 unsigned char d_type = DT_UNKNOWN; 711 unsigned char d_type = DT_UNKNOWN;
715 unsigned int bit_pos; 712 unsigned int bit_pos;
716 struct f2fs_dir_entry *de = NULL; 713 struct f2fs_dir_entry *de = NULL;
717 714
718 bit_pos = ((unsigned long)ctx->pos % max); 715 bit_pos = ((unsigned long)ctx->pos % d->max);
719 716
720 while (bit_pos < max) { 717 while (bit_pos < d->max) {
721 bit_pos = find_next_bit_le(bitmap, max, bit_pos); 718 bit_pos = find_next_bit_le(d->bitmap, d->max, bit_pos);
722 if (bit_pos >= max) 719 if (bit_pos >= d->max)
723 break; 720 break;
724 721
725 de = &dentry[bit_pos]; 722 de = &d->dentry[bit_pos];
726 if (de->file_type < F2FS_FT_MAX) 723 if (de->file_type < F2FS_FT_MAX)
727 d_type = f2fs_filetype_table[de->file_type]; 724 d_type = f2fs_filetype_table[de->file_type];
728 else 725 else
729 d_type = DT_UNKNOWN; 726 d_type = DT_UNKNOWN;
730 if (!dir_emit(ctx, filenames[bit_pos], 727 if (!dir_emit(ctx, d->filename[bit_pos],
731 le16_to_cpu(de->name_len), 728 le16_to_cpu(de->name_len),
732 le32_to_cpu(de->ino), d_type)) 729 le32_to_cpu(de->ino), d_type))
733 return true; 730 return true;
@@ -746,6 +743,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
746 struct page *dentry_page = NULL; 743 struct page *dentry_page = NULL;
747 struct file_ra_state *ra = &file->f_ra; 744 struct file_ra_state *ra = &file->f_ra;
748 unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK); 745 unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
746 struct f2fs_dentry_ptr d;
749 747
750 if (f2fs_has_inline_dentry(inode)) 748 if (f2fs_has_inline_dentry(inode))
751 return f2fs_read_inline_dir(file, ctx); 749 return f2fs_read_inline_dir(file, ctx);
@@ -762,10 +760,9 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
762 760
763 dentry_blk = kmap(dentry_page); 761 dentry_blk = kmap(dentry_page);
764 762
765 if (f2fs_fill_dentries(ctx, 763 make_dentry_ptr(&d, (void *)dentry_blk, 1);
766 &dentry_blk->dentry_bitmap, dentry_blk->dentry, 764
767 dentry_blk->filename, 765 if (f2fs_fill_dentries(ctx, &d, n * NR_DENTRY_IN_BLOCK))
768 NR_DENTRY_IN_BLOCK, n * NR_DENTRY_IN_BLOCK))
769 goto stop; 766 goto stop;
770 767
771 ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK; 768 ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK;