dir.c 2.3 KB

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