itree_v1.c 1.4 KB

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