以32GB的EXT4文件系统为例进行计算。
驱动信息
usb 1-1.3: new full-speed USB device number 4 using ci_hdrc
scsi 0:0:0:0: Direct-Access Generic STORAGE DEVICE 0819 PQ: 0 ANSI: 6
sd 0:0:0:0: [sda] 62566400 512-byte logical blocks: (32.0 GB/29.8 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk
fdisk查看信息
Disk /dev/sda: 32.0 GB, 32033996800 bytes
64 heads, 32 sectors/track, 30550 cylinders, total 62566400 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 2048 62566399 31282176 83 Linux
SD卡容量32GB,实际可存储容量为32033996800 bytes=31283200KB (62566400 * 512 = 29.833984375GB)
文件系统容量为31282176 KB,start 2048前面存储的是分区信息,占用2048*512=1024KB
挂载
/dev/sda1 on /mnt/sda1 type ext4 (rw,relatime,data=ordered)
容量df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 30659500 45232 29033776 0% /mnt/sda1
容量单位是1k,所以就是数字后面加k;
容量大小为30659500 KB (纯文件数据块容量)
使用大小为45232 KB(实际文件数据块173K + 还有什么占用数据块?)
空闲大小为29033776 KB(剩余数据块,不包含预留的空间)
隐藏大小为30659500 - 29079008 =1580492 KB (就是文件系统预留空间)
dumpe2fs信息
数据块总容量:7820544 * 4K = 31282176
使用大小:667756K(文件系统信息数据 + 实际文件数据块大小)
空闲容量:7653605 * 4K = 30614420
预留容量:391027 * 4K = 1564108
root@www:~# /mnt/emmc/dumpe2fs /dev/sda1 -h
dumpe2fs 1.44.5 (15-Dec-2018)
Filesystem volume name: <none>
Last mounted on: /mnt/sda1
Filesystem UUID: d200bbcf-7fa9-40a7-b69a-8891ed917744
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize
Filesystem flags: unsigned_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 1957888
Block count: 7820544
Reserved block count: 391027
Free blocks: 7653605
Free inodes: 1957877
First block: 0
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Reserved GDT blocks: 1024
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Mon Jan 21 10:26:05 2019
Last mount time: Thu Jan 3 18:25:12 2019
Last write time: Thu Jan 3 18:25:12 2019
Mount count: 1
Maximum mount count: -1
Last checked: Mon Jan 21 10:26:05 2019
Check interval: 0 (<none>)
Lifetime writes: 612 MB
Reserved blocks uid: 0 (user unknown)
Reserved blocks gid: 0 (group unknown)
First inode: 11
Inode size: 256
Required extra isize: 32
Desired extra isize: 32
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 1a43adc3-ca82-4a24-bb2a-8195f1c7aabb
Journal backup: inode blocks
Journal features: journal_64bit
Journal size: 128M
Journal length: 32768
Journal sequence: 0x00000002
Journal start: 1
容量示意图
总结
df实时显示内存中的ext4文件系统数据块容量信息,空闲容量不包括预留容量,预留容量在容量用完后给超级用户使用的;dumpe2fs是读取磁盘上面的超级块信息,不能实时更新,应该是在卸载或挂载时更新容量数据。