aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/dir.c
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk.kim@samsung.com>2013-07-05 04:28:12 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-07-08 05:35:48 -0400
commit99b072bb38c9b398bc7c3fc8a0f30d0801f78750 (patch)
tree0162568c00d24d580c1ed61963eb00b9025bc685 /fs/f2fs/dir.c
parent3de91f92377f1477c88a58bcad5b5615ffc4aad5 (diff)
f2fs: fix readdir incorrectness
In the previous Al Viro's readdir patch set, there occurs a bug when running xfstest: 006 as follows. [Error output] alpha size = 4, name length = 6, total files = 4096, nproc=1 1023 files created rm: cannot remove `/mnt/f2fs/permname.15150/a': Directory not empty [Correct output] alpha size = 4, name length = 6, total files = 4096, nproc=1 4097 files created This bug is due to the misupdate of directory position in ctx. So, this patch fixes this. [AV: fixed a braino] CC: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/f2fs/dir.c')
-rw-r--r--fs/f2fs/dir.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 9d1cd423450d..62f0d5977c64 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -610,13 +610,12 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
610{ 610{
611 struct inode *inode = file_inode(file); 611 struct inode *inode = file_inode(file);
612 unsigned long npages = dir_blocks(inode); 612 unsigned long npages = dir_blocks(inode);
613 unsigned int bit_pos = 0, start_bit_pos = 0; 613 unsigned int bit_pos = 0;
614 struct f2fs_dentry_block *dentry_blk = NULL; 614 struct f2fs_dentry_block *dentry_blk = NULL;
615 struct f2fs_dir_entry *de = NULL; 615 struct f2fs_dir_entry *de = NULL;
616 struct page *dentry_page = NULL; 616 struct page *dentry_page = NULL;
617 unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK); 617 unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
618 unsigned char d_type = DT_UNKNOWN; 618 unsigned char d_type = DT_UNKNOWN;
619 int slots;
620 619
621 bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK); 620 bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK);
622 621
@@ -625,7 +624,6 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
625 if (IS_ERR(dentry_page)) 624 if (IS_ERR(dentry_page))
626 continue; 625 continue;
627 626
628 start_bit_pos = bit_pos;
629 dentry_blk = kmap(dentry_page); 627 dentry_blk = kmap(dentry_page);
630 while (bit_pos < NR_DENTRY_IN_BLOCK) { 628 while (bit_pos < NR_DENTRY_IN_BLOCK) {
631 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, 629 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
@@ -634,19 +632,19 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
634 if (bit_pos >= NR_DENTRY_IN_BLOCK) 632 if (bit_pos >= NR_DENTRY_IN_BLOCK)
635 break; 633 break;
636 634
637 ctx->pos += bit_pos - start_bit_pos;
638 de = &dentry_blk->dentry[bit_pos]; 635 de = &dentry_blk->dentry[bit_pos];
639 if (de->file_type < F2FS_FT_MAX) 636 if (de->file_type < F2FS_FT_MAX)
640 d_type = f2fs_filetype_table[de->file_type]; 637 d_type = f2fs_filetype_table[de->file_type];
641 else 638 else
642 d_type = DT_UNKNOWN; 639 d_type = DT_UNKNOWN;
643 if (!dir_emit(ctx, 640 if (!dir_emit(ctx,
644 dentry_blk->filename[bit_pos], 641 dentry_blk->filename[bit_pos],
645 le16_to_cpu(de->name_len), 642 le16_to_cpu(de->name_len),
646 le32_to_cpu(de->ino), d_type)) 643 le32_to_cpu(de->ino), d_type))
647 goto success; 644 goto stop;
648 slots = GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 645
649 bit_pos += slots; 646 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
647 ctx->pos = n * NR_DENTRY_IN_BLOCK + bit_pos;
650 } 648 }
651 bit_pos = 0; 649 bit_pos = 0;
652 ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK; 650 ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK;
@@ -654,7 +652,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
654 f2fs_put_page(dentry_page, 1); 652 f2fs_put_page(dentry_page, 1);
655 dentry_page = NULL; 653 dentry_page = NULL;
656 } 654 }
657success: 655stop:
658 if (dentry_page && !IS_ERR(dentry_page)) { 656 if (dentry_page && !IS_ERR(dentry_page)) {
659 kunmap(dentry_page); 657 kunmap(dentry_page);
660 f2fs_put_page(dentry_page, 1); 658 f2fs_put_page(dentry_page, 1);