如何恢复Linux上删除的文件 (6)

http://tech.ddvip.com   2008年04月15日    社区交流

内容摘要:reiserfs 对于小文件的存取速度非常高,这取决于它所采用的精美的设计:reiserfs 文件系统就是一棵动态的 B+ 树,小文件和大文件的尾部数据都可以通过保存到叶子节点中而加快存取速度。本文将探讨 reiserfs 的设计和实现内幕,并从中探讨恢复删除文件的可能性。

  为了解决上面提到的问题,reiserfs 为每个文件系统采用一棵经过专门优化的 B+ 树来组织所有的文件数据,并实现了很多新特性,例如元数据日志。为了提高文件系统的利用率,reiserfs 中采用了所谓的尾部封装(tail packing)设计,可以充分利用已分配磁盘块中的剩余空间来存储小文件。实际上,reiserfs 文件系统中存储的文件会比 ext2/ext3 大 5% - 6% 以上。下面让我们来探索一下 reiserfs 文件系统中数据在磁盘上究竟是如何存储的。

  磁盘布局

  与 ext2/ext3 类似,reiserfs 文件系统在创建时,也会将磁盘空间划分成固定大小的数据块。数据块从 0 开始编号,最多可以有 232 个数据块。因此如果采用默认的 4KB 大小的数据块,单个 reiserfs 文件系统的上限是 16TB。reiserfs 分区的前 64KB 保留给引导扇区、磁盘标签等使用。超级块(super block)从 64KB 开始,会占用一个数据块;之后是一个数据块位图,用来标识对应的数据块是否处于空闲状态。如果一个数据块位图可以标识 n 个数据块,那么 reiserfs 分区中的第 n 个数据块也都是这样一个数据块,用来标识此后(包括自己)n 的数据块的状态。reiserfs 文件系统的磁盘结构如图 1 所示。

  图 1. reiserfs 分区磁盘布局

如何恢复Linux上删除的文件 (6)

  与 ext2/ext3 类似,reiserfs 文件系统的一些关键信息也保存超级块中。reiserfs 的超级块使用一个 reiserfs_super_block 结构来表示,其定义如清单1 所示:

  清单1. reiserfs_super_block 结构定义

135 struct reiserfs_super_block_v1 {
136     __le32 s_block_count;  /* blocks count     */
137     __le32 s_free_blocks;  /* free blocks count  */
138     __le32 s_root_block;  /* root block number  */
139     struct journal_params s_journal;
140     __le16 s_blocksize;   /* block size */
141     __le16 s_oid_maxsize;  /* max size of object id array, see
142                 * get_objectid() commentary */
143     __le16 s_oid_cursize;  /* current size of object id array */
144     __le16 s_umount_state; /* this is set to 1 when filesystem was
145                 * umounted, to 2 - when not */
146     char s_magic[10];    /* reiserfs magic string indicates that
147                 * file system is reiserfs:
148                 * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */
149     __le16 s_fs_state;   /* it is set to used by fsck to mark which
150                 * phase of rebuilding is done */
151     __le32 s_hash_function_code;  /* indicate, what hash function is being use
152                     * to sort names in a directory*/
153     __le16 s_tree_height;  /* height of disk tree */
154     __le16 s_bmap_nr;    /* amount of bitmap blocks needed to address
155                 * each block of file system */
156     __le16 s_version;    /* this field is only reliable on filesystem
157                 * with non-standard journal */
158     __le16 s_reserved_for_journal; /* size in blocks of journal area on main
159                     * device, we need to keep after
160                     * making fs with non-standard journal */
161 } __attribute__ ((__packed__));
162
163 #define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
164
165 /* this is the on disk super block */
166 struct reiserfs_super_block {
167     struct reiserfs_super_block_v1 s_v1;
168     __le32 s_inode_generation;
169     __le32 s_flags;   /* Right now used only by inode-attributes, if enabled */
170     unsigned char s_uuid[16];    /* filesystem unique identifier */
171     unsigned char s_label[16];   /* filesystem volume label */
172     char s_unused[88];   /* zero filled by mkreiserfs and
173                 * reiserfs_convert_objectid_map_v1()
174                 * so any additions must be updated
175                 * there as well. */
176 } __attribute__ ((__packed__));

来源:ibm    作者:冯锐 丁成    责编:豆豆技术应用

正在加载评论...