2 * QNX4 file system, Linux implementation.
6 * Using parts of the xiafs filesystem.
10 * 28-05-1998 by Richard Frowijn : first release.
11 * 20-06-1998 by Frank Denis : Linux 2.1.99+ & dcache support.
14 #include <linux/buffer_head.h>
18 * A qnx4 directory entry is an inode entry or link info
19 * depending on the status field in the last byte. The
20 * first byte is where the name start either way, and a
21 * zero means it's empty.
23 * Also, due to a bug in gcc, we don't want to use the
24 * real (differently sized) name arrays in the inode and
25 * link entries, but always the 'de_name[]' one in the
30 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578#c6
32 * for details, but basically gcc will take the size of the
33 * 'name' array from one of the used union entries randomly.
35 * This use of 'de_name[]' (48 bytes) avoids the false positive
36 * warnings that would happen if gcc decides to use 'inode.di_name'
37 * (16 bytes) even when the pointer and size were to come from
38 * 'link.dl_name' (48 bytes).
40 * In all cases the actual name pointer itself is the same, it's
41 * only the gcc internal 'what is the size of this field' logic
42 * that can get confused.
44 union qnx4_directory_entry {
46 const char de_name[48];
50 struct qnx4_inode_entry inode;
51 struct qnx4_link_info link;
54 static int qnx4_readdir(struct file *file, struct dir_context *ctx)
56 struct inode *inode = file_inode(file);
58 struct buffer_head *bh;
63 QNX4DEBUG((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
64 QNX4DEBUG((KERN_INFO "pos = %ld\n", (long) ctx->pos));
66 while (ctx->pos < inode->i_size) {
67 blknum = qnx4_block_map(inode, ctx->pos >> QNX4_BLOCK_SIZE_BITS);
68 bh = sb_bread(inode->i_sb, blknum);
70 printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum);
73 ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK;
74 for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) {
75 union qnx4_directory_entry *de;
77 offset = ix * QNX4_DIR_ENTRY_SIZE;
78 de = (union qnx4_directory_entry *) (bh->b_data + offset);
82 if (!(de->de_status & (QNX4_FILE_USED|QNX4_FILE_LINK)))
84 if (!(de->de_status & QNX4_FILE_LINK)) {
85 size = sizeof(de->inode.di_fname);
86 ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1;
88 size = sizeof(de->link.dl_fname);
89 ino = ( le32_to_cpu(de->link.dl_inode_blk) - 1 ) *
90 QNX4_INODES_PER_BLOCK +
91 de->link.dl_inode_ndx;
93 size = strnlen(de->de_name, size);
94 QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, name));
95 if (!dir_emit(ctx, de->de_name, size, ino, DT_UNKNOWN)) {
105 const struct file_operations qnx4_dir_operations =
107 .llseek = generic_file_llseek,
108 .read = generic_read_dir,
109 .iterate = qnx4_readdir,
110 .fsync = generic_file_fsync,
113 const struct inode_operations qnx4_dir_inode_operations =
115 .lookup = qnx4_lookup,