itree_v2.c 1.9 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. char b[BDEVNAME_SIZE];
  23. struct super_block *sb = inode->i_sb;
  24. if (block < 0) {
  25. printk("MINIX-fs: block_to_path: block %ld < 0 on dev %s\n",
  26. block, bdevname(sb->s_bdev, b));
  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 %s\n",
  32. block, bdevname(sb->s_bdev, b));
  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. }