1 // SPDX-License-Identifier: GPL-2.0
3 * QNX4 file system, Linux implementation.
7 * Using parts of the xiafs filesystem.
11 * 28-05-1998 by Richard Frowijn : first release.
12 * 20-06-1998 by Frank Denis : Linux 2.1.99+ & dcache support.
15 #include <linux/buffer_head.h>
19 * A qnx4 directory entry is an inode entry or link info
20 * depending on the status field in the last byte. The
21 * first byte is where the name start either way, and a
22 * zero means it's empty.
24 union qnx4_directory_entry {
30 struct qnx4_inode_entry inode;
31 struct qnx4_link_info link;
34 static int qnx4_readdir(struct file *file, struct dir_context *ctx)
36 struct inode *inode = file_inode(file);
38 struct buffer_head *bh;
43 QNX4DEBUG((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
44 QNX4DEBUG((KERN_INFO "pos = %ld\n", (long) ctx->pos));
46 while (ctx->pos < inode->i_size) {
47 blknum = qnx4_block_map(inode, ctx->pos >> QNX4_BLOCK_SIZE_BITS);
48 bh = sb_bread(inode->i_sb, blknum);
50 printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum);
53 ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK;
54 for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) {
55 union qnx4_directory_entry *de;
58 offset = ix * QNX4_DIR_ENTRY_SIZE;
59 de = (union qnx4_directory_entry *) (bh->b_data + offset);
63 if (!(de->de_status & (QNX4_FILE_USED|QNX4_FILE_LINK)))
65 if (!(de->de_status & QNX4_FILE_LINK)) {
66 size = sizeof(de->inode.di_fname);
67 name = de->inode.di_fname;
68 ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1;
70 size = sizeof(de->link.dl_fname);
71 name = de->link.dl_fname;
72 ino = ( le32_to_cpu(de->link.dl_inode_blk) - 1 ) *
73 QNX4_INODES_PER_BLOCK +
74 de->link.dl_inode_ndx;
76 size = strnlen(name, size);
77 QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, name));
78 if (!dir_emit(ctx, name, size, ino, DT_UNKNOWN)) {
88 const struct file_operations qnx4_dir_operations =
90 .llseek = generic_file_llseek,
91 .read = generic_read_dir,
92 .iterate_shared = qnx4_readdir,
93 .fsync = generic_file_fsync,
96 const struct inode_operations qnx4_dir_inode_operations =
98 .lookup = qnx4_lookup,