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