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