Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[readdir] convert affs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 0edf977d 2638ffba

+24 -45
+24 -45
fs/affs/dir.c
··· 15 15 16 16 #include "affs.h" 17 17 18 - static int affs_readdir(struct file *, void *, filldir_t); 18 + static int affs_readdir(struct file *, struct dir_context *); 19 19 20 20 const struct file_operations affs_dir_operations = { 21 21 .read = generic_read_dir, 22 22 .llseek = generic_file_llseek, 23 - .readdir = affs_readdir, 23 + .iterate = affs_readdir, 24 24 .fsync = affs_file_fsync, 25 25 }; 26 26 ··· 40 40 }; 41 41 42 42 static int 43 - affs_readdir(struct file *filp, void *dirent, filldir_t filldir) 43 + affs_readdir(struct file *file, struct dir_context *ctx) 44 44 { 45 - struct inode *inode = file_inode(filp); 45 + struct inode *inode = file_inode(file); 46 46 struct super_block *sb = inode->i_sb; 47 - struct buffer_head *dir_bh; 48 - struct buffer_head *fh_bh; 47 + struct buffer_head *dir_bh = NULL; 48 + struct buffer_head *fh_bh = NULL; 49 49 unsigned char *name; 50 50 int namelen; 51 51 u32 i; 52 52 int hash_pos; 53 53 int chain_pos; 54 - u32 f_pos; 55 54 u32 ino; 56 - int stored; 57 - int res; 58 55 59 - pr_debug("AFFS: readdir(ino=%lu,f_pos=%lx)\n",inode->i_ino,(unsigned long)filp->f_pos); 56 + pr_debug("AFFS: readdir(ino=%lu,f_pos=%lx)\n",inode->i_ino,(unsigned long)ctx->pos); 60 57 61 - stored = 0; 62 - res = -EIO; 63 - dir_bh = NULL; 64 - fh_bh = NULL; 65 - f_pos = filp->f_pos; 66 - 67 - if (f_pos == 0) { 68 - filp->private_data = (void *)0; 69 - if (filldir(dirent, ".", 1, f_pos, inode->i_ino, DT_DIR) < 0) 58 + if (ctx->pos < 2) { 59 + file->private_data = (void *)0; 60 + if (!dir_emit_dots(file, ctx)) 70 61 return 0; 71 - filp->f_pos = f_pos = 1; 72 - stored++; 73 - } 74 - if (f_pos == 1) { 75 - if (filldir(dirent, "..", 2, f_pos, parent_ino(filp->f_path.dentry), DT_DIR) < 0) 76 - return stored; 77 - filp->f_pos = f_pos = 2; 78 - stored++; 79 62 } 80 63 81 64 affs_lock_dir(inode); 82 - chain_pos = (f_pos - 2) & 0xffff; 83 - hash_pos = (f_pos - 2) >> 16; 65 + chain_pos = (ctx->pos - 2) & 0xffff; 66 + hash_pos = (ctx->pos - 2) >> 16; 84 67 if (chain_pos == 0xffff) { 85 68 affs_warning(sb, "readdir", "More than 65535 entries in chain"); 86 69 chain_pos = 0; 87 70 hash_pos++; 88 - filp->f_pos = ((hash_pos << 16) | chain_pos) + 2; 71 + ctx->pos = ((hash_pos << 16) | chain_pos) + 2; 89 72 } 90 73 dir_bh = affs_bread(sb, inode->i_ino); 91 74 if (!dir_bh) ··· 77 94 /* If the directory hasn't changed since the last call to readdir(), 78 95 * we can jump directly to where we left off. 79 96 */ 80 - ino = (u32)(long)filp->private_data; 81 - if (ino && filp->f_version == inode->i_version) { 97 + ino = (u32)(long)file->private_data; 98 + if (ino && file->f_version == inode->i_version) { 82 99 pr_debug("AFFS: readdir() left off=%d\n", ino); 83 100 goto inside; 84 101 } ··· 88 105 fh_bh = affs_bread(sb, ino); 89 106 if (!fh_bh) { 90 107 affs_error(sb, "readdir","Cannot read block %d", i); 91 - goto readdir_out; 108 + return -EIO; 92 109 } 93 110 ino = be32_to_cpu(AFFS_TAIL(sb, fh_bh)->hash_chain); 94 111 affs_brelse(fh_bh); ··· 102 119 ino = be32_to_cpu(AFFS_HEAD(dir_bh)->table[hash_pos]); 103 120 if (!ino) 104 121 continue; 105 - f_pos = (hash_pos << 16) + 2; 122 + ctx->pos = (hash_pos << 16) + 2; 106 123 inside: 107 124 do { 108 125 fh_bh = affs_bread(sb, ino); 109 126 if (!fh_bh) { 110 127 affs_error(sb, "readdir","Cannot read block %d", ino); 111 - goto readdir_done; 128 + break; 112 129 } 113 130 114 131 namelen = min(AFFS_TAIL(sb, fh_bh)->name[0], (u8)30); 115 132 name = AFFS_TAIL(sb, fh_bh)->name + 1; 116 133 pr_debug("AFFS: readdir(): filldir(\"%.*s\", ino=%u), hash=%d, f_pos=%x\n", 117 - namelen, name, ino, hash_pos, f_pos); 118 - if (filldir(dirent, name, namelen, f_pos, ino, DT_UNKNOWN) < 0) 134 + namelen, name, ino, hash_pos, (u32)ctx->pos); 135 + if (!dir_emit(ctx, name, namelen, ino, DT_UNKNOWN)) 119 136 goto readdir_done; 120 - stored++; 121 - f_pos++; 137 + ctx->pos++; 122 138 ino = be32_to_cpu(AFFS_TAIL(sb, fh_bh)->hash_chain); 123 139 affs_brelse(fh_bh); 124 140 fh_bh = NULL; 125 141 } while (ino); 126 142 } 127 143 readdir_done: 128 - filp->f_pos = f_pos; 129 - filp->f_version = inode->i_version; 130 - filp->private_data = (void *)(long)ino; 131 - res = stored; 144 + file->f_version = inode->i_version; 145 + file->private_data = (void *)(long)ino; 132 146 133 147 readdir_out: 134 148 affs_brelse(dir_bh); 135 149 affs_brelse(fh_bh); 136 150 affs_unlock_dir(inode); 137 - pr_debug("AFFS: readdir()=%d\n", stored); 138 - return res; 151 + return 0; 139 152 }