blob: 20217336802570e024dc6837c2f67742198877c6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Hitoshi Mitakee38be992009-06-22 11:11:20 +09002#ifndef FS_MINIX_H
3#define FS_MINIX_H
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/fs.h>
6#include <linux/pagemap.h>
7#include <linux/minix_fs.h>
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#define INODE_VERSION(inode) minix_sb(inode->i_sb)->s_version
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#define MINIX_V1 0x0001 /* original minix fs */
11#define MINIX_V2 0x0002 /* minix V2 fs */
Andries Brouwer939b00d2007-02-12 00:52:49 -080012#define MINIX_V3 0x0003 /* minix V3 fs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14/*
15 * minix fs inode data in memory
16 */
17struct 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 */
28struct 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 int s_dirsize;
36 int s_namelen;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 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
David Howellsa90a08802008-02-07 00:15:44 -080045extern struct inode *minix_iget(struct super_block *, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **);
47extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
Al Viro4f45ba3d2011-07-26 02:48:39 -040048extern struct inode * minix_new_inode(const struct inode *, umode_t, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049extern void minix_free_inode(struct inode * inode);
Josh Boyer016e8d42011-08-19 14:50:26 -040050extern unsigned long minix_count_free_inodes(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051extern int minix_new_block(struct inode * inode);
Andries Brouwer939b00d2007-02-12 00:52:49 -080052extern void minix_free_block(struct inode *inode, unsigned long block);
Josh Boyer016e8d42011-08-19 14:50:26 -040053extern unsigned long minix_count_free_blocks(struct super_block *sb);
Christian Brauner549c7292021-01-21 14:19:43 +010054extern int minix_getattr(struct user_namespace *, const struct path *,
55 struct kstat *, u32, unsigned int);
Christoph Hellwigf4e420d2010-06-04 11:29:56 +020056extern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058extern void V1_minix_truncate(struct inode *);
59extern void V2_minix_truncate(struct inode *);
60extern void minix_truncate(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061extern void minix_set_inode(struct inode *, dev_t);
62extern int V1_minix_get_block(struct inode *, long, struct buffer_head *, int);
63extern int V2_minix_get_block(struct inode *, long, struct buffer_head *, int);
Andries Brouwer939b00d2007-02-12 00:52:49 -080064extern unsigned V1_minix_blocks(loff_t, struct super_block *);
65extern unsigned V2_minix_blocks(loff_t, struct super_block *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67extern struct minix_dir_entry *minix_find_entry(struct dentry*, struct page**);
68extern int minix_add_link(struct dentry*, struct inode*);
69extern int minix_delete_entry(struct minix_dir_entry*, struct page*);
70extern int minix_make_empty(struct inode*, struct inode*);
71extern int minix_empty_dir(struct inode*);
72extern void minix_set_link(struct minix_dir_entry*, struct page*, struct inode*);
73extern struct minix_dir_entry *minix_dotdot(struct inode*, struct page**);
74extern ino_t minix_inode_by_name(struct dentry*);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -080076extern const struct inode_operations minix_file_inode_operations;
77extern const struct inode_operations minix_dir_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080078extern const struct file_operations minix_file_operations;
79extern const struct file_operations minix_dir_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81static inline struct minix_sb_info *minix_sb(struct super_block *sb)
82{
83 return sb->s_fs_info;
84}
85
86static inline struct minix_inode_info *minix_i(struct inode *inode)
87{
Rasmus Villemoesdb6172c2015-03-19 12:28:04 +010088 return container_of(inode, struct minix_inode_info, vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
Hitoshi Mitakee38be992009-06-22 11:11:20 +090090
Josh Boyer016e8d42011-08-19 14:50:26 -040091static inline unsigned minix_blocks_needed(unsigned bits, unsigned blocksize)
92{
93 return DIV_ROUND_UP(bits, blocksize * 8);
94}
95
Akinobu Mita61f2e7b2011-03-23 16:42:16 -070096#if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \
97 defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
98
99#error Minix file system byte order broken
100
101#elif defined(CONFIG_MINIX_FS_NATIVE_ENDIAN)
102
103/*
104 * big-endian 32 or 64 bit indexed bitmaps on big-endian system or
105 * little-endian bitmaps on little-endian system
106 */
107
108#define minix_test_and_set_bit(nr, addr) \
109 __test_and_set_bit((nr), (unsigned long *)(addr))
110#define minix_set_bit(nr, addr) \
111 __set_bit((nr), (unsigned long *)(addr))
112#define minix_test_and_clear_bit(nr, addr) \
113 __test_and_clear_bit((nr), (unsigned long *)(addr))
114#define minix_test_bit(nr, addr) \
115 test_bit((nr), (unsigned long *)(addr))
116#define minix_find_first_zero_bit(addr, size) \
117 find_first_zero_bit((unsigned long *)(addr), (size))
118
119#elif defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
120
121/*
122 * big-endian 16bit indexed bitmaps
123 */
124
125static inline int minix_find_first_zero_bit(const void *vaddr, unsigned size)
126{
127 const unsigned short *p = vaddr, *addr = vaddr;
128 unsigned short num;
129
130 if (!size)
131 return 0;
132
Al Virof1fd3062011-08-26 22:38:50 -0400133 size >>= 4;
Akinobu Mita61f2e7b2011-03-23 16:42:16 -0700134 while (*p++ == 0xffff) {
135 if (--size == 0)
136 return (p - addr) << 4;
137 }
138
139 num = *--p;
140 return ((p - addr) << 4) + ffz(num);
141}
142
143#define minix_test_and_set_bit(nr, addr) \
144 __test_and_set_bit((nr) ^ 16, (unsigned long *)(addr))
145#define minix_set_bit(nr, addr) \
146 __set_bit((nr) ^ 16, (unsigned long *)(addr))
147#define minix_test_and_clear_bit(nr, addr) \
148 __test_and_clear_bit((nr) ^ 16, (unsigned long *)(addr))
149
150static inline int minix_test_bit(int nr, const void *vaddr)
151{
152 const unsigned short *p = vaddr;
153 return (p[nr >> 4] & (1U << (nr & 15))) != 0;
154}
155
156#else
157
158/*
159 * little-endian bitmaps
160 */
161
162#define minix_test_and_set_bit __test_and_set_bit_le
163#define minix_set_bit __set_bit_le
164#define minix_test_and_clear_bit __test_and_clear_bit_le
165#define minix_test_bit test_bit_le
166#define minix_find_first_zero_bit find_first_zero_bit_le
167
168#endif
169
Hitoshi Mitakee38be992009-06-22 11:11:20 +0900170#endif /* FS_MINIX_H */