xref: /linux/include/uapi/linux/bfs_fs.h (revision 597473720f4dc69749542bfcfed4a927a43d935e)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells /*
3607ca46eSDavid Howells  *	include/linux/bfs_fs.h - BFS data structures on disk.
4*d1877155STigran Aivazian  *	Copyright (C) 1999-2018 Tigran Aivazian <aivazian.tigran@gmail.com>
5607ca46eSDavid Howells  */
6607ca46eSDavid Howells 
7607ca46eSDavid Howells #ifndef _LINUX_BFS_FS_H
8607ca46eSDavid Howells #define _LINUX_BFS_FS_H
9607ca46eSDavid Howells 
10607ca46eSDavid Howells #include <linux/types.h>
11607ca46eSDavid Howells 
12607ca46eSDavid Howells #define BFS_BSIZE_BITS		9
13607ca46eSDavid Howells #define BFS_BSIZE		(1<<BFS_BSIZE_BITS)
14607ca46eSDavid Howells 
15607ca46eSDavid Howells #define BFS_MAGIC		0x1BADFACE
16607ca46eSDavid Howells #define BFS_ROOT_INO		2
17607ca46eSDavid Howells #define BFS_INODES_PER_BLOCK	8
18607ca46eSDavid Howells 
19607ca46eSDavid Howells /* SVR4 vnode type values (bfs_inode->i_vtype) */
20607ca46eSDavid Howells #define BFS_VDIR 2L
21607ca46eSDavid Howells #define BFS_VREG 1L
22607ca46eSDavid Howells 
23607ca46eSDavid Howells /* BFS inode layout on disk */
24607ca46eSDavid Howells struct bfs_inode {
25607ca46eSDavid Howells 	__le16 i_ino;
26607ca46eSDavid Howells 	__u16 i_unused;
27607ca46eSDavid Howells 	__le32 i_sblock;
28607ca46eSDavid Howells 	__le32 i_eblock;
29607ca46eSDavid Howells 	__le32 i_eoffset;
30607ca46eSDavid Howells 	__le32 i_vtype;
31607ca46eSDavid Howells 	__le32 i_mode;
32607ca46eSDavid Howells 	__le32 i_uid;
33607ca46eSDavid Howells 	__le32 i_gid;
34607ca46eSDavid Howells 	__le32 i_nlink;
35607ca46eSDavid Howells 	__le32 i_atime;
36607ca46eSDavid Howells 	__le32 i_mtime;
37607ca46eSDavid Howells 	__le32 i_ctime;
38607ca46eSDavid Howells 	__u32 i_padding[4];
39607ca46eSDavid Howells };
40607ca46eSDavid Howells 
41607ca46eSDavid Howells #define BFS_NAMELEN		14
42607ca46eSDavid Howells #define BFS_DIRENT_SIZE		16
43607ca46eSDavid Howells #define BFS_DIRS_PER_BLOCK	32
44607ca46eSDavid Howells 
45607ca46eSDavid Howells struct bfs_dirent {
46607ca46eSDavid Howells 	__le16 ino;
47607ca46eSDavid Howells 	char name[BFS_NAMELEN];
48607ca46eSDavid Howells };
49607ca46eSDavid Howells 
50607ca46eSDavid Howells /* BFS superblock layout on disk */
51607ca46eSDavid Howells struct bfs_super_block {
52607ca46eSDavid Howells 	__le32 s_magic;
53607ca46eSDavid Howells 	__le32 s_start;
54607ca46eSDavid Howells 	__le32 s_end;
55607ca46eSDavid Howells 	__le32 s_from;
56607ca46eSDavid Howells 	__le32 s_to;
57607ca46eSDavid Howells 	__s32 s_bfrom;
58607ca46eSDavid Howells 	__s32 s_bto;
59607ca46eSDavid Howells 	char  s_fsname[6];
60607ca46eSDavid Howells 	char  s_volume[6];
61607ca46eSDavid Howells 	__u32 s_padding[118];
62607ca46eSDavid Howells };
63607ca46eSDavid Howells 
64607ca46eSDavid Howells 
65607ca46eSDavid Howells #define BFS_OFF2INO(offset) \
66607ca46eSDavid Howells         ((((offset) - BFS_BSIZE) / sizeof(struct bfs_inode)) + BFS_ROOT_INO)
67607ca46eSDavid Howells 
68607ca46eSDavid Howells #define BFS_INO2OFF(ino) \
69607ca46eSDavid Howells 	((__u32)(((ino) - BFS_ROOT_INO) * sizeof(struct bfs_inode)) + BFS_BSIZE)
70607ca46eSDavid Howells #define BFS_NZFILESIZE(ip) \
71607ca46eSDavid Howells         ((le32_to_cpu((ip)->i_eoffset) + 1) -  le32_to_cpu((ip)->i_sblock) * BFS_BSIZE)
72607ca46eSDavid Howells 
73607ca46eSDavid Howells #define BFS_FILESIZE(ip) \
74607ca46eSDavid Howells         ((ip)->i_sblock == 0 ? 0 : BFS_NZFILESIZE(ip))
75607ca46eSDavid Howells 
76607ca46eSDavid Howells #define BFS_FILEBLOCKS(ip) \
77607ca46eSDavid Howells         ((ip)->i_sblock == 0 ? 0 : (le32_to_cpu((ip)->i_eblock) + 1) -  le32_to_cpu((ip)->i_sblock))
78607ca46eSDavid Howells #define BFS_UNCLEAN(bfs_sb, sb)	\
791751e8a6SLinus Torvalds 	((le32_to_cpu(bfs_sb->s_from) != -1) && (le32_to_cpu(bfs_sb->s_to) != -1) && !(sb->s_flags & SB_RDONLY))
80607ca46eSDavid Howells 
81607ca46eSDavid Howells 
82607ca46eSDavid Howells #endif	/* _LINUX_BFS_FS_H */
83