Merge tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[linux-2.6-block.git] / fs / qnx4 / dir.c
CommitLineData
1da177e4
LT
1/*
2 * QNX4 file system, Linux implementation.
3 *
4 * Version : 0.2.1
5 *
6 * Using parts of the xiafs filesystem.
7 *
8 * History :
9 *
10 * 28-05-1998 by Richard Frowijn : first release.
11 * 20-06-1998 by Frank Denis : Linux 2.1.99+ & dcache support.
12 */
13
1da177e4 14#include <linux/buffer_head.h>
964f5369 15#include "qnx4.h"
1da177e4 16
663f4dec 17static int qnx4_readdir(struct file *file, struct dir_context *ctx)
1da177e4 18{
663f4dec 19 struct inode *inode = file_inode(file);
1da177e4
LT
20 unsigned int offset;
21 struct buffer_head *bh;
22 struct qnx4_inode_entry *de;
23 struct qnx4_link_info *le;
24 unsigned long blknum;
25 int ix, ino;
26 int size;
27
891ddb95 28 QNX4DEBUG((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
663f4dec 29 QNX4DEBUG((KERN_INFO "pos = %ld\n", (long) ctx->pos));
1da177e4 30
663f4dec
AV
31 while (ctx->pos < inode->i_size) {
32 blknum = qnx4_block_map(inode, ctx->pos >> QNX4_BLOCK_SIZE_BITS);
1da177e4 33 bh = sb_bread(inode->i_sb, blknum);
663f4dec 34 if (bh == NULL) {
1da177e4 35 printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum);
663f4dec 36 return 0;
1da177e4 37 }
663f4dec
AV
38 ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK;
39 for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) {
1da177e4
LT
40 offset = ix * QNX4_DIR_ENTRY_SIZE;
41 de = (struct qnx4_inode_entry *) (bh->b_data + offset);
663f4dec
AV
42 if (!de->di_fname[0])
43 continue;
44 if (!(de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK)))
45 continue;
46 if (!(de->di_status & QNX4_FILE_LINK))
47 size = QNX4_SHORT_NAME_MAX;
48 else
49 size = QNX4_NAME_MAX;
50 size = strnlen(de->di_fname, size);
51 QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, de->di_fname));
52 if (!(de->di_status & QNX4_FILE_LINK))
53 ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1;
54 else {
55 le = (struct qnx4_link_info*)de;
56 ino = ( le32_to_cpu(le->dl_inode_blk) - 1 ) *
57 QNX4_INODES_PER_BLOCK +
58 le->dl_inode_ndx;
59 }
60 if (!dir_emit(ctx, de->di_fname, size, ino, DT_UNKNOWN)) {
61 brelse(bh);
62 return 0;
1da177e4 63 }
1da177e4
LT
64 }
65 brelse(bh);
66 }
1da177e4
LT
67 return 0;
68}
69
4b6f5d20 70const struct file_operations qnx4_dir_operations =
1da177e4 71{
ca572727 72 .llseek = generic_file_llseek,
1da177e4 73 .read = generic_read_dir,
663f4dec 74 .iterate = qnx4_readdir,
1b061d92 75 .fsync = generic_file_fsync,
1da177e4
LT
76};
77
c5ef1c42 78const struct inode_operations qnx4_dir_inode_operations =
1da177e4
LT
79{
80 .lookup = qnx4_lookup,
1da177e4 81};