dir.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. unsigned long blknum;
  22. int ix, ino;
  23. int size;
  24. QNX4DEBUG((KERN_INFO "qnx4_readdir:i_size = %ld\n", (long) inode->i_size));
  25. QNX4DEBUG((KERN_INFO "pos = %ld\n", (long) ctx->pos));
  26. while (ctx->pos < inode->i_size) {
  27. blknum = qnx4_block_map(inode, ctx->pos >> QNX4_BLOCK_SIZE_BITS);
  28. bh = sb_bread(inode->i_sb, blknum);
  29. if (bh == NULL) {
  30. printk(KERN_ERR "qnx4_readdir: bread failed (%ld)\n", blknum);
  31. return 0;
  32. }
  33. ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK;
  34. for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) {
  35. union qnx4_directory_entry *de;
  36. const char *fname;
  37. offset = ix * QNX4_DIR_ENTRY_SIZE;
  38. de = (union qnx4_directory_entry *) (bh->b_data + offset);
  39. fname = get_entry_fname(de, &size);
  40. if (!fname)
  41. continue;
  42. if (!(de->de_status & QNX4_FILE_LINK)) {
  43. ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1;
  44. } else {
  45. ino = ( le32_to_cpu(de->link.dl_inode_blk) - 1 ) *
  46. QNX4_INODES_PER_BLOCK +
  47. de->link.dl_inode_ndx;
  48. }
  49. QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, fname));
  50. if (!dir_emit(ctx, fname, size, ino, DT_UNKNOWN)) {
  51. brelse(bh);
  52. return 0;
  53. }
  54. }
  55. brelse(bh);
  56. }
  57. return 0;
  58. }
  59. const struct file_operations qnx4_dir_operations =
  60. {
  61. .llseek = generic_file_llseek,
  62. .read = generic_read_dir,
  63. .iterate_shared = qnx4_readdir,
  64. .fsync = generic_file_fsync,
  65. };
  66. const struct inode_operations qnx4_dir_inode_operations =
  67. {
  68. .lookup = qnx4_lookup,
  69. };