18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * befs.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2001-2002 Will Dyson <will_dyson@pobox.com>
68c2ecf20Sopenharmony_ci * Copyright (C) 1999 Makoto Kato (m_kato@ga2.so-net.ne.jp)
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef _LINUX_BEFS_H
108c2ecf20Sopenharmony_ci#define _LINUX_BEFS_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include "befs_fs_types.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* used in debug.c */
158c2ecf20Sopenharmony_ci#define BEFS_VERSION "0.9.3"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_citypedef u64 befs_blocknr_t;
198c2ecf20Sopenharmony_ci/*
208c2ecf20Sopenharmony_ci * BeFS in memory structures
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct befs_mount_options {
248c2ecf20Sopenharmony_ci	kgid_t gid;
258c2ecf20Sopenharmony_ci	kuid_t uid;
268c2ecf20Sopenharmony_ci	int use_gid;
278c2ecf20Sopenharmony_ci	int use_uid;
288c2ecf20Sopenharmony_ci	int debug;
298c2ecf20Sopenharmony_ci	char *iocharset;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct befs_sb_info {
338c2ecf20Sopenharmony_ci	u32 magic1;
348c2ecf20Sopenharmony_ci	u32 block_size;
358c2ecf20Sopenharmony_ci	u32 block_shift;
368c2ecf20Sopenharmony_ci	int byte_order;
378c2ecf20Sopenharmony_ci	befs_off_t num_blocks;
388c2ecf20Sopenharmony_ci	befs_off_t used_blocks;
398c2ecf20Sopenharmony_ci	u32 inode_size;
408c2ecf20Sopenharmony_ci	u32 magic2;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	/* Allocation group information */
438c2ecf20Sopenharmony_ci	u32 blocks_per_ag;
448c2ecf20Sopenharmony_ci	u32 ag_shift;
458c2ecf20Sopenharmony_ci	u32 num_ags;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	/* State of the superblock */
488c2ecf20Sopenharmony_ci	u32 flags;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	/* Journal log entry */
518c2ecf20Sopenharmony_ci	befs_block_run log_blocks;
528c2ecf20Sopenharmony_ci	befs_off_t log_start;
538c2ecf20Sopenharmony_ci	befs_off_t log_end;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	befs_inode_addr root_dir;
568c2ecf20Sopenharmony_ci	befs_inode_addr indices;
578c2ecf20Sopenharmony_ci	u32 magic3;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	struct befs_mount_options mount_opts;
608c2ecf20Sopenharmony_ci	struct nls_table *nls;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct befs_inode_info {
648c2ecf20Sopenharmony_ci	u32 i_flags;
658c2ecf20Sopenharmony_ci	u32 i_type;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	befs_inode_addr i_inode_num;
688c2ecf20Sopenharmony_ci	befs_inode_addr i_parent;
698c2ecf20Sopenharmony_ci	befs_inode_addr i_attribute;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	union {
728c2ecf20Sopenharmony_ci		befs_data_stream ds;
738c2ecf20Sopenharmony_ci		char symlink[BEFS_SYMLINK_LEN];
748c2ecf20Sopenharmony_ci	} i_data;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	struct inode vfs_inode;
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cienum befs_err {
808c2ecf20Sopenharmony_ci	BEFS_OK,
818c2ecf20Sopenharmony_ci	BEFS_ERR,
828c2ecf20Sopenharmony_ci	BEFS_BAD_INODE,
838c2ecf20Sopenharmony_ci	BEFS_BT_END,
848c2ecf20Sopenharmony_ci	BEFS_BT_EMPTY,
858c2ecf20Sopenharmony_ci	BEFS_BT_MATCH,
868c2ecf20Sopenharmony_ci	BEFS_BT_OVERFLOW,
878c2ecf20Sopenharmony_ci	BEFS_BT_NOT_FOUND
888c2ecf20Sopenharmony_ci};
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/****************************/
928c2ecf20Sopenharmony_ci/* debug.c */
938c2ecf20Sopenharmony_ci__printf(2, 3)
948c2ecf20Sopenharmony_civoid befs_error(const struct super_block *sb, const char *fmt, ...);
958c2ecf20Sopenharmony_ci__printf(2, 3)
968c2ecf20Sopenharmony_civoid befs_warning(const struct super_block *sb, const char *fmt, ...);
978c2ecf20Sopenharmony_ci__printf(2, 3)
988c2ecf20Sopenharmony_civoid befs_debug(const struct super_block *sb, const char *fmt, ...);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_civoid befs_dump_super_block(const struct super_block *sb, befs_super_block *);
1018c2ecf20Sopenharmony_civoid befs_dump_inode(const struct super_block *sb, befs_inode *);
1028c2ecf20Sopenharmony_civoid befs_dump_index_entry(const struct super_block *sb, befs_disk_btree_super *);
1038c2ecf20Sopenharmony_civoid befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead *);
1048c2ecf20Sopenharmony_ci/****************************/
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* Gets a pointer to the private portion of the super_block
1088c2ecf20Sopenharmony_ci * structure from the public part
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_cistatic inline struct befs_sb_info *
1118c2ecf20Sopenharmony_ciBEFS_SB(const struct super_block *super)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	return (struct befs_sb_info *) super->s_fs_info;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic inline struct befs_inode_info *
1178c2ecf20Sopenharmony_ciBEFS_I(const struct inode *inode)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	return container_of(inode, struct befs_inode_info, vfs_inode);
1208c2ecf20Sopenharmony_ci}
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic inline befs_blocknr_t
1238c2ecf20Sopenharmony_ciiaddr2blockno(struct super_block *sb, const befs_inode_addr *iaddr)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	return ((iaddr->allocation_group << BEFS_SB(sb)->ag_shift) +
1268c2ecf20Sopenharmony_ci		iaddr->start);
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic inline befs_inode_addr
1308c2ecf20Sopenharmony_ciblockno2iaddr(struct super_block *sb, befs_blocknr_t blockno)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	befs_inode_addr iaddr;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	iaddr.allocation_group = blockno >> BEFS_SB(sb)->ag_shift;
1358c2ecf20Sopenharmony_ci	iaddr.start =
1368c2ecf20Sopenharmony_ci	    blockno - (iaddr.allocation_group << BEFS_SB(sb)->ag_shift);
1378c2ecf20Sopenharmony_ci	iaddr.len = 1;
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	return iaddr;
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic inline unsigned int
1438c2ecf20Sopenharmony_cibefs_iaddrs_per_block(struct super_block *sb)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	return BEFS_SB(sb)->block_size / sizeof(befs_disk_inode_addr);
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#include "endian.h"
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#endif				/* _LINUX_BEFS_H */
151