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