/filesystems/unixfs/minixfs/itree_v1.c

http://macfuse.googlecode.com/ · C · 69 lines · 47 code · 11 blank · 11 comment · 9 complexity · 107f82b119ab256fc26685cd34a2fe67 MD5 · raw file

  1. /*
  2. * Minix File System Famiy for MacFUSE
  3. * Amit Singh
  4. * http://osxbook.com
  5. *
  6. * Most of the code in this file comes from the Linux kernel implementation
  7. * of the minix file system. See fs/minix/ in the Linux kernel source tree.
  8. *
  9. * The code is Copyright (c) its various authors. It is covered by the
  10. * GNU GENERAL PUBLIC LICENSE Version 2.
  11. */
  12. #include <linux/buffer_head.h>
  13. #include "minixfs.h"
  14. enum { DEPTH = 3, DIRECT = 7 }; /* Only double indirect */
  15. typedef u16 block_t; /* 16 bit, host order */
  16. static inline unsigned long block_to_cpu(block_t n)
  17. {
  18. return n;
  19. }
  20. static inline block_t cpu_to_block(unsigned long n)
  21. {
  22. return n;
  23. }
  24. static inline block_t* i_data(struct inode* inode)
  25. {
  26. return (block_t *)minix_i(inode)->u.i1_data;
  27. }
  28. static int block_to_path(struct inode* inode, long block, int offsets[DEPTH])
  29. {
  30. int n = 0;
  31. if (block < 0) {
  32. printk("MINIX-fs: block_to_path: block %ld < 0\n", block);
  33. } else if (block >= (minix_sb(inode->I_sb)->s_max_size/BLOCK_SIZE)) {
  34. if (0)
  35. printk("MINIX-fs: block_to_path: block %ld too bign", block);
  36. } else if (block < 7) {
  37. offsets[n++] = block;
  38. } else if ((block -= 7) < 512) {
  39. offsets[n++] = 7;
  40. offsets[n++] = block;
  41. } else {
  42. block -= 512;
  43. offsets[n++] = 8;
  44. offsets[n++] = block >> 9;
  45. offsets[n++] = block & 511;
  46. }
  47. return n;
  48. }
  49. #include "itree_common.c"
  50. int
  51. minix_get_block_v1(struct inode* inode, sector_t iblock, off_t* result)
  52. {
  53. return get_block(inode, iblock, result);
  54. }
  55. unsigned V1_minix_blocks(loff_t size, struct super_block* sb)
  56. {
  57. return nblocks(size, sb);
  58. }