dir.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * QNX4 file system, Linux implementation.
  4. *
  5. * Version : 0.2.1
  6. *
  7. * Using parts of the xiafs filesystem.
  8. *
  9. * History :
  10. *
  11. * 28-05-1998 by Richard Frowijn : first release.
  12. * 20-06-1998 by Frank Denis : Linux 2.1.99+ & dcache support.
  13. */
  14. #include <linux/buffer_head.h>
  15. #include "qnx4.h"
  16. static int qnx4_readdir(struct file *file, struct dir_context *ctx)
  17. {
  18. struct inode *inode = file_inode(file);
  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((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
  27. QNX4DEBUG((KERN_INFO "pos = %ld\n", (long) ctx->pos));
  28. while (ctx->pos < inode->i_size) {
  29. blknum = qnx4_block_map(inode, ctx->pos >> QNX4_BLOCK_SIZE_BITS);
  30. bh = sb_bread(inode->i_sb, blknum);
  31. if (bh == NULL) {
  32. printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum);
  33. return 0;
  34. }
  35. ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK;
  36. for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) {
  37. offset = ix * QNX4_DIR_ENTRY_SIZE;
  38. de = (struct qnx4_inode_entry *) (bh->b_data + offset);
  39. if (!de->di_fname[0])
  40. continue;
  41. if (!(de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK)))
  42. continue;
  43. if (!(de->di_status & QNX4_FILE_LINK))
  44. size = QNX4_SHORT_NAME_MAX;
  45. else
  46. size = QNX4_NAME_MAX;
  47. size = strnlen(de->di_fname, size);
  48. QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, de->di_fname));
  49. if (!(de->di_status & QNX4_FILE_LINK))
  50. ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1;
  51. else {
  52. le = (struct qnx4_link_info*)de;
  53. ino = ( le32_to_cpu(le->dl_inode_blk) - 1 ) *
  54. QNX4_INODES_PER_BLOCK +
  55. le->dl_inode_ndx;
  56. }
  57. if (!dir_emit(ctx, de->di_fname, size, ino, DT_UNKNOWN)) {
  58. brelse(bh);
  59. return 0;
  60. }
  61. }
  62. brelse(bh);
  63. }
  64. return 0;
  65. }
  66. const struct file_operations qnx4_dir_operations =
  67. {
  68. .llseek = generic_file_llseek,
  69. .read = generic_read_dir,
  70. .iterate_shared = qnx4_readdir,
  71. .fsync = generic_file_fsync,
  72. };
  73. const struct inode_operations qnx4_dir_inode_operations =
  74. {
  75. .lookup = qnx4_lookup,
  76. };