dir.c 2.5 KB

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