Contiguous Allocation
When we store files on a disk using Contiguous Allocation, we're essentially giving each file a neat little slice of space where each part is right next to the other, like slices of bread in a loaf. Imagine you have a bookshelf (that's your disk), and you place your books (files) side by side without any gaps. That's what we're doing here digitally.
In technical terms, this means that if you were to look at your disk, you'd see that the file occupies a set of blocks that follow one after another. It's like getting a straight sequence of seats at the movies. This ensures that when your computer goes to read the file, it can do so quickly and without having to look around too much because the data blocks are sequentially aligned, leading to what we call sequential access.
However, life's not always a smooth ride. When you delete files and save new ones, you might end up with little patches of unused space between your files, known as external fragmentation. And just like a poorly organized bookshelf, over time, it can get harder to find a contiguous space big enough for a new file, which can wastefully leave these small spaces unused. This can require additional work, such as defragmentation, to tidy up the disk space.
Linked Allocation
The Linked Allocation method mixes things up a bit. It's like a treasure hunt where each clue points to the next location. A file is broken into pieces, and each piece can be stored anywhere on the disk - it doesn't have to be next to the previous one. Each block just needs to know where the next block is, thanks to a pointer.
Understanding Disk Block Pointers
Within each file block, there's an extra piece of information; a pointer that tells your computer where to find the next block in the file. These pointers act as breadcrumbs, leading from one block to the next.
So, if your bookends (the pointers) were magic and could transport you directly to the next book, no matter where it was on the shelf, you'd have a pretty good idea of how linked allocation works. This method shines at efficiently using disk space, as it makes it effortless to slip new blocks into any open spot. Expanding a file is a breeze since you just need to find a single empty block and point to it.
However, it's not all high-fives and easy living. The downside comes when it's time to read the file. Your computer can't just zoom through it. It has to follow the pointers from one block to the next, leading to slower access times. This is somewhat like hopping from one book to the next across a scattered bookshelf.
Indexed Allocation
Ever used a table of contents in a book? Indexed Allocation is a bit like that. Each file comes with an index – a special place that holds the addresses of all the file's blocks, neatly listed. So, instead of flipping through each page, you can jump straight to a chapter. That's faster, right? Same goes for files in indexed allocation.
In this setup, when you access a file, your system looks at the index first, which acts like a detailed map telling you exactly where each piece of the file is stored on disk. This allows for a more flexible and speedy retrieval, as you don't have to traverse pointers sequentially from block to block.
While this sounds great, it's not quite as straightforward to implement. Think of the table of contents getting bigger with the book; now imagine if you have a really, really long book. Similarly, a larger file would need a heftier index block to list all the addresses, which can get complex. If the index becomes too large, it might need to be stored in multiple blocks, which can complicate things further.
Despite the complexity, indexed allocation is adept at handling both small and large files, delivering faster access times without worrying about disk space fragmentation, making it a prevalent choice for file systems wanting to balance speed and efficiency.