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/smp_lock.h> |
| 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 | |
| 18 | static int qnx4_readdir(struct file *filp, void *dirent, filldir_t filldir) |
| 19 | { |
Josef Sipek | 24e23c24 | 2006-12-08 02:37:32 -0800 | [diff] [blame] | 20 | struct inode *inode = filp->f_path.dentry->d_inode; |
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 | |
| 29 | QNX4DEBUG(("qnx4_readdir:i_size = %ld\n", (long) inode->i_size)); |
| 30 | QNX4DEBUG(("filp->f_pos = %ld\n", (long) filp->f_pos)); |
| 31 | |
| 32 | lock_kernel(); |
| 33 | |
| 34 | while (filp->f_pos < inode->i_size) { |
| 35 | blknum = qnx4_block_map( inode, filp->f_pos >> QNX4_BLOCK_SIZE_BITS ); |
| 36 | bh = sb_bread(inode->i_sb, blknum); |
| 37 | if(bh==NULL) { |
| 38 | printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum); |
| 39 | break; |
| 40 | } |
| 41 | ix = (int)(filp->f_pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK; |
| 42 | while (ix < QNX4_INODES_PER_BLOCK) { |
| 43 | offset = ix * QNX4_DIR_ENTRY_SIZE; |
| 44 | de = (struct qnx4_inode_entry *) (bh->b_data + offset); |
| 45 | size = strlen(de->di_fname); |
| 46 | if (size) { |
| 47 | if ( !( de->di_status & QNX4_FILE_LINK ) && size > QNX4_SHORT_NAME_MAX ) |
| 48 | size = QNX4_SHORT_NAME_MAX; |
| 49 | else if ( size > QNX4_NAME_MAX ) |
| 50 | size = QNX4_NAME_MAX; |
| 51 | |
| 52 | if ( ( de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK) ) != 0 ) { |
| 53 | QNX4DEBUG(("qnx4_readdir:%.*s\n", size, de->di_fname)); |
| 54 | if ( ( de->di_status & QNX4_FILE_LINK ) == 0 ) |
| 55 | ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1; |
| 56 | else { |
| 57 | le = (struct qnx4_link_info*)de; |
Alexey Dobriyan | 75043cb | 2005-06-24 20:52:52 +0000 | [diff] [blame] | 58 | ino = ( le32_to_cpu(le->dl_inode_blk) - 1 ) * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | QNX4_INODES_PER_BLOCK + |
| 60 | le->dl_inode_ndx; |
| 61 | } |
| 62 | if (filldir(dirent, de->di_fname, size, filp->f_pos, ino, DT_UNKNOWN) < 0) { |
| 63 | brelse(bh); |
| 64 | goto out; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | ix++; |
| 69 | filp->f_pos += QNX4_DIR_ENTRY_SIZE; |
| 70 | } |
| 71 | brelse(bh); |
| 72 | } |
| 73 | out: |
| 74 | unlock_kernel(); |
| 75 | return 0; |
| 76 | } |
| 77 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 78 | const struct file_operations qnx4_dir_operations = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | .read = generic_read_dir, |
| 81 | .readdir = qnx4_readdir, |
Al Viro | 79d2576 | 2009-06-07 09:30:08 -0400 | [diff] [blame] | 82 | .fsync = simple_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 85 | const struct inode_operations qnx4_dir_inode_operations = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | .lookup = qnx4_lookup, |
| 88 | #ifdef CONFIG_QNX4FS_RW |
| 89 | .create = qnx4_create, |
| 90 | .unlink = qnx4_unlink, |
| 91 | .rmdir = qnx4_rmdir, |
| 92 | #endif |
| 93 | }; |