blob: 781056a0480f442942b69b85712ed7d697607f41 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/buffer_head.h>
Al Viro964f5362009-06-07 09:47:13 -040015#include "qnx4.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Al Viro663f4de2013-05-17 15:17:59 -040017static int qnx4_readdir(struct file *file, struct dir_context *ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018{
Al Viro663f4de2013-05-17 15:17:59 -040019 struct inode *inode = file_inode(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 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
Anders Larsen891ddb92009-09-26 20:15:09 +020028 QNX4DEBUG((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
Al Viro663f4de2013-05-17 15:17:59 -040029 QNX4DEBUG((KERN_INFO "pos = %ld\n", (long) ctx->pos));
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Al Viro663f4de2013-05-17 15:17:59 -040031 while (ctx->pos < inode->i_size) {
32 blknum = qnx4_block_map(inode, ctx->pos >> QNX4_BLOCK_SIZE_BITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 bh = sb_bread(inode->i_sb, blknum);
Al Viro663f4de2013-05-17 15:17:59 -040034 if (bh == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum);
Al Viro663f4de2013-05-17 15:17:59 -040036 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 }
Al Viro663f4de2013-05-17 15:17:59 -040038 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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 offset = ix * QNX4_DIR_ENTRY_SIZE;
41 de = (struct qnx4_inode_entry *) (bh->b_data + offset);
Al Viro663f4de2013-05-17 15:17:59 -040042 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 }
Al Viro663f4de2013-05-17 15:17:59 -040060 if (!dir_emit(ctx, de->di_fname, size, ino, DT_UNKNOWN)) {
61 brelse(bh);
62 return 0;
63 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 }
65 brelse(bh);
66 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 return 0;
68}
69
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080070const struct file_operations qnx4_dir_operations =
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
jan Blunckca572722010-05-26 14:44:53 -070072 .llseek = generic_file_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .read = generic_read_dir,
Al Viroc51da202016-04-30 22:37:34 -040074 .iterate_shared = qnx4_readdir,
Christoph Hellwig1b061d92010-05-26 17:53:41 +020075 .fsync = generic_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
Arjan van de Venc5ef1c42007-02-12 00:55:40 -080078const struct inode_operations qnx4_dir_inode_operations =
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 .lookup = qnx4_lookup,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};