dir.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <linux/buffer_head.h>
  14. #include "qnx4.h"
  15. static int qnx4_readdir(struct file *filp, void *dirent, filldir_t filldir)
  16. {
  17. struct inode *inode = filp->f_path.dentry->d_inode;
  18. unsigned int offset;
  19. struct buffer_head *bh;
  20. struct qnx4_inode_entry *de;
  21. struct qnx4_link_info *le;
  22. unsigned long blknum;
  23. int ix, ino;
  24. int size;
  25. QNX4DEBUG((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
  26. QNX4DEBUG((KERN_INFO "filp->f_pos = %ld\n", (long) filp->f_pos));
  27. while (filp->f_pos < inode->i_size) {
  28. blknum = qnx4_block_map( inode, filp->f_pos >> QNX4_BLOCK_SIZE_BITS );
  29. bh = sb_bread(inode->i_sb, blknum);
  30. if(bh==NULL) {
  31. printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum);
  32. break;
  33. }
  34. ix = (int)(filp->f_pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK;
  35. while (ix < QNX4_INODES_PER_BLOCK) {
  36. offset = ix * QNX4_DIR_ENTRY_SIZE;
  37. de = (struct qnx4_inode_entry *) (bh->b_data + offset);
  38. size = strlen(de->di_fname);
  39. if (size) {
  40. if ( !( de->di_status & QNX4_FILE_LINK ) && size > QNX4_SHORT_NAME_MAX )
  41. size = QNX4_SHORT_NAME_MAX;
  42. else if ( size > QNX4_NAME_MAX )
  43. size = QNX4_NAME_MAX;
  44. if ( ( de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK) ) != 0 ) {
  45. QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, de->di_fname));
  46. if ( ( de->di_status & QNX4_FILE_LINK ) == 0 )
  47. ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1;
  48. else {
  49. le = (struct qnx4_link_info*)de;
  50. ino = ( le32_to_cpu(le->dl_inode_blk) - 1 ) *
  51. QNX4_INODES_PER_BLOCK +
  52. le->dl_inode_ndx;
  53. }
  54. if (filldir(dirent, de->di_fname, size, filp->f_pos, ino, DT_UNKNOWN) < 0) {
  55. brelse(bh);
  56. goto out;
  57. }
  58. }
  59. }
  60. ix++;
  61. filp->f_pos += QNX4_DIR_ENTRY_SIZE;
  62. }
  63. brelse(bh);
  64. }
  65. out:
  66. return 0;
  67. }
  68. const struct file_operations qnx4_dir_operations =
  69. {
  70. .llseek = generic_file_llseek,
  71. .read = generic_read_dir,
  72. .readdir = qnx4_readdir,
  73. .fsync = generic_file_fsync,
  74. };
  75. const struct inode_operations qnx4_dir_inode_operations =
  76. {
  77. .lookup = qnx4_lookup,
  78. };