为了管理磁盘空间,文件系统需要知道哪些block是空闲的。Omfs使用bitmap来达到这个目的。Bitmap的每一个bit对应磁盘上的一个block,当对应的block被分配后,bitmap中的相应bit会被设置为1。这个是很经典也很清晰的一个设计,下面我们看看omfs的具体做法:
在上面新建的文件系统中新建一个文件aaaa:
Touch aaaa
ls -ali
total 4
3 drwxr-xr-x 2 root root 2048 2012-02-08 10:52 .
1048578 drwxr-xr-x 4 root root 4096 2012-02-08 13:44 ..
6 -rw-r--r-- 1 root root 0 2012-02-08 13:45 aaaa
再touch bbbb和touch cccc
3 drwxr-xr-x 2 root root 2048 2012-02-08 10:52 .
1048578 drwxr-xr-x 4 root root 4096 2012-02-08 13:44 ..
6 -rw-r--r-- 1 root root 0 2012-02-08 13:45 aaaa
8 -rw-r--r-- 1 root root 0 2012-02-08 13:54 bbbb
10 -rw-r--r-- 1 root root 0 2012-02-08 13:54 cccc
hexdump -C -s 0xa000 -n 8192 /dev/loop0
0000a000 ff 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0000a010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
0000a050 00 00 00 00 11 00 00 00 ff ff ff ff ff ff ff ff |................|
0000a060 ff ff 00 00 c9 0c 02 00 00 00 00 00 00 00 00 00 |................|
0000a070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
0000a190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 |................|
0000a1a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0000a1b0 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff |................|
0000a1c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
0000a800 00 00 00 00 29 05 02 00 00 00 00 00 00 00 00 00 |....)...........|
0000a810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
最初是3f 现在是ff0f 。
3f =0011 1111 这六位表示block 0到block 5 block0是super block,block1和block2是root block,block3 和block4是root directory inode, block5是bitmap
因为aaaa的i_no是6,所以占用block6,block7是备份。
Bbbb的i_no是8,所以占用block8,block9是备份。
Cccc的i_no是10,所以占用block10,block11是备份。
所以是ff0f = 1111 1111 0000 1111 block0至block11都是占用的