1 #ifndef __RFSD_REISER_FS_H__
2 #define __RFSD_REISER_FS_H__
4 #include <linux/types.h>
7 #define __PACKED __PACKED
12 /***************************************************************************/
14 /***************************************************************************/
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.
20 #define UNSET_HASH 0 // read_super will guess about, what hash names
21 // in directories were sorted with
25 #define DEFAULT_HASH R5_HASH
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 */
32 // Journal device number (?? for if the journal is on a seperate drive ??)
33 __u32 jp_journal_dev
; /* journal device st_rdev */
35 // Original journal size. (Needed when using partition on systems w/ different default journal sizes).
36 __u32 jp_journal_size
; /* size of the journal */
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 */
45 /* this is the super from 3.5.X, where X >= 10 */
50 struct reiserfs_super_block_v1
52 // The number of blocks in the partition
53 __u32 s_blocks_count
; /* blocks count */ //[mark] was _s_blocks_count
55 // The number of free blocks in the partition
56 __u32 s_free_blocks_count
; /* free blocks count */ //[mark] was _s_free_blocks
58 // Block number of the block containing the root node
59 __u32 s_root_block
; /* root block number */
62 struct journal_params s_journal
;
64 // The size (in bytes) of a block
65 __u16 s_blocksize
; /* block size */
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" */
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 */
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 */
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 */
95 #define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
97 /* this is the on disk super block */
102 struct reiserfs_super_block
104 struct reiserfs_super_block_v1 s_v1
;
106 // Number of the current inode generation (a counter that is increased every time the tree gets re-balanced).
107 __u32 s_inode_generation
;
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
122 #define SB_SIZE (sizeof(struct reiserfs_super_block))
124 #define REISERFS_VERSION_1 0
125 #define REISERFS_VERSION_2 2
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"
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
147 /* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */
148 #define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
152 /***************************************************************************/
154 /***************************************************************************/
158 #pragma pack(push, 1)
162 // old stat data is 32 bytes long. We are going to distinguish new one by
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) */
177 __u32 sd_blocks
; /* number of blocks file uses */ //[mark]this is the one filled..
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 */
194 /* inode flags stored in sd_attrs (nee sd_reserved) */
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
208 /* persistent flags that file inherits from the parent directory */
209 #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \
211 REISERFS_NOATIME_FL | \
212 REISERFS_NODUMP_FL | \
213 REISERFS_SECRM_FL | \
214 REISERFS_COMPR_FL | \
219 #pragma pack(push, 1)
222 /* Stat Data on disk (reiserfs version of UFS disk inode minus the
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) */
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? */
255 // this is 44 bytes long
257 #define SD_SIZE (sizeof(struct stat_data))
258 #define SD_V2_SIZE SD_SIZE
264 * values for s_umount_state field
266 #define REISERFS_VALID_FS 1
267 #define REISERFS_ERROR_FS 2
270 // there are 5 item types currently
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
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
287 /***************************************************************************/
288 /* KEY & ITEM HEAD */
289 /***************************************************************************/
291 typedef struct reiserfs_cpu_key
300 // directories use this key as well as old files
304 #pragma pack(push, 1)
318 #pragma pack(push, 1)
322 #ifdef __LITTLE_ENDIAN
323 /* little endian version */
327 /* big endian version */
341 #pragma pack(push, 1)
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 */
350 struct offset_v1 k_offset_v1
;
351 struct offset_v2 k_offset_v2
;
363 #pragma pack(push, 1)
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
372 /* Everything in the tree is found by searching for it based on
374 struct reiserfs_key ih_key
;
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
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
;
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
401 /* object identifier for root dir */
402 #define REISERFS_ROOT_OBJECTID 2
403 #define REISERFS_ROOT_PARENT_OBJECTID 1
409 * Picture represents a leaf of the S+tree
410 * ______________________________________________________
412 * |Block | Object-Item | F r e e | Objects- |
413 * | head | Headers | S p a c e | Items |
414 * |______|_______________|___________________|___________|
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. */
421 #pragma pack(push, 1)
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. */
429 /* dump this in v4/planA */
430 struct reiserfs_key blk_right_delim_key
; /* kept only for compatibility */
443 /***************************************************************************/
444 /* DIRECTORY STRUCTURE */
445 /***************************************************************************/
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 ------>
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. */
463 Q: How to get key of object pointed to by entry from entry?
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 */
469 Directory will someday contain stat data of object */
473 #pragma pack(push, 1)
476 struct reiserfs_de_head
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) */
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 * |______|_______________|___________________|___________|
504 /***************************************************************************/
506 /***************************************************************************/
507 /* Disk child pointer: The pointer from an internal node of the tree
508 to a node that is on disk. */
511 #pragma pack(push, 1)
515 __u32 dc_block_number
; /* Disk child's block number. */
516 __u16 dc_size
; /* Disk child's used space. */