aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/linux-2.6/xfs_file.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c
index fb8dd34041eb..54c564693d93 100644
--- a/fs/xfs/linux-2.6/xfs_file.c
+++ b/fs/xfs/linux-2.6/xfs_file.c
@@ -218,6 +218,15 @@ xfs_vm_fault(
218} 218}
219#endif /* CONFIG_XFS_DMAPI */ 219#endif /* CONFIG_XFS_DMAPI */
220 220
221/*
222 * Unfortunately we can't just use the clean and simple readdir implementation
223 * below, because nfs might call back into ->lookup from the filldir callback
224 * and that will deadlock the low-level btree code.
225 *
226 * Hopefully we'll find a better workaround that allows to use the optimal
227 * version at least for local readdirs for 2.6.25.
228 */
229#if 0
221STATIC int 230STATIC int
222xfs_file_readdir( 231xfs_file_readdir(
223 struct file *filp, 232 struct file *filp,
@@ -249,6 +258,121 @@ xfs_file_readdir(
249 return -error; 258 return -error;
250 return 0; 259 return 0;
251} 260}
261#else
262
263struct hack_dirent {
264 int namlen;
265 loff_t offset;
266 u64 ino;
267 unsigned int d_type;
268 char name[];
269};
270
271struct hack_callback {
272 char *dirent;
273 size_t len;
274 size_t used;
275};
276
277STATIC int
278xfs_hack_filldir(
279 void *__buf,
280 const char *name,
281 int namlen,
282 loff_t offset,
283 u64 ino,
284 unsigned int d_type)
285{
286 struct hack_callback *buf = __buf;
287 struct hack_dirent *de = (struct hack_dirent *)(buf->dirent + buf->used);
288
289 if (buf->used + sizeof(struct hack_dirent) + namlen > buf->len)
290 return -EINVAL;
291
292 de->namlen = namlen;
293 de->offset = offset;
294 de->ino = ino;
295 de->d_type = d_type;
296 memcpy(de->name, name, namlen);
297 buf->used += sizeof(struct hack_dirent) + namlen;
298 return 0;
299}
300
301STATIC int
302xfs_file_readdir(
303 struct file *filp,
304 void *dirent,
305 filldir_t filldir)
306{
307 struct inode *inode = filp->f_path.dentry->d_inode;
308 xfs_inode_t *ip = XFS_I(inode);
309 struct hack_callback buf;
310 struct hack_dirent *de;
311 int error;
312 loff_t size;
313 int eof = 0;
314 xfs_off_t start_offset, curr_offset, offset;
315
316 /*
317 * Try fairly hard to get memory
318 */
319 buf.len = PAGE_CACHE_SIZE;
320 do {
321 buf.dirent = kmalloc(buf.len, GFP_KERNEL);
322 if (buf.dirent)
323 break;
324 buf.len >>= 1;
325 } while (buf.len >= 1024);
326
327 if (!buf.dirent)
328 return -ENOMEM;
329
330 curr_offset = filp->f_pos;
331 if (curr_offset == 0x7fffffff)
332 offset = 0xffffffff;
333 else
334 offset = filp->f_pos;
335
336 while (!eof) {
337 int reclen;
338 start_offset = offset;
339
340 buf.used = 0;
341 error = -xfs_readdir(ip, &buf, buf.len, &offset,
342 xfs_hack_filldir);
343 if (error || offset == start_offset) {
344 size = 0;
345 break;
346 }
347
348 size = buf.used;
349 de = (struct hack_dirent *)buf.dirent;
350 while (size > 0) {
351 if (filldir(dirent, de->name, de->namlen,
352 curr_offset & 0x7fffffff,
353 de->ino, de->d_type)) {
354 goto done;
355 }
356
357 reclen = sizeof(struct hack_dirent) + de->namlen;
358 size -= reclen;
359 curr_offset = de->offset /* & 0x7fffffff */;
360 de = (struct hack_dirent *)((char *)de + reclen);
361 }
362 }
363
364 done:
365 if (!error) {
366 if (size == 0)
367 filp->f_pos = offset & 0x7fffffff;
368 else if (de)
369 filp->f_pos = curr_offset;
370 }
371
372 kfree(buf.dirent);
373 return error;
374}
375#endif
252 376
253STATIC int 377STATIC int
254xfs_file_mmap( 378xfs_file_mmap(