itree_v2.c 1.8 KB

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