Max*_*cat 8 c filesystems file
我正在编写一些块级操作,我想确保我不会打击其他文件.在ext2/3/4文件系统中,多个文件可以存储在同一个块中吗?我的第一直觉是没有办法,但我想与社区核实.
这个问题很难回答.也许正确答案可能在理论上是肯定的,但在实践中没有.
说到ext2和ext3,超级块和inode结构被设计为允许块被分段.(见:fs/ext2/ext2.h
和fs/ext3/ext3.h
)
fs/ext3/ext3.h
这里给出的简短片段:
struct ext3_super_block {
/*00*/ __le32 s_inodes_count; /* Inodes count */
__le32 s_blocks_count; /* Blocks count */
__le32 s_r_blocks_count; /* Reserved blocks count */
__le32 s_free_blocks_count; /* Free blocks count */
/*10*/ __le32 s_free_inodes_count; /* Free inodes count */
__le32 s_first_data_block; /* First Data Block */
__le32 s_log_block_size; /* Block size */
__le32 s_log_frag_size; /* Fragment size */
// ...
struct ext3_inode {
__le16 i_mode; /* File mode */
__le16 i_uid; /* Low 16 bits of Owner Uid */
// ...
__le32 i_faddr; /* Fragment address */
Run Code Online (Sandbox Code Playgroud)
虽然准备好了,至少在linux内核(直到版本3.13)中,块碎片从未实现,因此强制碎片大小等于块大小.(见fs/ext3/super.c
)
if (blocksize != sbi->s_frag_size) {
ext3_msg(sb, KERN_ERR,
"error: fragsize %lu != blocksize %u (unsupported)",
sbi->s_frag_size, blocksize);
goto failed_mount;
}
Run Code Online (Sandbox Code Playgroud)
Afaik GNU/Hurd也没有实现ext2/3文件系统的块碎片.最有可能的是,没有操作系统可以实现它.
尽管如此,s_log_frag_size
在开始块级操作之前检查超级块可能不是一个坏主意,因为您将是安全的.
随着ext4,故事变得不那么麻烦了,因为ext4不再允许阻塞碎片.用于存储片段大小的超级块字段已被赋予新作业,并且用于存储片段地址(重命名为i_obso_faddr
)的iode字段已在源中标记为已过时.
struct ext4_inode {
__le16 i_mode; /* File mode */
__le16 i_uid; /* Low 16 bits of Owner Uid */
// ...
__le32 i_obso_faddr; /* Obsoleted fragment address */
Run Code Online (Sandbox Code Playgroud)