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