minix.h 5.2 KB

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