Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/buffer_head.h> |
Al Viro | 964f536 | 2009-06-07 09:47:13 -0400 | [diff] [blame] | 16 | #include "qnx4.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 18 | static int qnx4_readdir(struct file *file, struct dir_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | { |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 20 | struct inode *inode = file_inode(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | unsigned int offset; |
| 22 | struct buffer_head *bh; |
| 23 | struct qnx4_inode_entry *de; |
| 24 | struct qnx4_link_info *le; |
| 25 | unsigned long blknum; |
| 26 | int ix, ino; |
| 27 | int size; |
| 28 | |
Anders Larsen | 891ddb9 | 2009-09-26 20:15:09 +0200 | [diff] [blame] | 29 | QNX4DEBUG((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size)); |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 30 | QNX4DEBUG((KERN_INFO "pos = %ld\n", (long) ctx->pos)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 32 | while (ctx->pos < inode->i_size) { |
| 33 | blknum = qnx4_block_map(inode, ctx->pos >> QNX4_BLOCK_SIZE_BITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | bh = sb_bread(inode->i_sb, blknum); |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 35 | if (bh == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum); |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 37 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 39 | ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK; |
| 40 | for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | offset = ix * QNX4_DIR_ENTRY_SIZE; |
| 42 | de = (struct qnx4_inode_entry *) (bh->b_data + offset); |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 43 | if (!de->di_fname[0]) |
| 44 | continue; |
| 45 | if (!(de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK))) |
| 46 | continue; |
| 47 | if (!(de->di_status & QNX4_FILE_LINK)) |
| 48 | size = QNX4_SHORT_NAME_MAX; |
| 49 | else |
| 50 | size = QNX4_NAME_MAX; |
| 51 | size = strnlen(de->di_fname, size); |
| 52 | QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, de->di_fname)); |
| 53 | if (!(de->di_status & QNX4_FILE_LINK)) |
| 54 | ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1; |
| 55 | else { |
| 56 | le = (struct qnx4_link_info*)de; |
| 57 | ino = ( le32_to_cpu(le->dl_inode_blk) - 1 ) * |
| 58 | QNX4_INODES_PER_BLOCK + |
| 59 | le->dl_inode_ndx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
Al Viro | 663f4de | 2013-05-17 15:17:59 -0400 | [diff] [blame] | 61 | if (!dir_emit(ctx, de->di_fname, size, ino, DT_UNKNOWN)) { |
| 62 | brelse(bh); |
| 63 | return 0; |
| 64 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | brelse(bh); |
| 67 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 71 | const struct file_operations qnx4_dir_operations = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
jan Blunck | ca57272 | 2010-05-26 14:44:53 -0700 | [diff] [blame] | 73 | .llseek = generic_file_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | .read = generic_read_dir, |
Al Viro | c51da20 | 2016-04-30 22:37:34 -0400 | [diff] [blame] | 75 | .iterate_shared = qnx4_readdir, |
Christoph Hellwig | 1b061d9 | 2010-05-26 17:53:41 +0200 | [diff] [blame] | 76 | .fsync = generic_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 79 | const struct inode_operations qnx4_dir_inode_operations = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | .lookup = qnx4_lookup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; |