]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
[readdir] convert f2fs
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 17 May 2013 22:02:17 +0000 (18:02 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 29 Jun 2013 08:56:46 +0000 (12:56 +0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/cramfs/inode.c
fs/f2fs/dir.c

index 35b1c7bd18b758a30fc03fd4267151d18fcb2281..e501ac3a49ff7380a1bd2644ecc8abc3f648ce64 100644 (file)
@@ -349,18 +349,17 @@ static int cramfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 /*
  * Read a cramfs directory entry.
  */
-static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int cramfs_readdir(struct file *file, struct dir_context *ctx)
 {
-       struct inode *inode = file_inode(filp);
+       struct inode *inode = file_inode(file);
        struct super_block *sb = inode->i_sb;
        char *buf;
        unsigned int offset;
-       int copied;
 
        /* Offset within the thing. */
-       offset = filp->f_pos;
-       if (offset >= inode->i_size)
+       if (ctx->pos >= inode->i_size)
                return 0;
+       offset = ctx->pos;
        /* Directory entries are always 4-byte aligned */
        if (offset & 3)
                return -EINVAL;
@@ -369,14 +368,13 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
        if (!buf)
                return -ENOMEM;
 
-       copied = 0;
        while (offset < inode->i_size) {
                struct cramfs_inode *de;
                unsigned long nextoffset;
                char *name;
                ino_t ino;
                umode_t mode;
-               int namelen, error;
+               int namelen;
 
                mutex_lock(&read_mutex);
                de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+CRAMFS_MAXPATHLEN);
@@ -402,13 +400,10 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                                break;
                        namelen--;
                }
-               error = filldir(dirent, buf, namelen, offset, ino, mode >> 12);
-               if (error)
+               if (!dir_emit(ctx, buf, namelen, ino, mode >> 12))
                        break;
 
-               offset = nextoffset;
-               filp->f_pos = offset;
-               copied++;
+               ctx->pos = offset = nextoffset;
        }
        kfree(buf);
        return 0;
@@ -547,7 +542,7 @@ static const struct address_space_operations cramfs_aops = {
 static const struct file_operations cramfs_directory_operations = {
        .llseek         = generic_file_llseek,
        .read           = generic_read_dir,
-       .readdir        = cramfs_readdir,
+       .iterate        = cramfs_readdir,
 };
 
 static const struct inode_operations cramfs_dir_inode_operations = {
index 1ac6b93036b7a23980a66d4f6987a82c34ff32df..600bb5efe60379628672a0dabefcb673a8479042 100644 (file)
@@ -591,24 +591,19 @@ bool f2fs_empty_dir(struct inode *dir)
        return true;
 }
 
-static int f2fs_readdir(struct file *file, void *dirent, filldir_t filldir)
+static int f2fs_readdir(struct file *file, struct dir_context *ctx)
 {
-       unsigned long pos = file->f_pos;
        struct inode *inode = file_inode(file);
        unsigned long npages = dir_blocks(inode);
-       unsigned char *types = NULL;
        unsigned int bit_pos = 0, start_bit_pos = 0;
-       int over = 0;
        struct f2fs_dentry_block *dentry_blk = NULL;
        struct f2fs_dir_entry *de = NULL;
        struct page *dentry_page = NULL;
-       unsigned int n = 0;
+       unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
        unsigned char d_type = DT_UNKNOWN;
        int slots;
 
-       types = f2fs_filetype_table;
-       bit_pos = (pos % NR_DENTRY_IN_BLOCK);
-       n = (pos / NR_DENTRY_IN_BLOCK);
+       bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK);
 
        for ( ; n < npages; n++) {
                dentry_page = get_lock_data_page(inode, n);
@@ -618,31 +613,28 @@ static int f2fs_readdir(struct file *file, void *dirent, filldir_t filldir)
                start_bit_pos = bit_pos;
                dentry_blk = kmap(dentry_page);
                while (bit_pos < NR_DENTRY_IN_BLOCK) {
-                       d_type = DT_UNKNOWN;
                        bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
                                                        NR_DENTRY_IN_BLOCK,
                                                        bit_pos);
                        if (bit_pos >= NR_DENTRY_IN_BLOCK)
                                break;
 
+                       ctx->pos += bit_pos - start_bit_pos;
                        de = &dentry_blk->dentry[bit_pos];
-                       if (types && de->file_type < F2FS_FT_MAX)
-                               d_type = types[de->file_type];
-
-                       over = filldir(dirent,
-                                       dentry_blk->filename[bit_pos],
-                                       le16_to_cpu(de->name_len),
-                                       (n * NR_DENTRY_IN_BLOCK) + bit_pos,
-                                       le32_to_cpu(de->ino), d_type);
-                       if (over) {
-                               file->f_pos += bit_pos - start_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 success;
-                       }
                        slots = GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
                        bit_pos += slots;
                }
                bit_pos = 0;
-               file->f_pos = (n + 1) * NR_DENTRY_IN_BLOCK;
+               ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK;
                kunmap(dentry_page);
                f2fs_put_page(dentry_page, 1);
                dentry_page = NULL;
@@ -659,7 +651,7 @@ success:
 const struct file_operations f2fs_dir_operations = {
        .llseek         = generic_file_llseek,
        .read           = generic_read_dir,
-       .readdir        = f2fs_readdir,
+       .iterate        = f2fs_readdir,
        .fsync          = f2fs_sync_file,
        .unlocked_ioctl = f2fs_ioctl,
 };