[REISERFS]
[reactos.git] / reactos / drivers / filesystems / reiserfs / inc / reiserfs.h
1 #ifndef __RFSD_REISER_FS_H__
2 #define __RFSD_REISER_FS_H__
3
4 #include <linux/types.h>
5
6 #ifdef __GCC__
7 #ifndef __REACTOS__
8 #define __PACKED __PACKED
9 #else
10 #define __PACKED __attribute__((packed))
11 #endif
12 #else
13 #define __PACKED
14 #endif
15
16 /***************************************************************************/
17 /* SUPER BLOCK */
18 /***************************************************************************/
19
20 /*
21 * Structure of super block on disk, a version of which in RAM is often accessed as REISERFS_SB(s)->s_rs
22 * the version in RAM is part of a larger structure containing fields never written to disk.
23 */
24 #define UNSET_HASH 0 // read_super will guess about, what hash names
25 // in directories were sorted with
26 #define TEA_HASH 1
27 #define YURA_HASH 2
28 #define R5_HASH 3
29 #define DEFAULT_HASH R5_HASH
30
31
32 struct journal_params {
33 // Block number of the block containing the first journal node.
34 __u32 jp_journal_1st_block; /* where does journal start from on its device */
35
36 // Journal device number (?? for if the journal is on a seperate drive ??)
37 __u32 jp_journal_dev; /* journal device st_rdev */
38
39 // Original journal size. (Needed when using partition on systems w/ different default journal sizes).
40 __u32 jp_journal_size; /* size of the journal */
41
42 __u32 jp_journal_trans_max; /* max number of blocks in a transaction. */
43 __u32 jp_journal_magic; /* random value made on fs creation (this was sb_journal_block_count) */
44 __u32 jp_journal_max_batch; /* max number of blocks to batch into a trans */
45 __u32 jp_journal_max_commit_age; /* in seconds, how old can an async commit be */
46 __u32 jp_journal_max_trans_age; /* in seconds, how old can a transaction be */
47 };
48
49 /* this is the super from 3.5.X, where X >= 10 */
50 #ifndef __GCC__
51 #pragma pack(push, 1)
52 #endif
53
54 struct reiserfs_super_block_v1
55 {
56 // The number of blocks in the partition
57 __u32 s_blocks_count; /* blocks count */ //[mark] was _s_blocks_count
58
59 // The number of free blocks in the partition
60 __u32 s_free_blocks_count; /* free blocks count */ //[mark] was _s_free_blocks
61
62 // Block number of the block containing the root node
63 __u32 s_root_block; /* root block number */
64
65
66 struct journal_params s_journal;
67
68 // The size (in bytes) of a block
69 __u16 s_blocksize; /* block size */
70
71 __u16 s_oid_maxsize; /* max size of object id array, see get_objectid() commentary */
72 __u16 s_oid_cursize; /* current size of object id array */
73 __u16 s_umount_state; /* this is set to 1 when filesystem was umounted, to 2 - when not */
74 char s_magic[10]; /* reiserfs magic string indicates that
75 * file system is reiserfs:
76 * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */
77
78 // State of the partition: valid(1), error (2)
79 __u16 s_fs_state; /* it is set to used by fsck to mark which phase of rebuilding is done */
80
81 __u32 s_hash_function_code; /* indicate, what hash function is being use
82 * to sort names in a directory*/
83 __u16 s_tree_height; /* height of disk tree */
84 __u16 s_bmap_nr; /* amount of bitmap blocks needed to address
85 * each block of file system */
86
87 // The reiserfs version number
88 __u16 s_version; /* this field is only reliable on filesystem
89 * with non-standard journal */
90 __u16 s_reserved_for_journal; /* size in blocks of journal area on main
91 * device, we need to keep after
92 * making fs with non-standard journal */
93 } __PACKED;
94 #ifndef __GCC__
95 #pragma pack(pop)
96 #endif
97
98
99 #define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
100
101 /* this is the on disk super block */
102 #ifndef __GCC__
103 #pragma pack(push, 1)
104 #endif
105
106 struct reiserfs_super_block
107 {
108 struct reiserfs_super_block_v1 s_v1;
109
110 // Number of the current inode generation (a counter that is increased every time the tree gets re-balanced).
111 __u32 s_inode_generation;
112
113 __u32 s_flags; /* Right now used only by inode-attributes, if enabled */
114 unsigned char s_uuid[16]; /* filesystem unique identifier */
115 unsigned char s_label[16]; /* filesystem volume label */
116 char s_unused[88] ; /* zero filled by mkreiserfs and
117 * reiserfs_convert_objectid_map_v1()
118 * so any additions must be updated
119 * there as well. */
120 } __PACKED;
121
122 #ifndef __GCC__
123 #pragma pack(pop)
124 #endif
125
126 #define SB_SIZE (sizeof(struct reiserfs_super_block))
127
128 #define REISERFS_VERSION_1 0
129 #define REISERFS_VERSION_2 2
130
131 // ... [ommissions]
132
133
134 /* used by gcc */
135 #define REISERFS_SUPER_MAGIC 0x52654973
136 /* used by file system utilities that
137 look at the superblock, etc. */
138 #define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
139 #define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
140 #define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs"
141
142 /* ReiserFS leaves the first 64k unused, so that partition labels have
143 enough space. If someone wants to write a fancy bootloader that
144 needs more than 64k, let us know, and this will be increased in size.
145 This number must be larger than than the largest block size on any
146 platform, or code will break. -Hans */
147 #define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
148 #define REISERFS_FIRST_BLOCK unused_define
149 #define REISERFS_JOURNAL_OFFSET_IN_BYTES REISERFS_DISK_OFFSET_IN_BYTES
150
151 /* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */
152 #define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
153
154
155
156 /***************************************************************************/
157 /* STAT DATA */
158 /***************************************************************************/
159
160
161 #ifndef __GCC__
162 #pragma pack(push, 1)
163 #endif
164
165 //
166 // old stat data is 32 bytes long. We are going to distinguish new one by
167 // different size
168 //
169 struct stat_data_v1
170 {
171 __u16 sd_mode; /* file type, permissions */
172 __u16 sd_nlink; /* number of hard links */
173 __u16 sd_uid; /* owner */
174 __u16 sd_gid; /* group */
175 __u32 sd_size; /* file size (in bytes) */
176 __u32 sd_atime; /* time of last access */
177 __u32 sd_mtime; /* time file was last modified */
178 __u32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
179 union {
180 __u32 sd_rdev;
181 __u32 sd_blocks; /* number of blocks file uses */ //[mark]this is the one filled..
182 } __PACKED u;
183 __u32 sd_first_direct_byte; /* first byte of file which is stored
184 in a direct item: except that if it
185 equals 1 it is a symlink and if it
186 equals ~(__u32)0 there is no
187 direct item. The existence of this
188 field really grates on me. Let's
189 replace it with a macro based on
190 sd_size and our tail suppression
191 policy. Someday. -Hans */
192 } __PACKED;
193
194 #ifndef __GCC__
195 #pragma pack(pop)
196 #endif
197
198 /* inode flags stored in sd_attrs (nee sd_reserved) */
199
200 /* we want common flags to have the same values as in ext2,
201 so chattr(1) will work without problems */
202 #define REISERFS_IMMUTABLE_FL EXT2_IMMUTABLE_FL
203 #define REISERFS_APPEND_FL EXT2_APPEND_FL
204 #define REISERFS_SYNC_FL EXT2_SYNC_FL
205 #define REISERFS_NOATIME_FL EXT2_NOATIME_FL
206 #define REISERFS_NODUMP_FL EXT2_NODUMP_FL
207 #define REISERFS_SECRM_FL EXT2_SECRM_FL
208 #define REISERFS_UNRM_FL EXT2_UNRM_FL
209 #define REISERFS_COMPR_FL EXT2_COMPR_FL
210 #define REISERFS_NOTAIL_FL EXT2_NOTAIL_FL
211
212 /* persistent flags that file inherits from the parent directory */
213 #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \
214 REISERFS_SYNC_FL | \
215 REISERFS_NOATIME_FL | \
216 REISERFS_NODUMP_FL | \
217 REISERFS_SECRM_FL | \
218 REISERFS_COMPR_FL | \
219 REISERFS_NOTAIL_FL )
220
221
222 #ifndef __GCC__
223 #pragma pack(push, 1)
224 #endif
225
226 /* Stat Data on disk (reiserfs version of UFS disk inode minus the
227 address blocks) */
228 struct stat_data {
229 __u16 i_mode; /* file type, permissions */ // The low 9 bits (3 octals) contain world/group/user permissions. The next 3 bits (from lower to higher) are the sticky bit, the set GID bit, and the set UID bit. The high 4 bits are the file type (as defined in stat.h: socket, symlink, regular, block dev, directory, char device, fifo)
230 __u16 sd_attrs; /* persistent inode flags */
231 __u32 i_links_count; /* number of hard links */ //[mark] was sd_nlink
232 __u64 i_size; /* file size */
233 __u32 i_uid; /* owner */
234 __u32 i_gid; /* group */
235 __u32 i_atime; /* time of last access */
236 __u32 i_mtime; /* time file was last modified */
237 __u32 i_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
238 __u32 sd_blocks;
239 union {
240 __u32 sd_rdev;
241 __u32 i_generation;
242 //__u32 sd_first_direct_byte;
243 /* first byte of file which is stored in a
244 direct item: except that if it equals 1
245 it is a symlink and if it equals
246 ~(__u32)0 there is no direct item. The
247 existence of this field really grates
248 on me. Let's replace it with a macro
249 based on sd_size and our tail
250 suppression policy? */
251 } __PACKED u;
252 } __PACKED;
253
254 #ifndef __GCC__
255 #pragma pack(pop)
256 #endif
257
258 //
259 // this is 44 bytes long
260 //
261 #define SD_SIZE (sizeof(struct stat_data))
262 #define SD_V2_SIZE SD_SIZE
263
264
265
266
267 /*
268 * values for s_umount_state field
269 */
270 #define REISERFS_VALID_FS 1
271 #define REISERFS_ERROR_FS 2
272
273 //
274 // there are 5 item types currently
275 //
276
277 #define RFSD_KEY_TYPE_v1_STAT_DATA 0
278 #define RFSD_KEY_TYPE_v1_INDIRECT 0xFFFFFFFe
279 #define RFSD_KEY_TYPE_v1_DIRECT 0xFFFFFFFF
280 #define RFSD_KEY_TYPE_v1_DIRENTRY 500
281
282 #define RFSD_KEY_TYPE_v2_STAT_DATA 0
283 #define RFSD_KEY_TYPE_v2_INDIRECT 1
284 #define RFSD_KEY_TYPE_v2_DIRECT 2
285 #define RFSD_KEY_TYPE_v2_DIRENTRY 3
286
287
288
289
290
291 /***************************************************************************/
292 /* KEY & ITEM HEAD */
293 /***************************************************************************/
294
295 typedef struct reiserfs_cpu_key
296 {
297 __u32 k_dir_id;
298 __u32 k_objectid;
299 __u64 k_offset;
300 __u32 k_type;
301 } no_c4091;
302
303 //
304 // directories use this key as well as old files
305 //
306
307 #ifndef __GCC__
308 #pragma pack(push, 1)
309 #endif
310
311 struct offset_v1 {
312 __u32 k_offset;
313 __u32 k_uniqueness;
314 } __PACKED;
315
316 #ifndef __GCC__
317 #pragma pack(pop)
318 #endif
319
320
321 #ifndef __GCC__
322 #pragma pack(push, 1)
323 #endif
324
325 struct offset_v2 {
326 #ifdef __LITTLE_ENDIAN
327 /* little endian version */
328 __u64 k_offset:60;
329 __u64 k_type: 4;
330 #else
331 /* big endian version */
332 __u64 k_type: 4;
333 __u64 k_offset:60;
334 #endif
335 } __PACKED;
336
337 #ifndef __GCC__
338 #pragma pack(pop)
339 #endif
340
341
342 // ...
343
344 #ifndef __GCC__
345 #pragma pack(push, 1)
346 #endif
347
348 /* Key of an item determines its location in the S+tree, and
349 is composed of 4 components */
350 struct reiserfs_key {
351 __u32 k_dir_id; /* packing locality: by default parent directory object id */
352 __u32 k_objectid; /* object identifier */
353 union {
354 struct offset_v1 k_offset_v1;
355 struct offset_v2 k_offset_v2;
356 } u;
357 } __PACKED;
358
359 #ifndef __GCC__
360 #pragma pack(pop)
361 #endif
362
363
364 /// ...
365
366 #ifndef __GCC__
367 #pragma pack(push, 1)
368 #endif
369
370 /* Everything in the filesystem is stored as a set of items. The
371 item head contains the key of the item, its free space (for
372 indirect items) and specifies the location of the item itself
373 within the block. */
374 struct item_head
375 {
376 /* Everything in the tree is found by searching for it based on
377 * its key.*/
378 struct reiserfs_key ih_key;
379 union {
380 /* The free space in the last unformatted node of an
381 indirect item if this is an indirect item. This
382 equals 0xFFFF iff this is a direct item or stat data
383 item. Note that the key, not this field, is used to
384 determine the item type, and thus which field this
385 union contains. */
386 __u16 ih_free_space_reserved;
387 /* Iff this is a directory item, this field equals the
388 number of directory entries in the directory item. */
389 __u16 ih_entry_count;
390 } u;
391 __u16 ih_item_len; /* total size of the item body */
392 __u16 ih_item_location; /* an offset to the item body within the block */
393 __u16 ih_version; /* 0 for all old items, 2 for new
394 ones. Highest bit is set by fsck
395 temporary, cleaned after all
396 done */
397 } __PACKED;
398
399 #ifndef __GCC__
400 #pragma pack(pop)
401 #endif
402
403 /// ...
404
405 /* object identifier for root dir */
406 #define REISERFS_ROOT_OBJECTID 2
407 #define REISERFS_ROOT_PARENT_OBJECTID 1
408
409 /// ...
410
411
412 /*
413 * Picture represents a leaf of the S+tree
414 * ______________________________________________________
415 * | | Array of | | |
416 * |Block | Object-Item | F r e e | Objects- |
417 * | head | Headers | S p a c e | Items |
418 * |______|_______________|___________________|___________|
419 */
420
421 /* Header of a disk block. More precisely, header of a formatted leaf
422 or internal node, and not the header of an unformatted node. */
423
424 #ifndef __GCC__
425 #pragma pack(push, 1)
426 #endif
427
428 struct block_head {
429 __u16 blk_level; /* Level of a block in the tree. */
430 __u16 blk_nr_item; /* Number of keys/items in a block. */
431 __u16 blk_free_space; /* Block free space in bytes. */
432 __u16 blk_reserved;
433 /* dump this in v4/planA */
434 struct reiserfs_key blk_right_delim_key; /* kept only for compatibility */
435 };
436
437 #ifndef __GCC__
438 #pragma pack(pop)
439 #endif
440
441
442
443
444
445
446
447 /***************************************************************************/
448 /* DIRECTORY STRUCTURE */
449 /***************************************************************************/
450 /*
451 Picture represents the structure of directory items
452 ________________________________________________
453 | Array of | | | | | |
454 | directory |N-1| N-2 | .... | 1st |0th|
455 | entry headers | | | | | |
456 |_______________|___|_____|________|_______|___|
457 <---- directory entries ------>
458
459 First directory item has k_offset component 1. We store "." and ".."
460 in one item, always, we never split "." and ".." into differing
461 items. This makes, among other things, the code for removing
462 directories simpler. */
463
464 // ...
465
466 /*
467 Q: How to get key of object pointed to by entry from entry?
468
469 A: Each directory entry has its header. This header has deh_dir_id and deh_objectid fields, those are key
470 of object, entry points to */
471
472 /* NOT IMPLEMENTED:
473 Directory will someday contain stat data of object */
474
475
476 #ifndef __GCC__
477 #pragma pack(push, 1)
478 #endif
479
480 struct reiserfs_de_head
481 {
482 __u32 deh_offset; /* third component of the directory entry key */
483 __u32 deh_dir_id; /* objectid of the parent directory of the object, that is referenced by directory entry */
484 __u32 deh_objectid; /* objectid of the object, that is referenced by directory entry */
485 __u16 deh_location; /* offset of name in the whole item */
486 __u16 deh_state; /* whether 1) entry contains stat data (for future), and 2) whether
487 entry is hidden (unlinked) */
488 } __PACKED;
489
490 #ifndef __GCC__
491 #pragma pack(pop)
492 #endif
493
494
495
496
497
498
499 /*
500 * Picture represents an internal node of the reiserfs tree
501 * ______________________________________________________
502 * | | Array of | Array of | Free |
503 * |block | keys | pointers | space |
504 * | head | N | N+1 | |
505 * |______|_______________|___________________|___________|
506 */
507
508 /***************************************************************************/
509 /* DISK CHILD */
510 /***************************************************************************/
511 /* Disk child pointer: The pointer from an internal node of the tree
512 to a node that is on disk. */
513
514 #ifndef __GCC__
515 #pragma pack(push, 1)
516 #endif
517
518 struct disk_child {
519 __u32 dc_block_number; /* Disk child's block number. */
520 __u16 dc_size; /* Disk child's used space. */
521 __u16 dc_reserved;
522 };
523
524 #ifndef __GCC__
525 #pragma pack(pop)
526 #endif
527
528
529
530
531 #endif // header