28 Jul 09:18
File index leaf format
Daniel Phillips <phillips <at> phunq.net>
2008-07-28 07:18:57 GMT
2008-07-28 07:18:57 GMT
In an earlier post I was seen fretting about how to reduce the
relatively expensive linear search in a PHTree directory file dirent
block to O(log(dirents)), while keeping the compactness and physical
stability of the good old Ext dirent format. It did not take too long
to find one.
struct tux3_dirent { unsigned inum:48, type:8, len:8; char name[]; };
Versus an Ext2 dirent, the two byte record size is gone and the inum
is increased from 32 bits to 48. The fields are big-endian and the
structure is byte-aligned, and therefore needs to be declared with
attribute packed so that gcc will generate code that does not throw
exceptions on alignment-challenged architectures when trying to pick up
the 48 bit inum field.
A simple directory grows down from the top of the dirent block towards
the dirents:
be_16 entries[];
Each big endian 16 bit entry is the offset of a dirent from the base of
the block. The entries are in lexically sorted order to support
binsearch. To maintain physical stability for telldir cookies, an
entry is never moved once created. Too bad about directory compaction,
that is an offline operation.
To search for space within the dirent we make a copy of the directory
and sort it. In the base of the directory we record the size of the
biggest contiguous free space in the dirent block in order to avoid
most fruitless searches and the associated sort. There is also a
(Continue reading)
RSS Feed