minix.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef FS_MINIX_H
  2. #define FS_MINIX_H
  3. #include <linux/fs.h>
  4. #include <linux/pagemap.h>
  5. #include <linux/minix_fs.h>
  6. #define INODE_VERSION(inode) minix_sb(inode->i_sb)->s_version
  7. #define MINIX_V1 0x0001 /* original minix fs */
  8. #define MINIX_V2 0x0002 /* minix V2 fs */
  9. #define MINIX_V3 0x0003 /* minix V3 fs */
  10. /*
  11. * minix fs inode data in memory
  12. */
  13. struct minix_inode_info {
  14. union {
  15. __u16 i1_data[16];
  16. __u32 i2_data[16];
  17. } u;
  18. struct inode vfs_inode;
  19. };
  20. /*
  21. * minix super-block data in memory
  22. */
  23. struct minix_sb_info {
  24. unsigned long s_ninodes;
  25. unsigned long s_nzones;
  26. unsigned long s_imap_blocks;
  27. unsigned long s_zmap_blocks;
  28. unsigned long s_firstdatazone;
  29. unsigned long s_log_zone_size;
  30. unsigned long s_max_size;
  31. int s_dirsize;
  32. int s_namelen;
  33. struct buffer_head ** s_imap;
  34. struct buffer_head ** s_zmap;
  35. struct buffer_head * s_sbh;
  36. struct minix_super_block * s_ms;
  37. unsigned short s_mount_state;
  38. unsigned short s_version;
  39. };
  40. extern struct inode *minix_iget(struct super_block *, unsigned long);
  41. extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **);
  42. extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
  43. extern struct inode * minix_new_inode(const struct inode *, umode_t, int *);
  44. extern void minix_free_inode(struct inode * inode);
  45. extern unsigned long minix_count_free_inodes(struct super_block *sb);
  46. extern int minix_new_block(struct inode * inode);
  47. extern void minix_free_block(struct inode *inode, unsigned long block);
  48. extern unsigned long minix_count_free_blocks(struct super_block *sb);
  49. extern int minix_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  50. extern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len);
  51. extern void V1_minix_truncate(struct inode *);
  52. extern void V2_minix_truncate(struct inode *);
  53. extern void minix_truncate(struct inode *);
  54. extern void minix_set_inode(struct inode *, dev_t);
  55. extern int V1_minix_get_block(struct inode *, long, struct buffer_head *, int);
  56. extern int V2_minix_get_block(struct inode *, long, struct buffer_head *, int);
  57. extern unsigned V1_minix_blocks(loff_t, struct super_block *);
  58. extern unsigned V2_minix_blocks(loff_t, struct super_block *);
  59. extern struct minix_dir_entry *minix_find_entry(struct dentry*, struct page**);
  60. extern int minix_add_link(struct dentry*, struct inode*);
  61. extern int minix_delete_entry(struct minix_dir_entry*, struct page*);
  62. extern int minix_make_empty(struct inode*, struct inode*);
  63. extern int minix_empty_dir(struct inode*);
  64. extern void minix_set_link(struct minix_dir_entry*, struct page*, struct inode*);
  65. extern struct minix_dir_entry *minix_dotdot(struct inode*, struct page**);
  66. extern ino_t minix_inode_by_name(struct dentry*);
  67. extern const struct inode_operations minix_file_inode_operations;
  68. extern const struct inode_operations minix_dir_inode_operations;
  69. extern const struct file_operations minix_file_operations;
  70. extern const struct file_operations minix_dir_operations;
  71. static inline struct minix_sb_info *minix_sb(struct super_block *sb)
  72. {
  73. return sb->s_fs_info;
  74. }
  75. static inline struct minix_inode_info *minix_i(struct inode *inode)
  76. {
  77. return container_of(inode, struct minix_inode_info, vfs_inode);
  78. }
  79. static inline unsigned minix_blocks_needed(unsigned bits, unsigned blocksize)
  80. {
  81. return DIV_ROUND_UP(bits, blocksize * 8);
  82. }
  83. #if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \
  84. defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
  85. #error Minix file system byte order broken
  86. #elif defined(CONFIG_MINIX_FS_NATIVE_ENDIAN)
  87. /*
  88. * big-endian 32 or 64 bit indexed bitmaps on big-endian system or
  89. * little-endian bitmaps on little-endian system
  90. */
  91. #define minix_test_and_set_bit(nr, addr) \
  92. __test_and_set_bit((nr), (unsigned long *)(addr))
  93. #define minix_set_bit(nr, addr) \
  94. __set_bit((nr), (unsigned long *)(addr))
  95. #define minix_test_and_clear_bit(nr, addr) \
  96. __test_and_clear_bit((nr), (unsigned long *)(addr))
  97. #define minix_test_bit(nr, addr) \
  98. test_bit((nr), (unsigned long *)(addr))
  99. #define minix_find_first_zero_bit(addr, size) \
  100. find_first_zero_bit((unsigned long *)(addr), (size))
  101. #elif defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
  102. /*
  103. * big-endian 16bit indexed bitmaps
  104. */
  105. static inline int minix_find_first_zero_bit(const void *vaddr, unsigned size)
  106. {
  107. const unsigned short *p = vaddr, *addr = vaddr;
  108. unsigned short num;
  109. if (!size)
  110. return 0;
  111. size >>= 4;
  112. while (*p++ == 0xffff) {
  113. if (--size == 0)
  114. return (p - addr) << 4;
  115. }
  116. num = *--p;
  117. return ((p - addr) << 4) + ffz(num);
  118. }
  119. #define minix_test_and_set_bit(nr, addr) \
  120. __test_and_set_bit((nr) ^ 16, (unsigned long *)(addr))
  121. #define minix_set_bit(nr, addr) \
  122. __set_bit((nr) ^ 16, (unsigned long *)(addr))
  123. #define minix_test_and_clear_bit(nr, addr) \
  124. __test_and_clear_bit((nr) ^ 16, (unsigned long *)(addr))
  125. static inline int minix_test_bit(int nr, const void *vaddr)
  126. {
  127. const unsigned short *p = vaddr;
  128. return (p[nr >> 4] & (1U << (nr & 15))) != 0;
  129. }
  130. #else
  131. /*
  132. * little-endian bitmaps
  133. */
  134. #define minix_test_and_set_bit __test_and_set_bit_le
  135. #define minix_set_bit __set_bit_le
  136. #define minix_test_and_clear_bit __test_and_clear_bit_le
  137. #define minix_test_bit test_bit_le
  138. #define minix_find_first_zero_bit find_first_zero_bit_le
  139. #endif
  140. #endif /* FS_MINIX_H */