I am sure a directory file has much less information than 4096 bytes. I know the sector size is 4096 bytes. But normal files smaller than that do exist.
Why does Unix reserve 4096 bytes for each folder?
|
|
|
It's the initial size necessary to store the meta-data about files contained in that directory (including names). The initial allocation equals the size of one sector, but can grow above that if necessary. Once allocated, space is not freed if files are removed, to reduce fragmentation. For example:
|
|||||
|
|
Sometimes 4096 bytes is the smallest allocation unit for some filesystems. That's why directory has 4096. The same thing apply to files. Even though some files might report fewer than 4096, they are actually taking al least 4096 of storage from disk. |
|||||||||||||||||
|
|
4096 is reserved to reduce fragmentation, because often the actual size of the metadata contained will fluctuate based on the directory contents. If it is constantly growing and shrinking (say it contained log files or dynamic content) over time it could hurt performance. This likely wouldn't happen with one folder, but across the whole file system it would add up quickly. |
|||
|
|
|
It depends on filesystem. On ext2/3/4 it "is" 4096. On reiserfs it can be 9608 (my By default on ext2/3/4 block is 4096 - and file cannot take less than that. If file is smaller it takes a whole block anyway. As it is pointless to ask about logical size of directory and this information is probably not on disk anyway and it have to report something it reports a size of block times the number of blocks taken i.e. the physical space that have been taken. |
|||||||||
|