0.11 檔案系統的資料結構

來源:互聯網
上載者:User

在Linux中普通檔案和目錄檔案儲存在稱為塊物理裝置的磁碟或者磁帶上。一套Linux系統支援若干物理盤,每個物理盤可定義一個或者多個檔案系統。(類比於微機磁碟分割)。每個檔案系統由邏輯塊的序列組成,一個邏輯盤空間一般劃分為幾個用途各不相同的部分,即引導塊、超級塊、inode區以及資料區等。

檔案系統邏輯塊各部分分布圖:其中引導塊部分可以不包含代碼,但必須存在以保持格式的一致性。

超級快:

struct super_block {
 unsigned short s_ninodes;  //節點數
 unsigned short s_nzones;   //邏輯塊數
 unsigned short s_imap_blocks; //i節點位元影像所佔塊數
 unsigned short s_zmap_blocks; //邏輯塊位元影像所佔塊數
 unsigned short s_firstdatazone; //資料區第一個邏輯塊塊號
 unsigned short s_log_zone_size; //以2為底數,表示每個邏輯塊包含幾個磁碟塊
 unsigned long s_max_size; //最大檔案長度,受到磁碟容量的限制
 unsigned short s_magic;
/* These are only in memory */
 struct buffer_head * s_imap[8]; //i節點位元影像在高速緩衝塊指標數組
 struct buffer_head * s_zmap[8];//邏輯塊位元影像在高速緩衝塊指標數組
 unsigned short s_dev; //超級塊所在的裝置的號
 struct m_inode * s_isup; //被安裝檔案系統根節點號
 struct m_inode * s_imount; //該檔案系統被安裝的節點
 unsigned long s_time; //修改時間
 struct task_struct * s_wait; //等待該超級塊的指標
 unsigned char s_lock;
 unsigned char s_rd_only;
 unsigned char s_dirt;
};

邏輯塊位元影像用於表示盤上每個資料區塊的使用方式,除了第一個位元位(位0)以外,邏輯塊位元影像中的每一位對應盤上資料區的一個塊。因此邏輯塊位元影像中的第一位代表資料區的第一個資料區塊(而不是引導塊)。當資料區的一個塊被佔用後,則邏輯塊位元影像中相應的位被置位。邏輯塊位元影像的位0閑置不用,並且建立檔案系統時被置位。

邏輯塊位元影像最多使用8個快取塊s_zmap[8],每個緩衝塊大小是1024位元組,每位代表著被使用否,所以可以表示8192個磁碟塊,8個緩衝區可以代表65536個盤快。

i節點位元影像s_imap[8],表示i節點被使用否。i節點位元影像說明i節點是否被使用,同樣每個位元位代表一個i節點的使用方式,同s_zmap[8]的情況,每一個s_imap可以代表8192個i節點的使用方式,i節點位元影像的第一個位元組的最低位(位0)和對應的i節點零都閑置不用,在檔案系統建立是被置位。因此第一個節點位元影像只能代表8191個節點的使用方式。

 

struct m_inode {
 unsigned short i_mode; //檔案類型和屬性 (rwx位)
 unsigned short i_uid;
 unsigned long i_size;
 unsigned long i_mtime;
 unsigned char i_gid;
 unsigned char i_nlinks;
 unsigned short i_zone[9];//[0]-[6]直接索引塊號,[7]一次索引塊號,[8]二次索引塊號,對於裝置檔案的i節點號,zone[0]存放著裝置的裝置號
/* these are in memory also */
 struct task_struct * i_wait;
 unsigned long i_atime;
 unsigned long i_ctime;
 unsigned short i_dev;
 unsigned short i_num;
 unsigned short i_count;
 unsigned char i_lock;
 unsigned char i_dirt;
 unsigned char i_pipe;
 unsigned char i_mount;
 unsigned char i_seek;
 unsigned char i_update;
};
檔案中的資料是存放在磁碟塊中的資料區塊中的,而一個檔案名稱則通過對應的i節點號與這些資料磁碟塊相聯絡,這些盤塊的號碼則儲存在i_zone[]地區中。若檔案的長度小於7K則可以根據i_zone[0]~i_zone[6]直接索引快速找到對應的塊。若檔案長度大於7k則通過一次索引i_zone[7]進行索引,該域存放著附加塊號,對於0.11的檔案系統可以存放512個盤塊號。i_zone[8]進行二次索引,可以存放512*512個盤塊。

對於/dev/下的裝置檔案,他們並不佔用磁碟塊中的資料區,即檔案長度為零,檔案裝置的i節點僅儲存裝置的屬性和相應的裝置號,裝置號儲存在i節點的i_zone[0]中。

 

這裡有篇文章,寫的相當不錯:http://blog.csdn.net/zheng80037/archive/2007/05/24/1624624.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.