itree_v2.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/buffer_head.h>
  3. #include "minix.h"
  4. enum {DIRECT = 7, DEPTH = 4}; /* Have triple indirect */
  5. typedef u32 block_t; /* 32 bit, host order */
  6. static inline unsigned long block_to_cpu(block_t n)
  7. {
  8. return n;
  9. }
  10. static inline block_t cpu_to_block(unsigned long n)
  11. {
  12. return n;
  13. }
  14. static inline block_t *i_data(struct inode *inode)
  15. {
  16. return (block_t *)minix_i(inode)->u.i2_data;
  17. }
  18. #define DIRCOUNT 7
  19. #define INDIRCOUNT(sb) (1 << ((sb)->s_blocksize_bits - 2))
  20. static int block_to_path(struct inode * inode, long block, int offsets[DEPTH])
  21. {
  22. int n = 0;
  23. struct super_block *sb = inode->i_sb;
  24. if (block < 0) {
  25. printk("MINIX-fs: block_to_path: block %ld < 0 on dev %pg\n",
  26. block, sb->s_bdev);
  27. } else if ((u64)block * (u64)sb->s_blocksize >=
  28. minix_sb(sb)->s_max_size) {
  29. if (printk_ratelimit())
  30. printk("MINIX-fs: block_to_path: "
  31. "block %ld too big on dev %pg\n",
  32. block, sb->s_bdev);
  33. } else if (block < DIRCOUNT) {
  34. offsets[n++] = block;
  35. } else if ((block -= DIRCOUNT) < INDIRCOUNT(sb)) {
  36. offsets[n++] = DIRCOUNT;
  37. offsets[n++] = block;
  38. } else if ((block -= INDIRCOUNT(sb)) < INDIRCOUNT(sb) * INDIRCOUNT(sb)) {
  39. offsets[n++] = DIRCOUNT + 1;
  40. offsets[n++] = block / INDIRCOUNT(sb);
  41. offsets[n++] = block % INDIRCOUNT(sb);
  42. } else {
  43. block -= INDIRCOUNT(sb) * INDIRCOUNT(sb);
  44. offsets[n++] = DIRCOUNT + 2;
  45. offsets[n++] = (block / INDIRCOUNT(sb)) / INDIRCOUNT(sb);
  46. offsets[n++] = (block / INDIRCOUNT(sb)) % INDIRCOUNT(sb);
  47. offsets[n++] = block % INDIRCOUNT(sb);
  48. }
  49. return n;
  50. }
  51. #include "itree_common.c"
  52. int V2_minix_get_block(struct inode * inode, long block,
  53. struct buffer_head *bh_result, int create)
  54. {
  55. return get_block(inode, block, bh_result, create);
  56. }
  57. void V2_minix_truncate(struct inode * inode)
  58. {
  59. truncate(inode);
  60. }
  61. unsigned V2_minix_blocks(loff_t size, struct super_block *sb)
  62. {
  63. return nblocks(size, sb);
  64. }