dir.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/config.h>
  14. #include <linux/string.h>
  15. #include <linux/errno.h>
  16. #include <linux/fs.h>
  17. #include <linux/qnx4_fs.h>
  18. #include <linux/stat.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/buffer_head.h>
  21. static int qnx4_readdir(struct file *filp, void *dirent, filldir_t filldir)
  22. {
  23. struct inode *inode = filp->f_dentry->d_inode;
  24. unsigned int offset;
  25. struct buffer_head *bh;
  26. struct qnx4_inode_entry *de;
  27. struct qnx4_link_info *le;
  28. unsigned long blknum;
  29. int ix, ino;
  30. int size;
  31. QNX4DEBUG(("qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
  32. QNX4DEBUG(("filp->f_pos = %ld\n", (long) filp->f_pos));
  33. lock_kernel();
  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. if ( ( de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK) ) != 0 ) {
  52. QNX4DEBUG(("qnx4_readdir:%.*s\n", size, de->di_fname));
  53. if ( ( de->di_status & QNX4_FILE_LINK ) == 0 )
  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;
  60. }
  61. if (filldir(dirent, de->di_fname, size, filp->f_pos, ino, DT_UNKNOWN) < 0) {
  62. brelse(bh);
  63. goto out;
  64. }
  65. }
  66. }
  67. ix++;
  68. filp->f_pos += QNX4_DIR_ENTRY_SIZE;
  69. }
  70. brelse(bh);
  71. }
  72. out:
  73. unlock_kernel();
  74. return 0;
  75. }
  76. const struct file_operations qnx4_dir_operations =
  77. {
  78. .read = generic_read_dir,
  79. .readdir = qnx4_readdir,
  80. .fsync = file_fsync,
  81. };
  82. struct inode_operations qnx4_dir_inode_operations =
  83. {
  84. .lookup = qnx4_lookup,
  85. #ifdef CONFIG_QNX4FS_RW
  86. .create = qnx4_create,
  87. .unlink = qnx4_unlink,
  88. .rmdir = qnx4_rmdir,
  89. #endif
  90. };