1

This is my stat output on a folder

stat Downloads/ File: `Downloads/' Size: 4096 Blocks: 8
IO Block: 4096 directory Device: fd02h/64770d Inode: 259595
Links: 3

What does it mean by the size of a directory ? I don't think it includes the directory contents. But if it is just a directory and a naming, why does it take up 4096 bytes ?

What is the difference between IO Block and Blocks ? What is actually inode ?

Regards, Noob

1 Answer 1

1

Drives are organized into clusters. Each cluster is some multiple of a hard drive sector (512 bytes). Initially, a directory is one cluster size big (e.g. 4,096 bytes). Even if there's just one file in the directory, the directory will show up as 4,096 bytes. Larger directories, containing many files, might be 8,192 bytes, 16,384 bytes, etc. Linux, like every other system out there, can only allocate in cluster sizes. This is an efficiency that allows smaller inode tables at the expense of some loss of usable space. For example, a text file with the letter "a" in it also takes up 4,096 bytes on the drive. An inode is basically an alias for a cluster.

7
  • is cluster the equivalent of an OS block ? you mentioned that larger directories containing many files might be 8192 bytes or larger etc - why ? i believe it is not reflecting the sizes of the files inside the directory; what is the 8192 bytes use to store for the directory ?
    – Noob
    Jun 23, 2015 at 3:00
  • Yes, clusters and blocks are synonymous. I grew up in the term cluster, from my Microsoft-based experiences, but Linux usually (exclusively?) refers to blocks in its utilities.
    – phyrfox
    Jun 23, 2015 at 3:05
  • can you elaborate further on why allocating in cluster size allow smaller inode ?
    – Noob
    Jun 23, 2015 at 4:16
  • The block size is a multiplier. Historically, it allowed larger partitions and larger files to require less metadata space by breaking the hard drive into larger areas. For example, at the point where a 16-bit number would overflow to a 17-bit number, you could double the space by doubling the block size, reducing the number back to 16-bits, but requiring more space be left empty by files. Block multipliers added virtual bits to the addresses and file sizes. This is less important today, but early systems only had limited address sizes.
    – phyrfox
    Jun 23, 2015 at 16:54
  • This allowed the flexibility of allowing more files to occupy a smaller space at the expensive of maximum file size and partition size, or allowing fewer files to occupy more space with a larger partition size. Note that the block size can only be allocated during formatting, but this parameter determines the maximum addressable area for a particular partition.
    – phyrfox
    Jun 23, 2015 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .