18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _UFS_UFS_H
38c2ecf20Sopenharmony_ci#define _UFS_UFS_H 1
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#ifdef pr_fmt
68c2ecf20Sopenharmony_ci#undef pr_fmt
78c2ecf20Sopenharmony_ci#endif
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define UFS_MAX_GROUP_LOADED 8
128c2ecf20Sopenharmony_ci#define UFS_CGNO_EMPTY ((unsigned)-1)
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct ufs_sb_private_info;
158c2ecf20Sopenharmony_cistruct ufs_cg_private_info;
168c2ecf20Sopenharmony_cistruct ufs_csum;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct ufs_sb_info {
198c2ecf20Sopenharmony_ci	struct ufs_sb_private_info * s_uspi;
208c2ecf20Sopenharmony_ci	struct ufs_csum	* s_csp;
218c2ecf20Sopenharmony_ci	unsigned s_bytesex;
228c2ecf20Sopenharmony_ci	unsigned s_flags;
238c2ecf20Sopenharmony_ci	struct buffer_head ** s_ucg;
248c2ecf20Sopenharmony_ci	struct ufs_cg_private_info * s_ucpi[UFS_MAX_GROUP_LOADED];
258c2ecf20Sopenharmony_ci	unsigned s_cgno[UFS_MAX_GROUP_LOADED];
268c2ecf20Sopenharmony_ci	unsigned short s_cg_loaded;
278c2ecf20Sopenharmony_ci	unsigned s_mount_opt;
288c2ecf20Sopenharmony_ci	struct super_block *sb;
298c2ecf20Sopenharmony_ci	int work_queued; /* non-zero if the delayed work is queued */
308c2ecf20Sopenharmony_ci	struct delayed_work sync_work; /* FS sync delayed work */
318c2ecf20Sopenharmony_ci	spinlock_t work_lock; /* protects sync_work and work_queued */
328c2ecf20Sopenharmony_ci	struct mutex s_lock;
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct ufs_inode_info {
368c2ecf20Sopenharmony_ci	union {
378c2ecf20Sopenharmony_ci		__fs32	i_data[15];
388c2ecf20Sopenharmony_ci		__u8	i_symlink[2 * 4 * 15];
398c2ecf20Sopenharmony_ci		__fs64	u2_i_data[15];
408c2ecf20Sopenharmony_ci	} i_u1;
418c2ecf20Sopenharmony_ci	__u32	i_flags;
428c2ecf20Sopenharmony_ci	__u32	i_shadow;
438c2ecf20Sopenharmony_ci	__u32	i_unused1;
448c2ecf20Sopenharmony_ci	__u32	i_unused2;
458c2ecf20Sopenharmony_ci	__u32	i_oeftflag;
468c2ecf20Sopenharmony_ci	__u16	i_osync;
478c2ecf20Sopenharmony_ci	__u64	i_lastfrag;
488c2ecf20Sopenharmony_ci	seqlock_t meta_lock;
498c2ecf20Sopenharmony_ci	struct mutex	truncate_mutex;
508c2ecf20Sopenharmony_ci	__u32   i_dir_start_lookup;
518c2ecf20Sopenharmony_ci	struct inode vfs_inode;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* mount options */
558c2ecf20Sopenharmony_ci#define UFS_MOUNT_ONERROR		0x0000000F
568c2ecf20Sopenharmony_ci#define UFS_MOUNT_ONERROR_PANIC		0x00000001
578c2ecf20Sopenharmony_ci#define UFS_MOUNT_ONERROR_LOCK		0x00000002
588c2ecf20Sopenharmony_ci#define UFS_MOUNT_ONERROR_UMOUNT	0x00000004
598c2ecf20Sopenharmony_ci#define UFS_MOUNT_ONERROR_REPAIR	0x00000008
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE		0x0000FFF0
628c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_OLD		0x00000010
638c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_44BSD		0x00000020
648c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_SUN		0x00000040
658c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_NEXTSTEP	0x00000080
668c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_NEXTSTEP_CD	0x00000100
678c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_OPENSTEP	0x00000200
688c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_SUNx86	0x00000400
698c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_HP	        0x00000800
708c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_UFS2		0x00001000
718c2ecf20Sopenharmony_ci#define UFS_MOUNT_UFSTYPE_SUNOS		0x00002000
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define ufs_clear_opt(o,opt)	o &= ~UFS_MOUNT_##opt
748c2ecf20Sopenharmony_ci#define ufs_set_opt(o,opt)	o |= UFS_MOUNT_##opt
758c2ecf20Sopenharmony_ci#define ufs_test_opt(o,opt)	((o) & UFS_MOUNT_##opt)
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/*
788c2ecf20Sopenharmony_ci * Debug code
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_ci#ifdef CONFIG_UFS_DEBUG
818c2ecf20Sopenharmony_ci#	define UFSD(f, a...)	{					\
828c2ecf20Sopenharmony_ci		pr_debug("UFSD (%s, %d): %s:",				\
838c2ecf20Sopenharmony_ci			__FILE__, __LINE__, __func__);		\
848c2ecf20Sopenharmony_ci		pr_debug(f, ## a);					\
858c2ecf20Sopenharmony_ci	}
868c2ecf20Sopenharmony_ci#else
878c2ecf20Sopenharmony_ci#	define UFSD(f, a...)	/**/
888c2ecf20Sopenharmony_ci#endif
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* balloc.c */
918c2ecf20Sopenharmony_ciextern void ufs_free_fragments (struct inode *, u64, unsigned);
928c2ecf20Sopenharmony_ciextern void ufs_free_blocks (struct inode *, u64, unsigned);
938c2ecf20Sopenharmony_ciextern u64 ufs_new_fragments(struct inode *, void *, u64, u64,
948c2ecf20Sopenharmony_ci			     unsigned, int *, struct page *);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* cylinder.c */
978c2ecf20Sopenharmony_ciextern struct ufs_cg_private_info * ufs_load_cylinder (struct super_block *, unsigned);
988c2ecf20Sopenharmony_ciextern void ufs_put_cylinder (struct super_block *, unsigned);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* dir.c */
1018c2ecf20Sopenharmony_ciextern const struct inode_operations ufs_dir_inode_operations;
1028c2ecf20Sopenharmony_ciextern int ufs_add_link (struct dentry *, struct inode *);
1038c2ecf20Sopenharmony_ciextern ino_t ufs_inode_by_name(struct inode *, const struct qstr *);
1048c2ecf20Sopenharmony_ciextern int ufs_make_empty(struct inode *, struct inode *);
1058c2ecf20Sopenharmony_ciextern struct ufs_dir_entry *ufs_find_entry(struct inode *, const struct qstr *, struct page **);
1068c2ecf20Sopenharmony_ciextern int ufs_delete_entry(struct inode *, struct ufs_dir_entry *, struct page *);
1078c2ecf20Sopenharmony_ciextern int ufs_empty_dir (struct inode *);
1088c2ecf20Sopenharmony_ciextern struct ufs_dir_entry *ufs_dotdot(struct inode *, struct page **);
1098c2ecf20Sopenharmony_ciextern void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de,
1108c2ecf20Sopenharmony_ci			 struct page *page, struct inode *inode, bool update_times);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* file.c */
1138c2ecf20Sopenharmony_ciextern const struct inode_operations ufs_file_inode_operations;
1148c2ecf20Sopenharmony_ciextern const struct file_operations ufs_file_operations;
1158c2ecf20Sopenharmony_ciextern const struct address_space_operations ufs_aops;
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* ialloc.c */
1188c2ecf20Sopenharmony_ciextern void ufs_free_inode (struct inode *inode);
1198c2ecf20Sopenharmony_ciextern struct inode * ufs_new_inode (struct inode *, umode_t);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* inode.c */
1228c2ecf20Sopenharmony_ciextern struct inode *ufs_iget(struct super_block *, unsigned long);
1238c2ecf20Sopenharmony_ciextern int ufs_write_inode (struct inode *, struct writeback_control *);
1248c2ecf20Sopenharmony_ciextern int ufs_sync_inode (struct inode *);
1258c2ecf20Sopenharmony_ciextern void ufs_evict_inode (struct inode *);
1268c2ecf20Sopenharmony_ciextern int ufs_setattr(struct dentry *dentry, struct iattr *attr);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* namei.c */
1298c2ecf20Sopenharmony_ciextern const struct file_operations ufs_dir_operations;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* super.c */
1328c2ecf20Sopenharmony_ciextern __printf(3, 4)
1338c2ecf20Sopenharmony_civoid ufs_warning(struct super_block *, const char *, const char *, ...);
1348c2ecf20Sopenharmony_ciextern __printf(3, 4)
1358c2ecf20Sopenharmony_civoid ufs_error(struct super_block *, const char *, const char *, ...);
1368c2ecf20Sopenharmony_ciextern __printf(3, 4)
1378c2ecf20Sopenharmony_civoid ufs_panic(struct super_block *, const char *, const char *, ...);
1388c2ecf20Sopenharmony_civoid ufs_mark_sb_dirty(struct super_block *sb);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic inline struct ufs_sb_info *UFS_SB(struct super_block *sb)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	return sb->s_fs_info;
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic inline struct ufs_inode_info *UFS_I(struct inode *inode)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	return container_of(inode, struct ufs_inode_info, vfs_inode);
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/*
1518c2ecf20Sopenharmony_ci * Give cylinder group number for a file system block.
1528c2ecf20Sopenharmony_ci * Give cylinder group block number for a file system block.
1538c2ecf20Sopenharmony_ci */
1548c2ecf20Sopenharmony_ci/* #define	ufs_dtog(d)	((d) / uspi->s_fpg) */
1558c2ecf20Sopenharmony_cistatic inline u64 ufs_dtog(struct ufs_sb_private_info * uspi, u64 b)
1568c2ecf20Sopenharmony_ci{
1578c2ecf20Sopenharmony_ci	do_div(b, uspi->s_fpg);
1588c2ecf20Sopenharmony_ci	return b;
1598c2ecf20Sopenharmony_ci}
1608c2ecf20Sopenharmony_ci/* #define	ufs_dtogd(d)	((d) % uspi->s_fpg) */
1618c2ecf20Sopenharmony_cistatic inline u32 ufs_dtogd(struct ufs_sb_private_info * uspi, u64 b)
1628c2ecf20Sopenharmony_ci{
1638c2ecf20Sopenharmony_ci	return do_div(b, uspi->s_fpg);
1648c2ecf20Sopenharmony_ci}
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#endif /* _UFS_UFS_H */
167