The current design:
Inspired by ext4, we added a nr_blk field to record the number of contiguous blocks within the file.
ββββ* __le32 inode; /* Inode number */
β* __le16 rec_len; /* Directory entry length */
β* __u8 name_len; /* Name length */
β* __u8 file_type; /* See file type macros EXT4_FT_* below */
e.g.
lost+found:
-> empty space = 0x00 00 (len = 2)
empty len = 0x14 - 0x04(inode) - 0x02(rec_len) - 0x01(name_len) - 0x01(file_type) - 0x0a(file_name) = 0x02
test1:
-> empty space = 0x00 00 00 (len = 3)
empty len = 0x10 - 0x04(inode) - 0x02(rec_len) - 0x01(name_len) - 0x01(file_type) - 0x05(file_name) = 0x03
When removing a file or directory in Ext4, the filesystem merges the freed space with the previous to reduce fragmentation. This way, the space left behind can be efficiently reused.
Later, when a new file or directory is created, Ext4 scans the directory entries from the beginning β a first-fit strategy β to find available space. If it encounters a free segment that is larger than the requested size, Ext4 will sperate from this segment.
Remove 30600 files:
create file
list all files
Non-linear file removal, including recreating the same number of files