1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * fs/befs/befs_fs_types.h
4  *
5  * Copyright (C) 2001 Will Dyson (will@cs.earlham.edu)
6  *
7  *
8  *
9  * from linux/include/linux/befs_fs.h
10  *
11  * Copyright (C) 1999 Makoto Kato (m_kato@ga2.so-net.ne.jp)
12  *
13  */
14 
15 #ifndef _LINUX_BEFS_FS_TYPES
16 #define _LINUX_BEFS_FS_TYPES
17 
18 #ifdef __KERNEL__
19 #include <linux/types.h>
20 #endif /*__KERNEL__*/
21 
22 #define PACKED __attribute__ ((__packed__))
23 
24 /*
25  * Max name lengths of BFS
26  */
27 
28 #define BEFS_NAME_LEN 255
29 
30 #define BEFS_SYMLINK_LEN 144
31 #define BEFS_NUM_DIRECT_BLOCKS 12
32 #define B_OS_NAME_LENGTH 32
33 
34 /* The datastream blocks mapped by the double-indirect
35  * block are always 4 fs blocks long.
36  * This eliminates the need for linear searches among
37  * the potentially huge number of indirect blocks
38  *
39  * Err. Should that be 4 fs blocks or 4k???
40  * It matters on large blocksize volumes
41  */
42 #define BEFS_DBLINDIR_BRUN_LEN 4
43 
44 /*
45  * Flags of superblock
46  */
47 
48 enum super_flags {
49 	BEFS_BYTESEX_BE,
50 	BEFS_BYTESEX_LE,
51 	BEFS_CLEAN = 0x434c454e,
52 	BEFS_DIRTY = 0x44495254,
53 	BEFS_SUPER_MAGIC1 = 0x42465331,	/* BFS1 */
54 	BEFS_SUPER_MAGIC2 = 0xdd121031,
55 	BEFS_SUPER_MAGIC3 = 0x15b6830e,
56 };
57 
58 #define BEFS_BYTEORDER_NATIVE 0x42494745
59 #define BEFS_BYTEORDER_NATIVE_LE ((__force fs32)cpu_to_le32(BEFS_BYTEORDER_NATIVE))
60 #define BEFS_BYTEORDER_NATIVE_BE ((__force fs32)cpu_to_be32(BEFS_BYTEORDER_NATIVE))
61 
62 #define BEFS_SUPER_MAGIC BEFS_SUPER_MAGIC1
63 #define BEFS_SUPER_MAGIC1_LE ((__force fs32)cpu_to_le32(BEFS_SUPER_MAGIC1))
64 #define BEFS_SUPER_MAGIC1_BE ((__force fs32)cpu_to_be32(BEFS_SUPER_MAGIC1))
65 
66 /*
67  * Flags of inode
68  */
69 
70 #define BEFS_INODE_MAGIC1 0x3bbe0ad9
71 
72 enum inode_flags {
73 	BEFS_INODE_IN_USE = 0x00000001,
74 	BEFS_ATTR_INODE = 0x00000004,
75 	BEFS_INODE_LOGGED = 0x00000008,
76 	BEFS_INODE_DELETED = 0x00000010,
77 	BEFS_LONG_SYMLINK = 0x00000040,
78 	BEFS_PERMANENT_FLAG = 0x0000ffff,
79 	BEFS_INODE_NO_CREATE = 0x00010000,
80 	BEFS_INODE_WAS_WRITTEN = 0x00020000,
81 	BEFS_NO_TRANSACTION = 0x00040000,
82 };
83 /*
84  * On-Disk datastructures of BeFS
85  */
86 
87 typedef u64 __bitwise fs64;
88 typedef u32 __bitwise fs32;
89 typedef u16 __bitwise fs16;
90 
91 typedef u64 befs_off_t;
92 typedef fs64 befs_time_t;
93 
94 /* Block runs */
95 typedef struct {
96 	fs32 allocation_group;
97 	fs16 start;
98 	fs16 len;
99 } PACKED befs_disk_block_run;
100 
101 typedef struct {
102 	u32 allocation_group;
103 	u16 start;
104 	u16 len;
105 } PACKED befs_block_run;
106 
107 typedef befs_disk_block_run befs_disk_inode_addr;
108 typedef befs_block_run befs_inode_addr;
109 
110 /*
111  * The Superblock Structure
112  */
113 typedef struct {
114 	char name[B_OS_NAME_LENGTH];
115 	fs32 magic1;
116 	fs32 fs_byte_order;
117 
118 	fs32 block_size;
119 	fs32 block_shift;
120 
121 	fs64 num_blocks;
122 	fs64 used_blocks;
123 
124 	fs32 inode_size;
125 
126 	fs32 magic2;
127 	fs32 blocks_per_ag;
128 	fs32 ag_shift;
129 	fs32 num_ags;
130 
131 	fs32 flags;
132 
133 	befs_disk_block_run log_blocks;
134 	fs64 log_start;
135 	fs64 log_end;
136 
137 	fs32 magic3;
138 	befs_disk_inode_addr root_dir;
139 	befs_disk_inode_addr indices;
140 
141 } PACKED befs_super_block;
142 
143 /*
144  * Note: the indirect and dbl_indir block_runs may
145  * be longer than one block!
146  */
147 typedef struct {
148 	befs_disk_block_run direct[BEFS_NUM_DIRECT_BLOCKS];
149 	fs64 max_direct_range;
150 	befs_disk_block_run indirect;
151 	fs64 max_indirect_range;
152 	befs_disk_block_run double_indirect;
153 	fs64 max_double_indirect_range;
154 	fs64 size;
155 } PACKED befs_disk_data_stream;
156 
157 typedef struct {
158 	befs_block_run direct[BEFS_NUM_DIRECT_BLOCKS];
159 	befs_off_t max_direct_range;
160 	befs_block_run indirect;
161 	befs_off_t max_indirect_range;
162 	befs_block_run double_indirect;
163 	befs_off_t max_double_indirect_range;
164 	befs_off_t size;
165 } PACKED befs_data_stream;
166 
167 /* Attribute */
168 typedef struct {
169 	fs32 type;
170 	fs16 name_size;
171 	fs16 data_size;
172 	char name[1];
173 } PACKED befs_small_data;
174 
175 /* Inode structure */
176 typedef struct {
177 	fs32 magic1;
178 	befs_disk_inode_addr inode_num;
179 	fs32 uid;
180 	fs32 gid;
181 	fs32 mode;
182 	fs32 flags;
183 	befs_time_t create_time;
184 	befs_time_t last_modified_time;
185 	befs_disk_inode_addr parent;
186 	befs_disk_inode_addr attributes;
187 	fs32 type;
188 
189 	fs32 inode_size;
190 	fs32 etc;		/* not use */
191 
192 	union {
193 		befs_disk_data_stream datastream;
194 		char symlink[BEFS_SYMLINK_LEN];
195 	} data;
196 
197 	fs32 pad[4];		/* not use */
198 	befs_small_data small_data[1];
199 } PACKED befs_inode;
200 
201 /*
202  * B+tree superblock
203  */
204 
205 #define BEFS_BTREE_MAGIC 0x69f6c2e8
206 
207 enum btree_types {
208 	BTREE_STRING_TYPE = 0,
209 	BTREE_INT32_TYPE = 1,
210 	BTREE_UINT32_TYPE = 2,
211 	BTREE_INT64_TYPE = 3,
212 	BTREE_UINT64_TYPE = 4,
213 	BTREE_FLOAT_TYPE = 5,
214 	BTREE_DOUBLE_TYPE = 6
215 };
216 
217 typedef struct {
218 	fs32 magic;
219 	fs32 node_size;
220 	fs32 max_depth;
221 	fs32 data_type;
222 	fs64 root_node_ptr;
223 	fs64 free_node_ptr;
224 	fs64 max_size;
225 } PACKED befs_disk_btree_super;
226 
227 typedef struct {
228 	u32 magic;
229 	u32 node_size;
230 	u32 max_depth;
231 	u32 data_type;
232 	befs_off_t root_node_ptr;
233 	befs_off_t free_node_ptr;
234 	befs_off_t max_size;
235 } PACKED befs_btree_super;
236 
237 /*
238  * Header structure of each btree node
239  */
240 typedef struct {
241 	fs64 left;
242 	fs64 right;
243 	fs64 overflow;
244 	fs16 all_key_count;
245 	fs16 all_key_length;
246 } PACKED befs_btree_nodehead;
247 
248 typedef struct {
249 	befs_off_t left;
250 	befs_off_t right;
251 	befs_off_t overflow;
252 	u16 all_key_count;
253 	u16 all_key_length;
254 } PACKED befs_host_btree_nodehead;
255 
256 #endif				/* _LINUX_BEFS_FS_TYPES */
257