3

I'm trying to learn about HFS+ and it keeps referring to "extents."

Wikipedia

Fork Data Attribute records contain references to a maximum of eight extents that can hold larger attributes. Extension Attributes are used to extend a Fork Data Attribute record when its eight extent records are already used.

  1. What is an extent and how is it used?
  2. Do file systems that use extents also use clusters?
  3. How are extents and clusters different?

I have read the Wikipedia entry for extents and all it says is: They are contiguous blocks of reserved memory. Without context this has no meaning.

3 Answers 3

7

(Disclaimer: I know about filesystems in general, but not HFS specifically.)

A cluster is a group of disk sectors that are allocated as a unit. It's generally a small power of two. For example, if a filesystem allocates space in units of 4 kilobytes, but the disk's physical sector size is 512 bytes, a cluster will correspond to a group of 8 sectors. Clusters are also referred to as "blocks" or "allocation units".

In a nutshell, a cluster is the smallest unit of storage in a filesystem, in the same sense that a sector is the smallest unit of storage on the underlying disk. They might be the same (e.g. a filesystem using 4k clusters on a disk with 4k physical sectors) or they might be different (you can make a FAT filesystem with 64k clusters, but no disk has sectors that big).

An extent means a contiguous range of clusters somewhere on the disk, described by a starting cluster number and a length (how many clusters after the starting one). They're used to keep track of where a file's contents are located on the disk. Ideally, a file's entire contents should be stored in one contiguous region so it can be described by a single extent record, but if the file is fragmented, each portion is described by a separate extent record.

2
  • 4
    Also, for completeness: a file's contents may be described with multiple extent records due to its size, even if it isn't fragmented. In an ext4 filesystem, for example, an extent can't be bigger than 128MB, so a 1GB file will need 8 extent records even if they're all contiguous.
    – Wyzard
    Feb 17, 2012 at 6:26
  • ... and to further that, sparse files may have a size that is larger than the sum of its extents - it may even have zero extents.
    – Attie
    Jun 13, 2020 at 11:14
3

I think Apple tries to hide it, but the full technical description of the HFS+ volume format can be found on their developer website here:

Technical Note TN1150
HFS Plus Volume Format

Here are some bits that are relevant to your question:

HFS Plus allocates space in units called allocation blocks; an allocation block is simply a group of consecutive bytes. The size (in bytes) of an allocation block is a power of two, greater than or equal to 512, which is set when the volume is initialized. This value cannot be easily changed without reinitializing the volume. Allocation blocks are identified by a 32-bit allocation block number, so there can be at most 2^32 allocation blocks on a volume. Current implementations of the file system are optimized for 4K allocation blocks. Note: For the best performance, the allocation block size should be a multiple of the sector size. If the volume has an HFS wrapper, the wrapper's allocation block size and allocation block start should also be multiples of the sector size to allow the best performance.

So basically, what Microsoft calls "clusters" in FAT and NTFS, Apple calls "allocation blocks" in HFS+. This answers your second question: Yes, HFS+ is an example of a filesystem that uses both extents and clusters allocation blocks. And for that matter, NTFS also uses extents and clusters.

HFS+ tracks which allocation blocks belong to a fork by maintaining a list of the fork's extents. An extent is a contiguous range of allocation blocks allocated to some fork, represented by a pair of numbers: the first allocation block number and the number of allocation blocks. For a user file, the first eight extents of each fork are stored in the volume's catalog file. Any additional extents are stored in the extents overflow file, which is also organized as a B-tree.

So in HFS+, an extent is a contiguous run of allocation blocks used to store a file* or a portion of a file. If the file is fragmented, it uses one extent per fragment. From what I can tell, this matches the way discussions of NTFS internals use the term "extents" as well.

*file: Technically, I should have said "fork" here, but since no one uses resource forks anymore, the fact that HFS+ supports separate "data" and "resource" forks for each file is mostly just a historical anachronism.

2
  • That's a great link :-), and thank you for explaining that.
    – rubixibuc
    Feb 18, 2012 at 0:04
  • I believe an allocation unit is a group of logically consecutive sectors. The physical sectors will be subject to sector interleaving and/or sector skew making bytes not consecutive at higher granularity than the sector. Jun 13, 2020 at 11:13
0

The very important point about extent\cluster size is that You can write inside a file with io block size 512B inspite of extent size = 4KB.

Why do we uses extents. It is just a convenient way to store information about what blocks a file uses. Instead of storing information about all the blocks on hdd file uses we can store just start blocks addresses of extents. When we know the extent numbers we can calculate all the blocks file uses. And after we calculated all the block file uses we can write inside the file with any block size from 512B to 4K(extent size).

So the important point if an extent size of FS=4K it dos NOT mean that all IO write operations can be not less than 4KB. NOPE. We can write inside the file with 512B if we need inspite of extent size.

You must log in to answer this question.

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