dir.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 *file, struct dir_context *ctx)
  16. {
  17. struct inode *inode = file_inode(file);
  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 "pos = %ld\n", (long) ctx->pos));
  27. while (ctx->pos < inode->i_size) {
  28. blknum = qnx4_block_map(inode, ctx->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. return 0;
  33. }
  34. ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK;
  35. for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) {
  36. offset = ix * QNX4_DIR_ENTRY_SIZE;
  37. de = (struct qnx4_inode_entry *) (bh->b_data + offset);
  38. if (!de->di_fname[0])
  39. continue;
  40. if (!(de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK)))
  41. continue;
  42. if (!(de->di_status & QNX4_FILE_LINK))
  43. size = QNX4_SHORT_NAME_MAX;
  44. else
  45. size = QNX4_NAME_MAX;
  46. size = strnlen(de->di_fname, size);
  47. QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, de->di_fname));
  48. if (!(de->di_status & QNX4_FILE_LINK))
  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 (!dir_emit(ctx, de->di_fname, size, ino, DT_UNKNOWN)) {
  57. brelse(bh);
  58. return 0;
  59. }
  60. }
  61. brelse(bh);
  62. }
  63. return 0;
  64. }
  65. const struct file_operations qnx4_dir_operations =
  66. {
  67. .llseek = generic_file_llseek,
  68. .read = generic_read_dir,
  69. .iterate = qnx4_readdir,
  70. .fsync = generic_file_fsync,
  71. };
  72. const struct inode_operations qnx4_dir_inode_operations =
  73. {
  74. .lookup = qnx4_lookup,
  75. };