diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2013-05-22 14:29:35 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-06-29 04:56:55 -0400 |
commit | 002f8bec854432db56f30121325867db6e248a03 (patch) | |
tree | 70d3321bc6263f7a90848bc98253252379b9e7bd | |
parent | f0f49ef5ce0a9393a084073ad4cbdf30464ad896 (diff) |
[readdir] convert hfs
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/hfs/dir.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/fs/hfs/dir.c b/fs/hfs/dir.c index e0101b6fb0d7..145566851e7a 100644 --- a/fs/hfs/dir.c +++ b/fs/hfs/dir.c | |||
@@ -51,9 +51,9 @@ done: | |||
51 | /* | 51 | /* |
52 | * hfs_readdir | 52 | * hfs_readdir |
53 | */ | 53 | */ |
54 | static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | 54 | static int hfs_readdir(struct file *file, struct dir_context *ctx) |
55 | { | 55 | { |
56 | struct inode *inode = file_inode(filp); | 56 | struct inode *inode = file_inode(file); |
57 | struct super_block *sb = inode->i_sb; | 57 | struct super_block *sb = inode->i_sb; |
58 | int len, err; | 58 | int len, err; |
59 | char strbuf[HFS_MAX_NAMELEN]; | 59 | char strbuf[HFS_MAX_NAMELEN]; |
@@ -62,7 +62,7 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
62 | struct hfs_readdir_data *rd; | 62 | struct hfs_readdir_data *rd; |
63 | u16 type; | 63 | u16 type; |
64 | 64 | ||
65 | if (filp->f_pos >= inode->i_size) | 65 | if (ctx->pos >= inode->i_size) |
66 | return 0; | 66 | return 0; |
67 | 67 | ||
68 | err = hfs_find_init(HFS_SB(sb)->cat_tree, &fd); | 68 | err = hfs_find_init(HFS_SB(sb)->cat_tree, &fd); |
@@ -73,14 +73,13 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
73 | if (err) | 73 | if (err) |
74 | goto out; | 74 | goto out; |
75 | 75 | ||
76 | switch ((u32)filp->f_pos) { | 76 | if (ctx->pos == 0) { |
77 | case 0: | ||
78 | /* This is completely artificial... */ | 77 | /* This is completely artificial... */ |
79 | if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR)) | 78 | if (!dir_emit_dot(file, ctx)) |
80 | goto out; | 79 | goto out; |
81 | filp->f_pos++; | 80 | ctx->pos = 1; |
82 | /* fall through */ | 81 | } |
83 | case 1: | 82 | if (ctx->pos == 1) { |
84 | if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) { | 83 | if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) { |
85 | err = -EIO; | 84 | err = -EIO; |
86 | goto out; | 85 | goto out; |
@@ -97,18 +96,16 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
97 | // err = -EIO; | 96 | // err = -EIO; |
98 | // goto out; | 97 | // goto out; |
99 | //} | 98 | //} |
100 | if (filldir(dirent, "..", 2, 1, | 99 | if (!dir_emit(ctx, "..", 2, |
101 | be32_to_cpu(entry.thread.ParID), DT_DIR)) | 100 | be32_to_cpu(entry.thread.ParID), DT_DIR)) |
102 | goto out; | 101 | goto out; |
103 | filp->f_pos++; | 102 | ctx->pos = 2; |
104 | /* fall through */ | ||
105 | default: | ||
106 | if (filp->f_pos >= inode->i_size) | ||
107 | goto out; | ||
108 | err = hfs_brec_goto(&fd, filp->f_pos - 1); | ||
109 | if (err) | ||
110 | goto out; | ||
111 | } | 103 | } |
104 | if (ctx->pos >= inode->i_size) | ||
105 | goto out; | ||
106 | err = hfs_brec_goto(&fd, ctx->pos - 1); | ||
107 | if (err) | ||
108 | goto out; | ||
112 | 109 | ||
113 | for (;;) { | 110 | for (;;) { |
114 | if (be32_to_cpu(fd.key->cat.ParID) != inode->i_ino) { | 111 | if (be32_to_cpu(fd.key->cat.ParID) != inode->i_ino) { |
@@ -131,7 +128,7 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
131 | err = -EIO; | 128 | err = -EIO; |
132 | goto out; | 129 | goto out; |
133 | } | 130 | } |
134 | if (filldir(dirent, strbuf, len, filp->f_pos, | 131 | if (!dir_emit(ctx, strbuf, len, |
135 | be32_to_cpu(entry.dir.DirID), DT_DIR)) | 132 | be32_to_cpu(entry.dir.DirID), DT_DIR)) |
136 | break; | 133 | break; |
137 | } else if (type == HFS_CDR_FIL) { | 134 | } else if (type == HFS_CDR_FIL) { |
@@ -140,7 +137,7 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
140 | err = -EIO; | 137 | err = -EIO; |
141 | goto out; | 138 | goto out; |
142 | } | 139 | } |
143 | if (filldir(dirent, strbuf, len, filp->f_pos, | 140 | if (!dir_emit(ctx, strbuf, len, |
144 | be32_to_cpu(entry.file.FlNum), DT_REG)) | 141 | be32_to_cpu(entry.file.FlNum), DT_REG)) |
145 | break; | 142 | break; |
146 | } else { | 143 | } else { |
@@ -148,22 +145,22 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
148 | err = -EIO; | 145 | err = -EIO; |
149 | goto out; | 146 | goto out; |
150 | } | 147 | } |
151 | filp->f_pos++; | 148 | ctx->pos++; |
152 | if (filp->f_pos >= inode->i_size) | 149 | if (ctx->pos >= inode->i_size) |
153 | goto out; | 150 | goto out; |
154 | err = hfs_brec_goto(&fd, 1); | 151 | err = hfs_brec_goto(&fd, 1); |
155 | if (err) | 152 | if (err) |
156 | goto out; | 153 | goto out; |
157 | } | 154 | } |
158 | rd = filp->private_data; | 155 | rd = file->private_data; |
159 | if (!rd) { | 156 | if (!rd) { |
160 | rd = kmalloc(sizeof(struct hfs_readdir_data), GFP_KERNEL); | 157 | rd = kmalloc(sizeof(struct hfs_readdir_data), GFP_KERNEL); |
161 | if (!rd) { | 158 | if (!rd) { |
162 | err = -ENOMEM; | 159 | err = -ENOMEM; |
163 | goto out; | 160 | goto out; |
164 | } | 161 | } |
165 | filp->private_data = rd; | 162 | file->private_data = rd; |
166 | rd->file = filp; | 163 | rd->file = file; |
167 | list_add(&rd->list, &HFS_I(inode)->open_dir_list); | 164 | list_add(&rd->list, &HFS_I(inode)->open_dir_list); |
168 | } | 165 | } |
169 | memcpy(&rd->key, &fd.key, sizeof(struct hfs_cat_key)); | 166 | memcpy(&rd->key, &fd.key, sizeof(struct hfs_cat_key)); |
@@ -306,7 +303,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
306 | 303 | ||
307 | const struct file_operations hfs_dir_operations = { | 304 | const struct file_operations hfs_dir_operations = { |
308 | .read = generic_read_dir, | 305 | .read = generic_read_dir, |
309 | .readdir = hfs_readdir, | 306 | .iterate = hfs_readdir, |
310 | .llseek = generic_file_llseek, | 307 | .llseek = generic_file_llseek, |
311 | .release = hfs_dir_release, | 308 | .release = hfs_dir_release, |
312 | }; | 309 | }; |