📄 reiserfs_private.h
字号:
/* * Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README * * GRUB -- GRand Unified Bootloader * Copyright (C) 2000, 2001 Free Software Foundation, Inc. * * (C) Copyright 2003 - 2004 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* An implementation for the ReiserFS filesystem ported from GRUB. * Some parts of this code (mainly the structures and defines) are * from the original reiser fs code, as found in the linux kernel. */#ifndef __BYTE_ORDER#if defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)#define __BYTE_ORDER __LITTLE_ENDIAN#elif defined(__BIG_ENDIAN) && !defined(__LITTLE_ENDIAN)#define __BYTE_ORDER __BIG_ENDIAN#else#error "unable to define __BYTE_ORDER"#endif#endif /* not __BYTE_ORDER */#define FSYS_BUFLEN 0x8000#define FSYS_BUF fsys_buf/* This is the new super block of a journaling reiserfs system */struct reiserfs_super_block{ __u32 s_block_count; /* blocks count */ __u32 s_free_blocks; /* free blocks count */ __u32 s_root_block; /* root block number */ __u32 s_journal_block; /* journal block number */ __u32 s_journal_dev; /* journal device number */ __u32 s_journal_size; /* size of the journal on FS creation. used to make sure they don't overflow it */ __u32 s_journal_trans_max; /* max number of blocks in a transaction. */ __u32 s_journal_magic; /* random value made on fs creation */ __u32 s_journal_max_batch; /* max number of blocks to batch into a trans */ __u32 s_journal_max_commit_age; /* in seconds, how old can an async commit be */ __u32 s_journal_max_trans_age; /* in seconds, how old can a transaction be */ __u16 s_blocksize; /* block size */ __u16 s_oid_maxsize; /* max size of object id array */ __u16 s_oid_cursize; /* current size of object id array */ __u16 s_state; /* valid or error */ char s_magic[16]; /* reiserfs magic string indicates that file system is reiserfs */ __u16 s_tree_height; /* height of disk tree */ __u16 s_bmap_nr; /* amount of bitmap blocks needed to address each block of file system */ __u16 s_version; char s_unused[128]; /* zero filled by mkreiserfs */};#define sb_root_block(sbp) (__le32_to_cpu((sbp)->s_root_block))#define sb_journal_block(sbp) (__le32_to_cpu((sbp)->s_journal_block))#define set_sb_journal_block(sbp,v) ((sbp)->s_journal_block = __cpu_to_le32(v))#define sb_journal_size(sbp) (__le32_to_cpu((sbp)->s_journal_size))#define sb_blocksize(sbp) (__le16_to_cpu((sbp)->s_blocksize))#define set_sb_blocksize(sbp,v) ((sbp)->s_blocksize = __cpu_to_le16(v))#define sb_version(sbp) (__le16_to_cpu((sbp)->s_version))#define set_sb_version(sbp,v) ((sbp)->s_version = __cpu_to_le16(v))#define REISERFS_MAX_SUPPORTED_VERSION 2#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"#define REISER3FS_SUPER_MAGIC_STRING "ReIsEr3Fs"#define MAX_HEIGHT 7/* must be correct to keep the desc and commit structs at 4k */#define JOURNAL_TRANS_HALF 1018/* first block written in a commit. */struct reiserfs_journal_desc { __u32 j_trans_id; /* id of commit */ __u32 j_len; /* length of commit. len +1 is the commit block */ __u32 j_mount_id; /* mount id of this trans*/ __u32 j_realblock[JOURNAL_TRANS_HALF]; /* real locations for the first blocks */ char j_magic[12];};/* last block written in a commit */struct reiserfs_journal_commit { __u32 j_trans_id; /* must match j_trans_id from the desc block */ __u32 j_len; /* ditto */ __u32 j_realblock[JOURNAL_TRANS_HALF]; /* real locations for the last blocks */ char j_digest[16]; /* md5 sum of all the blocks involved, including desc and commit. not used, kill it */};/* this header block gets written whenever a transaction is considered fully flushed, and is more recent than the last fully flushed transaction. fully flushed means all the log blocks and all the real blocks are on disk, and this transaction does not need to be replayed.*/struct reiserfs_journal_header { /* id of last fully flushed transaction */ __u32 j_last_flush_trans_id; /* offset in the log of where to start replay after a crash */ __u32 j_first_unflushed_offset; /* mount id to detect very old transactions */ __u32 j_mount_id;};/* magic string to find desc blocks in the journal */#define JOURNAL_DESC_MAGIC "ReIsErLB"/* * directories use this key as well as old files */struct offset_v1{ /* * for regular files this is the offset to the first byte of the * body, contained in the object-item, as measured from the start of * the entire body of the object. * * for directory entries, k_offset consists of hash derived from * hashing the name and using few bits (23 or more) of the resulting * hash, and generation number that allows distinguishing names with * hash collisions. If number of collisions overflows generation * number, we return EEXIST. High order bit is 0 always */ __u32 k_offset; __u32 k_uniqueness;};struct offset_v2 { /* * for regular files this is the offset to the first byte of the * body, contained in the object-item, as measured from the start of * the entire body of the object. * * for directory entries, k_offset consists of hash derived from * hashing the name and using few bits (23 or more) of the resulting * hash, and generation number that allows distinguishing names with * hash collisions. If number of collisions overflows generation * number, we return EEXIST. High order bit is 0 always */#if defined(__LITTLE_ENDIAN_BITFIELD) /* little endian version */ __u64 k_offset:60; __u64 k_type: 4;#elif defined(__BIG_ENDIAN_BITFIELD) /* big endian version */ __u64 k_type: 4; __u64 k_offset:60;#else#error "__LITTLE_ENDIAN_BITFIELD or __BIG_ENDIAN_BITFIELD must be defined"#endif} __attribute__ ((__packed__));#define TYPE_MAXTYPE 3#define TYPE_ANY 15#if (__BYTE_ORDER == __BIG_ENDIAN)typedef union { struct offset_v2 offset_v2; __u64 linear;} __attribute__ ((__packed__)) offset_v2_esafe_overlay;static inline __u16 offset_v2_k_type( const struct offset_v2 *v2 ){ offset_v2_esafe_overlay tmp = *(const offset_v2_esafe_overlay *)v2; tmp.linear = __le64_to_cpu( tmp.linear ); return (tmp.offset_v2.k_type <= TYPE_MAXTYPE)?tmp.offset_v2.k_type:TYPE_ANY;}static inline loff_t offset_v2_k_offset( const struct offset_v2 *v2 ){ offset_v2_esafe_overlay tmp = *(const offset_v2_esafe_overlay *)v2; tmp.linear = __le64_to_cpu( tmp.linear ); return tmp.offset_v2.k_offset;}#elif (__BYTE_ORDER == __LITTLE_ENDIAN)# define offset_v2_k_type(v2) ((v2)->k_type)# define offset_v2_k_offset(v2) ((v2)->k_offset)#else#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN"#endifstruct key{ /* packing locality: by default parent directory object id */ __u32 k_dir_id; /* object identifier */ __u32 k_objectid; /* the offset and node type (old and new form) */ union { struct offset_v1 v1; struct offset_v2 v2; } u;};#define KEY_SIZE (sizeof (struct key))/* Header of a disk block. More precisely, header of a formatted leaf or internal node, and not the header of an unformatted node. */struct block_head{ __u16 blk_level; /* Level of a block in the tree. */ __u16 blk_nr_item; /* Number of keys/items in a block. */ __u16 blk_free_space; /* Block free space in bytes. */ struct key blk_right_delim_key; /* Right delimiting key for this block (supported for leaf level nodes only) */};#define BLKH_SIZE (sizeof (struct block_head))#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */struct item_head{ /* Everything in the tree is found by searching for it based on * its key.*/ struct key ih_key; union { /* The free space in the last unformatted node of an indirect item if this is an indirect item. This equals 0xFFFF iff this is a direct item or stat data item. Note that the key, not this field, is used to determine the item type, and thus which field this union contains. */ __u16 ih_free_space; /* Iff this is a directory item, this field equals the number of directory entries in the directory item. */ __u16 ih_entry_count; } __attribute__ ((__packed__)) u; __u16 ih_item_len; /* total size of the item body */ __u16 ih_item_location; /* an offset to the item body * within the block */ __u16 ih_version; /* 0 for all old items, 2 for new ones. Highest bit is set by fsck temporary, cleaned after all done */} __attribute__ ((__packed__));/* size of item header */#define IH_SIZE (sizeof (struct item_head))#define ITEM_VERSION_1 0#define ITEM_VERSION_2 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -