aboutsummaryrefslogtreecommitdiffstats
path: root/fs/9p
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2013-05-17 17:51:41 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-06-29 04:56:45 -0400
commit8f29843a5187983965f1da07b8ebe5a1eb3f2a4a (patch)
treebcd92299c9a70b7919e13e3a1daf9331fc1f68aa /fs/9p
parent0edf977d2ae32b492780828d4b5bd41c5d51cb02 (diff)
[readdir] convert 9p
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/9p')
-rw-r--r--fs/9p/vfs_dir.c72
1 files changed, 28 insertions, 44 deletions
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index be1e34adc3c6..4d0c2e0be7e5 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -101,16 +101,15 @@ static struct p9_rdir *v9fs_alloc_rdir_buf(struct file *filp, int buflen)
101} 101}
102 102
103/** 103/**
104 * v9fs_dir_readdir - read a directory 104 * v9fs_dir_readdir - iterate through a directory
105 * @filp: opened file structure 105 * @file: opened file structure
106 * @dirent: directory structure ??? 106 * @ctx: actor we feed the entries to
107 * @filldir: function to populate directory structure ???
108 * 107 *
109 */ 108 */
110 109
111static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) 110static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
112{ 111{
113 int over; 112 bool over;
114 struct p9_wstat st; 113 struct p9_wstat st;
115 int err = 0; 114 int err = 0;
116 struct p9_fid *fid; 115 struct p9_fid *fid;
@@ -118,19 +117,19 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
118 int reclen = 0; 117 int reclen = 0;
119 struct p9_rdir *rdir; 118 struct p9_rdir *rdir;
120 119
121 p9_debug(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); 120 p9_debug(P9_DEBUG_VFS, "name %s\n", file->f_path.dentry->d_name.name);
122 fid = filp->private_data; 121 fid = file->private_data;
123 122
124 buflen = fid->clnt->msize - P9_IOHDRSZ; 123 buflen = fid->clnt->msize - P9_IOHDRSZ;
125 124
126 rdir = v9fs_alloc_rdir_buf(filp, buflen); 125 rdir = v9fs_alloc_rdir_buf(file, buflen);
127 if (!rdir) 126 if (!rdir)
128 return -ENOMEM; 127 return -ENOMEM;
129 128
130 while (1) { 129 while (1) {
131 if (rdir->tail == rdir->head) { 130 if (rdir->tail == rdir->head) {
132 err = v9fs_file_readn(filp, rdir->buf, NULL, 131 err = v9fs_file_readn(file, rdir->buf, NULL,
133 buflen, filp->f_pos); 132 buflen, ctx->pos);
134 if (err <= 0) 133 if (err <= 0)
135 return err; 134 return err;
136 135
@@ -148,51 +147,45 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
148 } 147 }
149 reclen = st.size+2; 148 reclen = st.size+2;
150 149
151 over = filldir(dirent, st.name, strlen(st.name), 150 over = !dir_emit(ctx, st.name, strlen(st.name),
152 filp->f_pos, v9fs_qid2ino(&st.qid), dt_type(&st)); 151 v9fs_qid2ino(&st.qid), dt_type(&st));
153
154 p9stat_free(&st); 152 p9stat_free(&st);
155
156 if (over) 153 if (over)
157 return 0; 154 return 0;
158 155
159 rdir->head += reclen; 156 rdir->head += reclen;
160 filp->f_pos += reclen; 157 ctx->pos += reclen;
161 } 158 }
162 } 159 }
163} 160}
164 161
165/** 162/**
166 * v9fs_dir_readdir_dotl - read a directory 163 * v9fs_dir_readdir_dotl - iterate through a directory
167 * @filp: opened file structure 164 * @file: opened file structure
168 * @dirent: buffer to fill dirent structures 165 * @ctx: actor we feed the entries to
169 * @filldir: function to populate dirent structures
170 * 166 *
171 */ 167 */
172static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent, 168static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx)
173 filldir_t filldir)
174{ 169{
175 int over;
176 int err = 0; 170 int err = 0;
177 struct p9_fid *fid; 171 struct p9_fid *fid;
178 int buflen; 172 int buflen;
179 struct p9_rdir *rdir; 173 struct p9_rdir *rdir;
180 struct p9_dirent curdirent; 174 struct p9_dirent curdirent;
181 u64 oldoffset = 0;
182 175
183 p9_debug(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); 176 p9_debug(P9_DEBUG_VFS, "name %s\n", file->f_path.dentry->d_name.name);
184 fid = filp->private_data; 177 fid = file->private_data;
185 178
186 buflen = fid->clnt->msize - P9_READDIRHDRSZ; 179 buflen = fid->clnt->msize - P9_READDIRHDRSZ;
187 180
188 rdir = v9fs_alloc_rdir_buf(filp, buflen); 181 rdir = v9fs_alloc_rdir_buf(file, buflen);
189 if (!rdir) 182 if (!rdir)
190 return -ENOMEM; 183 return -ENOMEM;
191 184
192 while (1) { 185 while (1) {
193 if (rdir->tail == rdir->head) { 186 if (rdir->tail == rdir->head) {
194 err = p9_client_readdir(fid, rdir->buf, buflen, 187 err = p9_client_readdir(fid, rdir->buf, buflen,
195 filp->f_pos); 188 ctx->pos);
196 if (err <= 0) 189 if (err <= 0)
197 return err; 190 return err;
198 191
@@ -210,22 +203,13 @@ static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
210 return -EIO; 203 return -EIO;
211 } 204 }
212 205
213 /* d_off in dirent structure tracks the offset into 206 if (!dir_emit(ctx, curdirent.d_name,
214 * the next dirent in the dir. However, filldir() 207 strlen(curdirent.d_name),
215 * expects offset into the current dirent. Hence 208 v9fs_qid2ino(&curdirent.qid),
216 * while calling filldir send the offset from the 209 curdirent.d_type))
217 * previous dirent structure.
218 */
219 over = filldir(dirent, curdirent.d_name,
220 strlen(curdirent.d_name),
221 oldoffset, v9fs_qid2ino(&curdirent.qid),
222 curdirent.d_type);
223 oldoffset = curdirent.d_off;
224
225 if (over)
226 return 0; 210 return 0;
227 211
228 filp->f_pos = curdirent.d_off; 212 ctx->pos = curdirent.d_off;
229 rdir->head += err; 213 rdir->head += err;
230 } 214 }
231 } 215 }
@@ -254,7 +238,7 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
254const struct file_operations v9fs_dir_operations = { 238const struct file_operations v9fs_dir_operations = {
255 .read = generic_read_dir, 239 .read = generic_read_dir,
256 .llseek = generic_file_llseek, 240 .llseek = generic_file_llseek,
257 .readdir = v9fs_dir_readdir, 241 .iterate = v9fs_dir_readdir,
258 .open = v9fs_file_open, 242 .open = v9fs_file_open,
259 .release = v9fs_dir_release, 243 .release = v9fs_dir_release,
260}; 244};
@@ -262,7 +246,7 @@ const struct file_operations v9fs_dir_operations = {
262const struct file_operations v9fs_dir_operations_dotl = { 246const struct file_operations v9fs_dir_operations_dotl = {
263 .read = generic_read_dir, 247 .read = generic_read_dir,
264 .llseek = generic_file_llseek, 248 .llseek = generic_file_llseek,
265 .readdir = v9fs_dir_readdir_dotl, 249 .iterate = v9fs_dir_readdir_dotl,
266 .open = v9fs_file_open, 250 .open = v9fs_file_open,
267 .release = v9fs_dir_release, 251 .release = v9fs_dir_release,
268 .fsync = v9fs_file_fsync_dotl, 252 .fsync = v9fs_file_fsync_dotl,