Linux文件系統

常見的硬盤如上圖所示,每個盤片分多個磁道,每個磁道分多個扇區,每個扇區512字節,是硬盤的最小存儲單元,但是在操作系統層面會將多個扇區組成塊(block),是操作系統存儲數據的最小單元,通常是8個扇區組成4K字節的塊。
對于Linux文件系統,需要考慮以下幾點:
Linux里面一切皆文件,都有以下幾種文件(從ls -l結果的第一位標識位可以看出來):
- 表示普通文件 d 表示文件夾 c 表示字符設備文件 b 表示塊設備文件 s 表示套接字socket文件 l 表示軟鏈接Inode和塊存儲
下面就以EXT系列格式為例來看一下文件是如果存在硬盤上的。首先文件會被分成一個個的塊,分散得存在硬盤上,就需要一個索引結構來幫助我們找到這些塊以及記錄文件的一些元信息,這就是inode,其中i代表index。inode數據結構如下:
struct ext4_inode { __le16 i_mode;  /* File mode */ __le16 i_uid;  /* Low 16 bits of Owner Uid */ __le32 i_size_lo; /* Size in bytes */ __le32 i_atime; /* Access time */ __le32 i_ctime; /* Inode Change time */ __le32 i_mtime; /* Modification time */ __le32 i_dtime; /* Deletion Time */ __le16 i_gid;  /* Low 16 bits of Group Id */ __le16 i_links_count; /* Links count */ __le32 i_blocks_lo; /* Blocks count */ __le32 i_flags; /* File flags */ union {  struct {   __le32 l_i_version;  } linux1;  struct {   __u32 h_i_translator;  } hurd1;  struct {   __u32 m_i_reserved1;  } masix1; } osd1;    /* OS dependent 1 */ __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */ __le32 i_generation; /* File version (for NFS) */ __le32 i_file_acl_lo; /* File ACL */ __le32 i_size_high; __le32 i_obso_faddr; /* Obsoleted fragment address */ union {  struct {   __le16 l_i_blocks_high; /* were l_i_reserved1 */   __le16 l_i_file_acl_high;   __le16 l_i_uid_high; /* these 2 fields */   __le16 l_i_gid_high; /* were reserved2[0] */   __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */   __le16 l_i_reserved;  } linux2;  struct {   __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */   __u16 h_i_mode_high;   __u16 h_i_uid_high;   __u16 h_i_gid_high;   __u32 h_i_author;  } hurd2;  struct {   __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */   __le16 m_i_file_acl_high;   __u32 m_i_reserved2[2];  } masix2; } osd2;    /* OS dependent 2 */ __le16 i_extra_isize; __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */ __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ __le32 i_crtime; /* File Creation time */ __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ __le32 i_version_hi; /* high 32 bits for 64-bit version */ __le32 i_projid; /* Project ID */};
新聞熱點
疑難解答