18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifdef pr_fmt
38c2ecf20Sopenharmony_ci#undef pr_fmt
48c2ecf20Sopenharmony_ci#endif
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/types.h>
98c2ecf20Sopenharmony_ci#include <linux/fs.h>
108c2ecf20Sopenharmony_ci#include <linux/buffer_head.h>
118c2ecf20Sopenharmony_ci#include "amigaffs.h"
128c2ecf20Sopenharmony_ci#include <linux/mutex.h>
138c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* Ugly macros make the code more pretty. */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define GET_END_PTR(st,p,sz)		 ((st *)((char *)(p)+((sz)-sizeof(st))))
188c2ecf20Sopenharmony_ci#define AFFS_GET_HASHENTRY(data,hashkey) be32_to_cpu(((struct dir_front *)data)->hashtable[hashkey])
198c2ecf20Sopenharmony_ci#define AFFS_BLOCK(sb, bh, blk)		(AFFS_HEAD(bh)->table[AFFS_SB(sb)->s_hashsize-1-(blk)])
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define AFFS_HEAD(bh)		((struct affs_head *)(bh)->b_data)
228c2ecf20Sopenharmony_ci#define AFFS_TAIL(sb, bh)	((struct affs_tail *)((bh)->b_data+(sb)->s_blocksize-sizeof(struct affs_tail)))
238c2ecf20Sopenharmony_ci#define AFFS_ROOT_HEAD(bh)	((struct affs_root_head *)(bh)->b_data)
248c2ecf20Sopenharmony_ci#define AFFS_ROOT_TAIL(sb, bh)	((struct affs_root_tail *)((bh)->b_data+(sb)->s_blocksize-sizeof(struct affs_root_tail)))
258c2ecf20Sopenharmony_ci#define AFFS_DATA_HEAD(bh)	((struct affs_data_head *)(bh)->b_data)
268c2ecf20Sopenharmony_ci#define AFFS_DATA(bh)		(((struct affs_data_head *)(bh)->b_data)->data)
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define AFFS_CACHE_SIZE		PAGE_SIZE
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define AFFS_LC_SIZE		(AFFS_CACHE_SIZE/sizeof(u32)/2)
318c2ecf20Sopenharmony_ci#define AFFS_AC_SIZE		(AFFS_CACHE_SIZE/sizeof(struct affs_ext_key)/2)
328c2ecf20Sopenharmony_ci#define AFFS_AC_MASK		(AFFS_AC_SIZE-1)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define AFFSNAMEMAX 30U
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct affs_ext_key {
378c2ecf20Sopenharmony_ci	u32	ext;				/* idx of the extended block */
388c2ecf20Sopenharmony_ci	u32	key;				/* block number */
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * affs fs inode data in memory
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_cistruct affs_inode_info {
458c2ecf20Sopenharmony_ci	atomic_t i_opencnt;
468c2ecf20Sopenharmony_ci	struct mutex i_link_lock;		/* Protects internal inode access. */
478c2ecf20Sopenharmony_ci	struct mutex i_ext_lock;		/* Protects internal inode access. */
488c2ecf20Sopenharmony_ci#define i_hash_lock i_ext_lock
498c2ecf20Sopenharmony_ci	u32	 i_blkcnt;			/* block count */
508c2ecf20Sopenharmony_ci	u32	 i_extcnt;			/* extended block count */
518c2ecf20Sopenharmony_ci	u32	*i_lc;				/* linear cache of extended blocks */
528c2ecf20Sopenharmony_ci	u32	 i_lc_size;
538c2ecf20Sopenharmony_ci	u32	 i_lc_shift;
548c2ecf20Sopenharmony_ci	u32	 i_lc_mask;
558c2ecf20Sopenharmony_ci	struct affs_ext_key *i_ac;		/* associative cache of extended blocks */
568c2ecf20Sopenharmony_ci	u32	 i_ext_last;			/* last accessed extended block */
578c2ecf20Sopenharmony_ci	struct buffer_head *i_ext_bh;		/* bh of last extended block */
588c2ecf20Sopenharmony_ci	loff_t	 mmu_private;
598c2ecf20Sopenharmony_ci	u32	 i_protect;			/* unused attribute bits */
608c2ecf20Sopenharmony_ci	u32	 i_lastalloc;			/* last allocated block */
618c2ecf20Sopenharmony_ci	int	 i_pa_cnt;			/* number of preallocated blocks */
628c2ecf20Sopenharmony_ci	struct inode vfs_inode;
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* short cut to get to the affs specific inode data */
668c2ecf20Sopenharmony_cistatic inline struct affs_inode_info *AFFS_I(struct inode *inode)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	return container_of(inode, struct affs_inode_info, vfs_inode);
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/*
728c2ecf20Sopenharmony_ci * super-block data in memory
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci * Block numbers are adjusted for their actual size
758c2ecf20Sopenharmony_ci *
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistruct affs_bm_info {
798c2ecf20Sopenharmony_ci	u32 bm_key;			/* Disk block number */
808c2ecf20Sopenharmony_ci	u32 bm_free;			/* Free blocks in here */
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistruct affs_sb_info {
848c2ecf20Sopenharmony_ci	int s_partition_size;		/* Partition size in blocks. */
858c2ecf20Sopenharmony_ci	int s_reserved;			/* Number of reserved blocks. */
868c2ecf20Sopenharmony_ci	//u32 s_blksize;			/* Initial device blksize */
878c2ecf20Sopenharmony_ci	u32 s_data_blksize;		/* size of the data block w/o header */
888c2ecf20Sopenharmony_ci	u32 s_root_block;		/* FFS root block number. */
898c2ecf20Sopenharmony_ci	int s_hashsize;			/* Size of hash table. */
908c2ecf20Sopenharmony_ci	unsigned long s_flags;		/* See below. */
918c2ecf20Sopenharmony_ci	kuid_t s_uid;			/* uid to override */
928c2ecf20Sopenharmony_ci	kgid_t s_gid;			/* gid to override */
938c2ecf20Sopenharmony_ci	umode_t s_mode;			/* mode to override */
948c2ecf20Sopenharmony_ci	struct buffer_head *s_root_bh;	/* Cached root block. */
958c2ecf20Sopenharmony_ci	struct mutex s_bmlock;		/* Protects bitmap access. */
968c2ecf20Sopenharmony_ci	struct affs_bm_info *s_bitmap;	/* Bitmap infos. */
978c2ecf20Sopenharmony_ci	u32 s_bmap_count;		/* # of bitmap blocks. */
988c2ecf20Sopenharmony_ci	u32 s_bmap_bits;		/* # of bits in one bitmap blocks */
998c2ecf20Sopenharmony_ci	u32 s_last_bmap;
1008c2ecf20Sopenharmony_ci	struct buffer_head *s_bmap_bh;
1018c2ecf20Sopenharmony_ci	char *s_prefix;			/* Prefix for volumes and assigns. */
1028c2ecf20Sopenharmony_ci	char s_volume[32];		/* Volume prefix for absolute symlinks. */
1038c2ecf20Sopenharmony_ci	spinlock_t symlink_lock;	/* protects the previous two */
1048c2ecf20Sopenharmony_ci	struct super_block *sb;		/* the VFS superblock object */
1058c2ecf20Sopenharmony_ci	int work_queued;		/* non-zero delayed work is queued */
1068c2ecf20Sopenharmony_ci	struct delayed_work sb_work;	/* superblock flush delayed work */
1078c2ecf20Sopenharmony_ci	spinlock_t work_lock;		/* protects sb_work and work_queued */
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_INTL		0x0001 /* International filesystem. */
1118c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_BM_VALID		0x0002 /* Bitmap is valid. */
1128c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_IMMUTABLE		0x0004 /* Protection bits cannot be changed */
1138c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_QUIET		0x0008 /* chmod errors will be not reported */
1148c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_SETUID		0x0010 /* Ignore Amiga uid */
1158c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_SETGID		0x0020 /* Ignore Amiga gid */
1168c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_SETMODE		0x0040 /* Ignore Amiga protection bits */
1178c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_MUFS		0x0100 /* Use MUFS uid/gid mapping */
1188c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_OFS		0x0200 /* Old filesystem */
1198c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_PREFIX		0x0400 /* Buffer for prefix is allocated */
1208c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_VERBOSE		0x0800 /* Talk about fs when mounting */
1218c2ecf20Sopenharmony_ci#define AFFS_MOUNT_SF_NO_TRUNCATE	0x1000 /* Don't truncate filenames */
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define affs_clear_opt(o, opt)    (o &= ~AFFS_MOUNT_##opt)
1248c2ecf20Sopenharmony_ci#define affs_set_opt(o, opt)      (o |= AFFS_MOUNT_##opt)
1258c2ecf20Sopenharmony_ci#define affs_test_opt(o, opt)     ((o) & AFFS_MOUNT_##opt)
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* short cut to get to the affs specific sb data */
1288c2ecf20Sopenharmony_cistatic inline struct affs_sb_info *AFFS_SB(struct super_block *sb)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	return sb->s_fs_info;
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_civoid affs_mark_sb_dirty(struct super_block *sb);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/* amigaffs.c */
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ciextern int	affs_insert_hash(struct inode *inode, struct buffer_head *bh);
1388c2ecf20Sopenharmony_ciextern int	affs_remove_hash(struct inode *dir, struct buffer_head *rem_bh);
1398c2ecf20Sopenharmony_ciextern int	affs_remove_header(struct dentry *dentry);
1408c2ecf20Sopenharmony_ciextern u32	affs_checksum_block(struct super_block *sb, struct buffer_head *bh);
1418c2ecf20Sopenharmony_ciextern void	affs_fix_checksum(struct super_block *sb, struct buffer_head *bh);
1428c2ecf20Sopenharmony_ciextern void	affs_secs_to_datestamp(time64_t secs, struct affs_date *ds);
1438c2ecf20Sopenharmony_ciextern umode_t	affs_prot_to_mode(u32 prot);
1448c2ecf20Sopenharmony_ciextern void	affs_mode_to_prot(struct inode *inode);
1458c2ecf20Sopenharmony_ci__printf(3, 4)
1468c2ecf20Sopenharmony_ciextern void	affs_error(struct super_block *sb, const char *function,
1478c2ecf20Sopenharmony_ci			   const char *fmt, ...);
1488c2ecf20Sopenharmony_ci__printf(3, 4)
1498c2ecf20Sopenharmony_ciextern void	affs_warning(struct super_block *sb, const char *function,
1508c2ecf20Sopenharmony_ci			     const char *fmt, ...);
1518c2ecf20Sopenharmony_ciextern bool	affs_nofilenametruncate(const struct dentry *dentry);
1528c2ecf20Sopenharmony_ciextern int	affs_check_name(const unsigned char *name, int len,
1538c2ecf20Sopenharmony_ci				bool notruncate);
1548c2ecf20Sopenharmony_ciextern int	affs_copy_name(unsigned char *bstr, struct dentry *dentry);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* bitmap. c */
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciextern u32	affs_count_free_blocks(struct super_block *s);
1598c2ecf20Sopenharmony_ciextern void	affs_free_block(struct super_block *sb, u32 block);
1608c2ecf20Sopenharmony_ciextern u32	affs_alloc_block(struct inode *inode, u32 goal);
1618c2ecf20Sopenharmony_ciextern int	affs_init_bitmap(struct super_block *sb, int *flags);
1628c2ecf20Sopenharmony_ciextern void	affs_free_bitmap(struct super_block *sb);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/* namei.c */
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ciextern const struct export_operations affs_export_ops;
1678c2ecf20Sopenharmony_ciextern int	affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len);
1688c2ecf20Sopenharmony_ciextern struct dentry *affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int);
1698c2ecf20Sopenharmony_ciextern int	affs_unlink(struct inode *dir, struct dentry *dentry);
1708c2ecf20Sopenharmony_ciextern int	affs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool);
1718c2ecf20Sopenharmony_ciextern int	affs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
1728c2ecf20Sopenharmony_ciextern int	affs_rmdir(struct inode *dir, struct dentry *dentry);
1738c2ecf20Sopenharmony_ciextern int	affs_link(struct dentry *olddentry, struct inode *dir,
1748c2ecf20Sopenharmony_ci			  struct dentry *dentry);
1758c2ecf20Sopenharmony_ciextern int	affs_symlink(struct inode *dir, struct dentry *dentry,
1768c2ecf20Sopenharmony_ci			     const char *symname);
1778c2ecf20Sopenharmony_ciextern int	affs_rename2(struct inode *old_dir, struct dentry *old_dentry,
1788c2ecf20Sopenharmony_ci			    struct inode *new_dir, struct dentry *new_dentry,
1798c2ecf20Sopenharmony_ci			    unsigned int flags);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* inode.c */
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ciextern struct inode		*affs_new_inode(struct inode *dir);
1848c2ecf20Sopenharmony_ciextern int			 affs_notify_change(struct dentry *dentry, struct iattr *attr);
1858c2ecf20Sopenharmony_ciextern void			 affs_evict_inode(struct inode *inode);
1868c2ecf20Sopenharmony_ciextern struct inode		*affs_iget(struct super_block *sb,
1878c2ecf20Sopenharmony_ci					unsigned long ino);
1888c2ecf20Sopenharmony_ciextern int			 affs_write_inode(struct inode *inode,
1898c2ecf20Sopenharmony_ci					struct writeback_control *wbc);
1908c2ecf20Sopenharmony_ciextern int			 affs_add_entry(struct inode *dir, struct inode *inode, struct dentry *dentry, s32 type);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/* file.c */
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_civoid		affs_free_prealloc(struct inode *inode);
1958c2ecf20Sopenharmony_ciextern void	affs_truncate(struct inode *);
1968c2ecf20Sopenharmony_ciint		affs_file_fsync(struct file *, loff_t, loff_t, int);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/* dir.c */
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ciextern void   affs_dir_truncate(struct inode *);
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci/* jump tables */
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ciextern const struct inode_operations	 affs_file_inode_operations;
2058c2ecf20Sopenharmony_ciextern const struct inode_operations	 affs_dir_inode_operations;
2068c2ecf20Sopenharmony_ciextern const struct inode_operations   affs_symlink_inode_operations;
2078c2ecf20Sopenharmony_ciextern const struct file_operations	 affs_file_operations;
2088c2ecf20Sopenharmony_ciextern const struct file_operations	 affs_file_operations_ofs;
2098c2ecf20Sopenharmony_ciextern const struct file_operations	 affs_dir_operations;
2108c2ecf20Sopenharmony_ciextern const struct address_space_operations	 affs_symlink_aops;
2118c2ecf20Sopenharmony_ciextern const struct address_space_operations	 affs_aops;
2128c2ecf20Sopenharmony_ciextern const struct address_space_operations	 affs_aops_ofs;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ciextern const struct dentry_operations	 affs_dentry_operations;
2158c2ecf20Sopenharmony_ciextern const struct dentry_operations	 affs_intl_dentry_operations;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistatic inline bool affs_validblock(struct super_block *sb, int block)
2188c2ecf20Sopenharmony_ci{
2198c2ecf20Sopenharmony_ci	return(block >= AFFS_SB(sb)->s_reserved &&
2208c2ecf20Sopenharmony_ci	       block < AFFS_SB(sb)->s_partition_size);
2218c2ecf20Sopenharmony_ci}
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cistatic inline void
2248c2ecf20Sopenharmony_ciaffs_set_blocksize(struct super_block *sb, int size)
2258c2ecf20Sopenharmony_ci{
2268c2ecf20Sopenharmony_ci	sb_set_blocksize(sb, size);
2278c2ecf20Sopenharmony_ci}
2288c2ecf20Sopenharmony_cistatic inline struct buffer_head *
2298c2ecf20Sopenharmony_ciaffs_bread(struct super_block *sb, int block)
2308c2ecf20Sopenharmony_ci{
2318c2ecf20Sopenharmony_ci	pr_debug("%s: %d\n", __func__, block);
2328c2ecf20Sopenharmony_ci	if (affs_validblock(sb, block))
2338c2ecf20Sopenharmony_ci		return sb_bread(sb, block);
2348c2ecf20Sopenharmony_ci	return NULL;
2358c2ecf20Sopenharmony_ci}
2368c2ecf20Sopenharmony_cistatic inline struct buffer_head *
2378c2ecf20Sopenharmony_ciaffs_getblk(struct super_block *sb, int block)
2388c2ecf20Sopenharmony_ci{
2398c2ecf20Sopenharmony_ci	pr_debug("%s: %d\n", __func__, block);
2408c2ecf20Sopenharmony_ci	if (affs_validblock(sb, block))
2418c2ecf20Sopenharmony_ci		return sb_getblk(sb, block);
2428c2ecf20Sopenharmony_ci	return NULL;
2438c2ecf20Sopenharmony_ci}
2448c2ecf20Sopenharmony_cistatic inline struct buffer_head *
2458c2ecf20Sopenharmony_ciaffs_getzeroblk(struct super_block *sb, int block)
2468c2ecf20Sopenharmony_ci{
2478c2ecf20Sopenharmony_ci	struct buffer_head *bh;
2488c2ecf20Sopenharmony_ci	pr_debug("%s: %d\n", __func__, block);
2498c2ecf20Sopenharmony_ci	if (affs_validblock(sb, block)) {
2508c2ecf20Sopenharmony_ci		bh = sb_getblk(sb, block);
2518c2ecf20Sopenharmony_ci		lock_buffer(bh);
2528c2ecf20Sopenharmony_ci		memset(bh->b_data, 0 , sb->s_blocksize);
2538c2ecf20Sopenharmony_ci		set_buffer_uptodate(bh);
2548c2ecf20Sopenharmony_ci		unlock_buffer(bh);
2558c2ecf20Sopenharmony_ci		return bh;
2568c2ecf20Sopenharmony_ci	}
2578c2ecf20Sopenharmony_ci	return NULL;
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_cistatic inline struct buffer_head *
2608c2ecf20Sopenharmony_ciaffs_getemptyblk(struct super_block *sb, int block)
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci	struct buffer_head *bh;
2638c2ecf20Sopenharmony_ci	pr_debug("%s: %d\n", __func__, block);
2648c2ecf20Sopenharmony_ci	if (affs_validblock(sb, block)) {
2658c2ecf20Sopenharmony_ci		bh = sb_getblk(sb, block);
2668c2ecf20Sopenharmony_ci		wait_on_buffer(bh);
2678c2ecf20Sopenharmony_ci		set_buffer_uptodate(bh);
2688c2ecf20Sopenharmony_ci		return bh;
2698c2ecf20Sopenharmony_ci	}
2708c2ecf20Sopenharmony_ci	return NULL;
2718c2ecf20Sopenharmony_ci}
2728c2ecf20Sopenharmony_cistatic inline void
2738c2ecf20Sopenharmony_ciaffs_brelse(struct buffer_head *bh)
2748c2ecf20Sopenharmony_ci{
2758c2ecf20Sopenharmony_ci	if (bh)
2768c2ecf20Sopenharmony_ci		pr_debug("%s: %lld\n", __func__, (long long) bh->b_blocknr);
2778c2ecf20Sopenharmony_ci	brelse(bh);
2788c2ecf20Sopenharmony_ci}
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistatic inline void
2818c2ecf20Sopenharmony_ciaffs_adjust_checksum(struct buffer_head *bh, u32 val)
2828c2ecf20Sopenharmony_ci{
2838c2ecf20Sopenharmony_ci	u32 tmp = be32_to_cpu(((__be32 *)bh->b_data)[5]);
2848c2ecf20Sopenharmony_ci	((__be32 *)bh->b_data)[5] = cpu_to_be32(tmp - val);
2858c2ecf20Sopenharmony_ci}
2868c2ecf20Sopenharmony_cistatic inline void
2878c2ecf20Sopenharmony_ciaffs_adjust_bitmapchecksum(struct buffer_head *bh, u32 val)
2888c2ecf20Sopenharmony_ci{
2898c2ecf20Sopenharmony_ci	u32 tmp = be32_to_cpu(((__be32 *)bh->b_data)[0]);
2908c2ecf20Sopenharmony_ci	((__be32 *)bh->b_data)[0] = cpu_to_be32(tmp - val);
2918c2ecf20Sopenharmony_ci}
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_cistatic inline void
2948c2ecf20Sopenharmony_ciaffs_lock_link(struct inode *inode)
2958c2ecf20Sopenharmony_ci{
2968c2ecf20Sopenharmony_ci	mutex_lock(&AFFS_I(inode)->i_link_lock);
2978c2ecf20Sopenharmony_ci}
2988c2ecf20Sopenharmony_cistatic inline void
2998c2ecf20Sopenharmony_ciaffs_unlock_link(struct inode *inode)
3008c2ecf20Sopenharmony_ci{
3018c2ecf20Sopenharmony_ci	mutex_unlock(&AFFS_I(inode)->i_link_lock);
3028c2ecf20Sopenharmony_ci}
3038c2ecf20Sopenharmony_cistatic inline void
3048c2ecf20Sopenharmony_ciaffs_lock_dir(struct inode *inode)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	mutex_lock_nested(&AFFS_I(inode)->i_hash_lock, SINGLE_DEPTH_NESTING);
3078c2ecf20Sopenharmony_ci}
3088c2ecf20Sopenharmony_cistatic inline void
3098c2ecf20Sopenharmony_ciaffs_unlock_dir(struct inode *inode)
3108c2ecf20Sopenharmony_ci{
3118c2ecf20Sopenharmony_ci	mutex_unlock(&AFFS_I(inode)->i_hash_lock);
3128c2ecf20Sopenharmony_ci}
3138c2ecf20Sopenharmony_cistatic inline void
3148c2ecf20Sopenharmony_ciaffs_lock_ext(struct inode *inode)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	mutex_lock(&AFFS_I(inode)->i_ext_lock);
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_cistatic inline void
3198c2ecf20Sopenharmony_ciaffs_unlock_ext(struct inode *inode)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	mutex_unlock(&AFFS_I(inode)->i_ext_lock);
3228c2ecf20Sopenharmony_ci}
323