xref: /haiku/src/add-ons/kernel/file_systems/reiserfs/reiserfs.h (revision 25a7b01d15612846f332751841da3579db313082)
1 /* Copyright 1996-2000 Hans Reiser, see reiserfs/README for licensing
2  * and copyright details */
3 //
4 // Modified by Ingo Weinhold (bonefish), Jan. 2003:
5 // Glued from the files reiserfs_fs.h and reiserfs_sb.h,
6 // adjusted for BeOS and cut what wasn't needed for my purpose.
7 
8 #ifndef REISER_FS_H
9 #define REISER_FS_H
10 
11 #include <SupportDefs.h>
12 
13 //////////////////////
14 // from reiserfs_fs.h
15 //
16 
17 /* there are two formats of keys: 3.5 and 3.6
18  */
19 #define KEY_FORMAT_3_5 0
20 #define KEY_FORMAT_3_6 1
21 
22 /* there are two stat datas */
23 #define STAT_DATA_V1 0
24 #define STAT_DATA_V2 1
25 
26 #define SD_OFFSET  0
27 #define SD_UNIQUENESS 0
28 #define DOT_OFFSET 1
29 #define DOT_DOT_OFFSET 2
30 #define DIRENTRY_UNIQUENESS 500
31 #define FIRST_ITEM_OFFSET 1
32 
33 #define REISERFS_ROOT_OBJECTID 2
34 #define REISERFS_ROOT_PARENT_OBJECTID 1
35 
36 //
37 // there are 5 item types currently
38 //
39 #define TYPE_STAT_DATA 0
40 #define TYPE_INDIRECT 1
41 #define TYPE_DIRECT 2
42 #define TYPE_DIRENTRY 3
43 #define TYPE_ANY 15 // FIXME: comment is required
44 
45 #define V1_SD_UNIQUENESS 0
46 #define V1_INDIRECT_UNIQUENESS 0xfffffffe
47 #define V1_DIRECT_UNIQUENESS 0xffffffff
48 #define V1_DIRENTRY_UNIQUENESS 500
49 #define V1_ANY_UNIQUENESS 555 // FIXME: comment is required
50 
51 
52 /* hash value occupies bits from 7 up to 30 */
53 static inline
54 uint32
offset_hash_value(uint64 offset)55 offset_hash_value(uint64 offset)
56 {
57 	return offset & 0x7fffff80ULL;
58 }
59 
60 /* generation number occupies 7 bits starting from 0 up to 6 */
61 static inline
62 uint32
offset_generation_number(uint64 offset)63 offset_generation_number(uint64 offset)
64 {
65 	return offset & 0x7fULL;
66 }
67 
68 #define MAX_GENERATION_NUMBER  127
69 
70 //
71 // directories use this key as well as old files
72 //
73 struct offset_v1 {
74 	uint32	k_offset;
75 	uint32	k_uniqueness;
76 } _PACKED;
77 
78 struct offset_v2 {
79 #if LITTLE_ENDIAN
80 	// little endian
81 	uint64	k_offset:60;
82 	uint64	k_type: 4;
83 #else
84 	// big endian
85 	uint64	k_type: 4;
86 	uint64	k_offset:60;
87 #endif
88 } _PACKED;
89 
90 
91 struct key {
92 	uint32	k_dir_id;    /* packing locality: by default parent
93 						    directory object id */
94 	uint32	k_objectid;  /* object identifier */
95 	union {
96 		offset_v1	k_offset_v1;
97 		offset_v2	k_offset_v2;
98 	} _PACKED u;
99 } _PACKED;
100 
101 
102 struct block_head {
103 	uint16	blk_level;        /* Level of a block in the tree. */
104 	uint16	blk_nr_item;      /* Number of keys/items in a block. */
105 	uint16	blk_free_space;   /* Block free space in bytes. */
106 	uint16	blk_reserved;
107 	key		blk_right_delim_key; /* kept only for compatibility */
108 };
109 
110 struct disk_child {
111 	uint32	dc_block_number;              /* Disk child's block number. */
112 	uint16	dc_size;		            /* Disk child's used space.   */
113 	uint16	dc_reserved;
114 };
115 
116 struct item_head
117 {
118 	/* Everything in the tree is found by searching for it based on
119 	* its key.*/
120 	struct key ih_key;
121 	union {
122 		/* The free space in the last unformatted node of an
123 		indirect item if this is an indirect item.  This
124 		equals 0xFFFF iff this is a direct item or stat data
125 		item. Note that the key, not this field, is used to
126 		determine the item type, and thus which field this
127 		union contains. */
128 		uint16 ih_free_space_reserved;
129 		/* Iff this is a directory item, this field equals the
130 		number of directory entries in the directory item. */
131 		uint16 ih_entry_count;
132 	} _PACKED u;
133 	uint16 ih_item_len;           /* total size of the item body */
134 	uint16 ih_item_location;      /* an offset to the item body
135 								   * within the block */
136 	uint16 ih_version;	     /* 0 for all old items, 2 for new
137 								ones. Highest bit is set by fsck
138 								temporary, cleaned after all
139 								done */
140 } _PACKED;
141 
142 struct stat_data {
143 	uint16	sd_mode;	/* file type, permissions */
144 	uint16	sd_reserved;
145 	uint32	sd_nlink;	/* number of hard links */
146 	uint64	sd_size;	/* file size */
147 	uint32	sd_uid;		/* owner */
148 	uint32	sd_gid;		/* group */
149 	uint32	sd_atime;	/* time of last access */
150 	uint32	sd_mtime;	/* time file was last modified  */
151 	uint32	sd_ctime;	/* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
152 	uint32	sd_blocks;
153 	union {
154 		uint32	sd_rdev;
155 		uint32	sd_generation;
156 	} _PACKED u;
157 } _PACKED;
158 
159 struct stat_data_v1
160 {
161 	uint16	sd_mode;	/* file type, permissions */
162 	uint16	sd_nlink;	/* number of hard links */
163 	uint16	sd_uid;		/* owner */
164 	uint16	sd_gid;		/* group */
165 	uint32	sd_size;	/* file size */
166 	uint32	sd_atime;	/* time of last access */
167 	uint32	sd_mtime;	/* time file was last modified  */
168 	uint32	sd_ctime;	/* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
169 	union {
170 		uint32	sd_rdev;
171 		uint32	sd_blocks;	/* number of blocks file uses */
172 	} _PACKED u;
173 	uint32	sd_first_direct_byte; /* first byte of file which is stored
174 	in a direct item: except that if it
175 	equals 1 it is a symlink and if it
176 	equals ~(__u32)0 there is no
177 	direct item.  The existence of this
178 	field really grates on me. Let's
179 	replace it with a macro based on
180 	sd_size and our tail suppression
181 	policy.  Someday.  -Hans */
182 } _PACKED;
183 
184 struct reiserfs_de_head
185 {
186 	uint32	deh_offset;		/* third component of the directory entry key */
187 	uint32	deh_dir_id;		/* objectid of the parent directory of the object, that is referenced
188 								by directory entry */
189 	uint32	deh_objectid;		/* objectid of the object, that is referenced by directory entry */
190 	uint16	deh_location;		/* offset of name in the whole item */
191 	uint16	deh_state;		/* whether 1) entry contains stat data (for future), and 2) whether
192 								entry is hidden (unlinked) */
193 } _PACKED;
194 
195 #define DEH_Statdata 0			/* not used now */
196 #define DEH_Visible 2
197 
198 /* ReiserFS leaves the first 64k unused, so that partition labels have
199    enough space.  If someone wants to write a fancy bootloader that
200    needs more than 64k, let us know, and this will be increased in size.
201    This number must be larger than than the largest block size on any
202    platform, or code will break.  -Hans */
203 #define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
204 
205 /* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */
206 #define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
207 
208 #define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
209 #define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
210 
211 /*
212  * values for s_state field
213  */
214 #define REISERFS_VALID_FS    1
215 #define REISERFS_ERROR_FS    2
216 
217 
218 //////////////////////
219 // from reiserfs_sb.h
220 //
221 
222 //
223 // superblock's field values
224 //
225 #define REISERFS_VERSION_0 0 /* undistributed bitmap */
226 #define REISERFS_VERSION_1 1 /* distributed bitmap and resizer*/
227 #define REISERFS_VERSION_2 2 /* distributed bitmap, resizer, 64-bit, etc*/
228 #define UNSET_HASH 0 // read_super will guess about, what hash names
229                      // in directories were sorted with
230 #define TEA_HASH  1
231 #define YURA_HASH 2
232 #define R5_HASH   3
233 #define DEFAULT_HASH R5_HASH
234 
235 /* this is the on disk superblock */
236 
237 struct reiserfs_super_block
238 {
239   uint32 s_block_count;
240   uint32 s_free_blocks;                  /* free blocks count    */
241   uint32 s_root_block;           	/* root block number    */
242   uint32 s_journal_block;           	/* journal block number    */
243   uint32 s_journal_dev;           	/* journal device number  */
244 
245   /* Since journal size is currently a #define in a header file, if
246   ** someone creates a disk with a 16MB journal and moves it to a
247   ** system with 32MB journal default, they will overflow their journal
248   ** when they mount the disk.  s_orig_journal_size, plus some checks
249   ** while mounting (inside journal_init) prevent that from happening
250   */
251 
252 				/* great comment Chris. Thanks.  -Hans */
253 
254   uint32 s_orig_journal_size;
255   uint32 s_journal_trans_max ;           /* max number of blocks in a transaction.  */
256   uint32 s_journal_block_count ;         /* total size of the journal. can change over time  */
257   uint32 s_journal_max_batch ;           /* max number of blocks to batch into a trans */
258   uint32 s_journal_max_commit_age ;      /* in seconds, how old can an async commit be */
259   uint32 s_journal_max_trans_age ;       /* in seconds, how old can a transaction be */
260   uint16 s_blocksize;                   	/* block size           */
261   uint16 s_oid_maxsize;			/* max size of object id array, see get_objectid() commentary  */
262   uint16 s_oid_cursize;			/* current size of object id array */
263   uint16 s_state;                       	/* valid or error       */
264   char s_magic[12];                     /* reiserfs magic string indicates that file system is reiserfs */
265   uint32 s_hash_function_code;		/* indicate, what hash function is being use to sort names in a directory*/
266   uint16 s_tree_height;                  /* height of disk tree */
267   uint16 s_bmap_nr;                      /* amount of bitmap blocks needed to address each block of file system */
268   uint16 s_version;		/* I'd prefer it if this was a string,
269                                    something like "3.6.4", and maybe
270                                    16 bytes long mostly unused. We
271                                    don't need to save bytes in the
272                                    superblock. -Hans */
273   uint16 s_reserved;
274   uint32 s_inode_generation;
275   uint32 s_flags;
276   char s_uuid[16];
277   char s_label[16];
278   uint16 s_mnt_count;
279   uint16 s_max_mnt_count;
280   uint32 s_lastcheck;
281   uint32 s_check_interval;
282   char s_unused[76] ;			/* zero filled by mkreiserfs */
283 } _PACKED;
284 
285 #define SB_SIZE (sizeof(struct reiserfs_super_block))
286 
287 /* this is the super from 3.5.X, where X >= 10 */
288 struct reiserfs_super_block_v1
289 {
290   uint32 s_block_count;			/* blocks count         */
291   uint32 s_free_blocks;                  /* free blocks count    */
292   uint32 s_root_block;           	/* root block number    */
293   uint32 s_journal_block;           	/* journal block number    */
294   uint32 s_journal_dev;           	/* journal device number  */
295   uint32 s_orig_journal_size; 		/* size of the journal on FS creation.  used to make sure they don't overflow it */
296   uint32 s_journal_trans_max ;           /* max number of blocks in a transaction.  */
297   uint32 s_journal_block_count ;         /* total size of the journal. can change over time  */
298   uint32 s_journal_max_batch ;           /* max number of blocks to batch into a trans */
299   uint32 s_journal_max_commit_age ;      /* in seconds, how old can an async commit be */
300   uint32 s_journal_max_trans_age ;       /* in seconds, how old can a transaction be */
301   uint16 s_blocksize;                   	/* block size           */
302   uint16 s_oid_maxsize;			/* max size of object id array, see get_objectid() commentary  */
303   uint16 s_oid_cursize;			/* current size of object id array */
304   uint16 s_state;                       	/* valid or error       */
305   char s_magic[16];                     /* reiserfs magic string indicates that file system is reiserfs */
306   uint16 s_tree_height;                  /* height of disk tree */
307   uint16 s_bmap_nr;                      /* amount of bitmap blocks needed to address each block of file system */
308   uint32 s_reserved;
309 } _PACKED;
310 
311 #define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
312 
313 /* Definitions of reiserfs on-disk properties: */
314 #define REISERFS_3_5 0
315 #define REISERFS_3_6 1
316 
317 #endif	// REISER_FS_H
318