系统块大小,block size并不被重视,因为一般很少会注视到,除非需要探究文件系统原理。df命令源码实现
涉及库函数如下:
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);
参数:
path: 位于需要查询信息的文件系统的文件路径名。
fd: 位于需要查询信息的文件系统的文件描述词。
buf:以下结构体的指针变量,用于储存文件系统相关的信息
struct statfs {
long f_type; /* 文件系统类型 */
long f_bsize; /* 经过优化的传输块大小 */
long f_blocks; /* 文件系统数据块总数 */
long f_bfree; /* 可用块数 */
long f_bavail; /* 非超级用户可获取的块数 */
long f_files; /* 文件结点总数 */
long f_ffree; /* 可用文件结点数 */
fsid_t f_fsid; /* 文件系统标识 */
long f_namelen; /* 文件名的最大长度 */
};
文件系统块(Block)
block即文件系统格式化后的分区的最小单位,其大小在格式化时被指定,一般为1KB,2KB,4KB。磁盘分区只有被文件系统格式化之后才能被操作系统使用。硬盘最小存储单位是sector即扇区,为了增加读写效率则有了逻辑区块( Block )这个概念,其为sector的2次方倍数。
注意:文件系统创建时系统块大小就已确定,一般创建文件系统之后就无法更改。
文件系统块大小查询
在linux系统上,可以用命令tune2fs 查询
[root@localhost test10g]# tune2fs -help
tune2fs 1.35 (28-Feb-2004)
tune2fs: invalid option -- h
Usage: tune2fs [-c max-mounts-count] [-e errors-behavior] [-g group]
[-i interval[d|m|w]] [-j] [-J journal-options]
[-l] [-s sparse-flag] [-m reserved-blocks-percent]
[-o [^]mount-options[,...]] [-r reserved-blocks-count]
[-u user] [-C mount-count] [-L volume-label] [-M last-mounted-dir]
[-O [^]feature[,...]] [-T last-check-time] [-U UUID] device
[root@localhost test10g]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 8776068 7576504 753764 91% /
/dev/sda1 497829 16303 455824 4% /boot
none 517300 0 517300 0% /dev/shm
/dev/sda5 1035660 96452 886600 10% /tmp
[root@localhost test10g]# tune2fs -l /dev/sda1|grep Block
Block count: 514048
Block size: 1024
Blocks per group: 8192
[root@localhost test10g]# tune2fs -l /dev/sda2|grep Block
Block count: 2229018
Block size: 4096
Blocks per group: 32768
上面Block size即为块大小。
在WINDOWS系统上,可以用命令fsutil来查看,测试如下:
C:/Documents and Settings/ct2>fsutil --help
--help 是无效参数。
---- 支持的命令 ----
behavior 控制文件系统行为
dirty 管理卷的被损坏的位数
file 文件特定命令
fsinfo 文件系统信息
hardlink 硬链接管理
objectid 对象 ID 管理
quota 配额管理