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