18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef FS_MINIX_H
38c2ecf20Sopenharmony_ci#define FS_MINIX_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/fs.h>
68c2ecf20Sopenharmony_ci#include <linux/pagemap.h>
78c2ecf20Sopenharmony_ci#include <linux/minix_fs.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define INODE_VERSION(inode)	minix_sb(inode->i_sb)->s_version
108c2ecf20Sopenharmony_ci#define MINIX_V1		0x0001		/* original minix fs */
118c2ecf20Sopenharmony_ci#define MINIX_V2		0x0002		/* minix V2 fs */
128c2ecf20Sopenharmony_ci#define MINIX_V3		0x0003		/* minix V3 fs */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * minix fs inode data in memory
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_cistruct minix_inode_info {
188c2ecf20Sopenharmony_ci	union {
198c2ecf20Sopenharmony_ci		__u16 i1_data[16];
208c2ecf20Sopenharmony_ci		__u32 i2_data[16];
218c2ecf20Sopenharmony_ci	} u;
228c2ecf20Sopenharmony_ci	struct inode vfs_inode;
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/*
268c2ecf20Sopenharmony_ci * minix super-block data in memory
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_cistruct minix_sb_info {
298c2ecf20Sopenharmony_ci	unsigned long s_ninodes;
308c2ecf20Sopenharmony_ci	unsigned long s_nzones;
318c2ecf20Sopenharmony_ci	unsigned long s_imap_blocks;
328c2ecf20Sopenharmony_ci	unsigned long s_zmap_blocks;
338c2ecf20Sopenharmony_ci	unsigned long s_firstdatazone;
348c2ecf20Sopenharmony_ci	unsigned long s_log_zone_size;
358c2ecf20Sopenharmony_ci	int s_dirsize;
368c2ecf20Sopenharmony_ci	int s_namelen;
378c2ecf20Sopenharmony_ci	struct buffer_head ** s_imap;
388c2ecf20Sopenharmony_ci	struct buffer_head ** s_zmap;
398c2ecf20Sopenharmony_ci	struct buffer_head * s_sbh;
408c2ecf20Sopenharmony_ci	struct minix_super_block * s_ms;
418c2ecf20Sopenharmony_ci	unsigned short s_mount_state;
428c2ecf20Sopenharmony_ci	unsigned short s_version;
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciextern struct inode *minix_iget(struct super_block *, unsigned long);
468c2ecf20Sopenharmony_ciextern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **);
478c2ecf20Sopenharmony_ciextern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
488c2ecf20Sopenharmony_ciextern struct inode * minix_new_inode(const struct inode *, umode_t, int *);
498c2ecf20Sopenharmony_ciextern void minix_free_inode(struct inode * inode);
508c2ecf20Sopenharmony_ciextern unsigned long minix_count_free_inodes(struct super_block *sb);
518c2ecf20Sopenharmony_ciextern int minix_new_block(struct inode * inode);
528c2ecf20Sopenharmony_ciextern void minix_free_block(struct inode *inode, unsigned long block);
538c2ecf20Sopenharmony_ciextern unsigned long minix_count_free_blocks(struct super_block *sb);
548c2ecf20Sopenharmony_ciextern int minix_getattr(const struct path *, struct kstat *, u32, unsigned int);
558c2ecf20Sopenharmony_ciextern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciextern void V1_minix_truncate(struct inode *);
588c2ecf20Sopenharmony_ciextern void V2_minix_truncate(struct inode *);
598c2ecf20Sopenharmony_ciextern void minix_truncate(struct inode *);
608c2ecf20Sopenharmony_ciextern void minix_set_inode(struct inode *, dev_t);
618c2ecf20Sopenharmony_ciextern int V1_minix_get_block(struct inode *, long, struct buffer_head *, int);
628c2ecf20Sopenharmony_ciextern int V2_minix_get_block(struct inode *, long, struct buffer_head *, int);
638c2ecf20Sopenharmony_ciextern unsigned V1_minix_blocks(loff_t, struct super_block *);
648c2ecf20Sopenharmony_ciextern unsigned V2_minix_blocks(loff_t, struct super_block *);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciextern struct minix_dir_entry *minix_find_entry(struct dentry*, struct page**);
678c2ecf20Sopenharmony_ciextern int minix_add_link(struct dentry*, struct inode*);
688c2ecf20Sopenharmony_ciextern int minix_delete_entry(struct minix_dir_entry*, struct page*);
698c2ecf20Sopenharmony_ciextern int minix_make_empty(struct inode*, struct inode*);
708c2ecf20Sopenharmony_ciextern int minix_empty_dir(struct inode*);
718c2ecf20Sopenharmony_ciextern void minix_set_link(struct minix_dir_entry*, struct page*, struct inode*);
728c2ecf20Sopenharmony_ciextern struct minix_dir_entry *minix_dotdot(struct inode*, struct page**);
738c2ecf20Sopenharmony_ciextern ino_t minix_inode_by_name(struct dentry*);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciextern const struct inode_operations minix_file_inode_operations;
768c2ecf20Sopenharmony_ciextern const struct inode_operations minix_dir_inode_operations;
778c2ecf20Sopenharmony_ciextern const struct file_operations minix_file_operations;
788c2ecf20Sopenharmony_ciextern const struct file_operations minix_dir_operations;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline struct minix_sb_info *minix_sb(struct super_block *sb)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	return sb->s_fs_info;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline struct minix_inode_info *minix_i(struct inode *inode)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	return container_of(inode, struct minix_inode_info, vfs_inode);
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic inline unsigned minix_blocks_needed(unsigned bits, unsigned blocksize)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	return DIV_ROUND_UP(bits, blocksize * 8);
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \
968c2ecf20Sopenharmony_ci	defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#error Minix file system byte order broken
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#elif defined(CONFIG_MINIX_FS_NATIVE_ENDIAN)
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/*
1038c2ecf20Sopenharmony_ci * big-endian 32 or 64 bit indexed bitmaps on big-endian system or
1048c2ecf20Sopenharmony_ci * little-endian bitmaps on little-endian system
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define minix_test_and_set_bit(nr, addr)	\
1088c2ecf20Sopenharmony_ci	__test_and_set_bit((nr), (unsigned long *)(addr))
1098c2ecf20Sopenharmony_ci#define minix_set_bit(nr, addr)		\
1108c2ecf20Sopenharmony_ci	__set_bit((nr), (unsigned long *)(addr))
1118c2ecf20Sopenharmony_ci#define minix_test_and_clear_bit(nr, addr) \
1128c2ecf20Sopenharmony_ci	__test_and_clear_bit((nr), (unsigned long *)(addr))
1138c2ecf20Sopenharmony_ci#define minix_test_bit(nr, addr)		\
1148c2ecf20Sopenharmony_ci	test_bit((nr), (unsigned long *)(addr))
1158c2ecf20Sopenharmony_ci#define minix_find_first_zero_bit(addr, size) \
1168c2ecf20Sopenharmony_ci	find_first_zero_bit((unsigned long *)(addr), (size))
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#elif defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/*
1218c2ecf20Sopenharmony_ci * big-endian 16bit indexed bitmaps
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic inline int minix_find_first_zero_bit(const void *vaddr, unsigned size)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci	const unsigned short *p = vaddr, *addr = vaddr;
1278c2ecf20Sopenharmony_ci	unsigned short num;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	if (!size)
1308c2ecf20Sopenharmony_ci		return 0;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	size >>= 4;
1338c2ecf20Sopenharmony_ci	while (*p++ == 0xffff) {
1348c2ecf20Sopenharmony_ci		if (--size == 0)
1358c2ecf20Sopenharmony_ci			return (p - addr) << 4;
1368c2ecf20Sopenharmony_ci	}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	num = *--p;
1398c2ecf20Sopenharmony_ci	return ((p - addr) << 4) + ffz(num);
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define minix_test_and_set_bit(nr, addr)	\
1438c2ecf20Sopenharmony_ci	__test_and_set_bit((nr) ^ 16, (unsigned long *)(addr))
1448c2ecf20Sopenharmony_ci#define minix_set_bit(nr, addr)	\
1458c2ecf20Sopenharmony_ci	__set_bit((nr) ^ 16, (unsigned long *)(addr))
1468c2ecf20Sopenharmony_ci#define minix_test_and_clear_bit(nr, addr)	\
1478c2ecf20Sopenharmony_ci	__test_and_clear_bit((nr) ^ 16, (unsigned long *)(addr))
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic inline int minix_test_bit(int nr, const void *vaddr)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	const unsigned short *p = vaddr;
1528c2ecf20Sopenharmony_ci	return (p[nr >> 4] & (1U << (nr & 15))) != 0;
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#else
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/*
1588c2ecf20Sopenharmony_ci * little-endian bitmaps
1598c2ecf20Sopenharmony_ci */
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#define minix_test_and_set_bit	__test_and_set_bit_le
1628c2ecf20Sopenharmony_ci#define minix_set_bit		__set_bit_le
1638c2ecf20Sopenharmony_ci#define minix_test_and_clear_bit	__test_and_clear_bit_le
1648c2ecf20Sopenharmony_ci#define minix_test_bit	test_bit_le
1658c2ecf20Sopenharmony_ci#define minix_find_first_zero_bit	find_first_zero_bit_le
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#endif
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci#endif /* FS_MINIX_H */
170