Linux 文件系統(tǒng)之inode

老師推薦的書是《The Design of the UNIX Operating System》,有壓力,每天都覺得自己在欠技術債。

引用阮一峰寫的一篇日志,他將對inode的理解寫的通俗易懂,點個贊。

inode的內(nèi)容

[root@chances126 product]# stat hn_dcms.sql 
  File: "hn_dcms.sql"
  Size: 6375968     Blocks: 12456      IO Block: 4096   普通文件
Device: 808h/2056d   Inode: 9459975     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-01-29 14:27:19.618772319 +0800
Modify: 2016-01-29 14:26:34.897772357 +0800
Change: 2016-01-29 14:26:34.897772357 +0800

Blocks 占用數(shù)目的單位 是什么? Block 還是 sector?

block size 512,分配時4個block 一起分配 一個整數(shù)
12456/4=3114

[root@chances126 product]# fdisk -lu /dev/sda8
Disk /dev/sda8: 221.0 GB, 220971663360 bytes
255 heads, 63 sectors/track, 26864 cylinders, total 431585280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

每個sector為512,IO block 為4096

[root@chances126 product]# stat hn_dcms.sql 
  File: "hn_dcms.sql"
  Size: 6375968     Blocks: 12456      IO Block: 4096   普通文件
Device: 808h/2056d   Inode: 9459975     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-01-29 14:27:19.618772319 +0800
Modify: 2016-01-29 14:26:34.897772357 +0800
Change: 2016-01-29 14:26:34.897772357 +0800

獲取文件對應的inode信息
File sizes/ Sector = 共需多少個Sector
6375968 / 512 = 12453.0625 = 12454
8個sector 為一個block ,因此所需Block為=12454/8=1556.75
雖有偏差,但能大致能對應上,但有個問題:
計算出的 Sector是 12454,查詢出的Blocks: 12456 ,還有2個Sector 也就是1024字節(jié) 是什么呢?

[root@chances126 product]# debugfs /dev/sda8
debugfs:  stat hn_dcms.sql 
Inode: 9459975   Type: regular    Mode:  0644   Flags: 0x80000
Generation: 2744091751    Version: 0x00000000:00000001
User:     0   Group:     0   Size: 6375968
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 12456
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x56ab061a:d60bad14 -- Fri Jan 29 14:26:34 2016
 atime: 0x56ab0647:9386dd7c -- Fri Jan 29 14:27:19 2016
 mtime: 0x56ab061a:d60bad14 -- Fri Jan 29 14:26:34 2016
crtime: 0x56ab061a:05e7fc20 -- Fri Jan 29 14:26:34 2016
Size of extra inode fields: 28
EXTENTS:
(0-1556): 38119424-38120980

(0-1556): 38119424-38120980 為文件數(shù)據(jù)具體在磁盤上的位置
inode 大小

[root@chances126 product]# sudo dumpe2fs -h /dev/sda8 | grep "Inode size"
dumpe2fs 1.41.12 (17-May-2010)
Inode size:           256
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容