File Allocation Methods, Explained

UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 6.4 Free with a free account

File Allocation Methods

Introduction to Operating Systems · Chapter 6: File Systems and Data ManagementSection 6.4 · lesson 51 of 838 min · free with a free account

← File ManagersNext lesson: File Extensions →

A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

In this lesson

How contiguous, linked, FAT and indexed allocation track file blocks.

  • Compare contiguous, linked and indexed allocation and the weakness of each
  • Follow a chain of entries in a File Allocation Table
  • Calculate the largest file one index block can describe from block and pointer size
  • Explain how inode direct and indirect pointers reach large files

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (1,060 words). Read along, or search it.

Opening Puzzle

Hotel Rooms for Every File

A hotel has to give each guest some rooms. A family of five gets five rooms in a row, and they're happy. But what if the free rooms are scattered over different floors? And what if they want one more room next week, and the room next door is taken? A file system faces the same puzzle every time you save a file: which blocks should it use, and how will it remember them? There are three classic answers. Each one solves a problem, and creates another.

Method One

Contiguous Allocation Uses One Unbroken Run

Recall that the OS hands out whole blocks. With blocks of four thousand ninety-six bytes, a ten thousand byte file needs three. The simplest plan is contiguous allocation: the file gets one unbroken run. The directory stores two numbers: start twenty, length three, which means blocks twenty, twenty-one and twenty-two. Reading is quick, because the blocks sit side by side, so a hard disk moves its arm just once. And jumping to any byte is a simple sum.

Weakness

Growing Files and External Fragmentation

The weakness is the hotel problem. A file that grows needs room after its last block, and a neighbor may already be there. Then the whole file has to move. Over time, the free space gets chopped into small gaps. A big new file may find no gap large enough, even though plenty of space is free in total. That's called external fragmentation. Memory allocation, in lesson four point eleven, tells the same story.

Method Two

Linked Allocation Chains Blocks Together

Linked allocation lets blocks live anywhere. Each block ends with a note saying which block comes next, like a scavenger hunt: clue one leads to clue two. Files can grow into any free block, so there's no external fragmentation. The cost is jumping around. To reach the hundredth block, you must follow ninety-nine links first. And one damaged link loses the rest of the file.

FAT

One Table Holds Every Link

The File Allocation Table, or FAT, is a tidier version of the same idea. The links are gathered into one table at the start of the partition, with one entry per block. Each entry says which block comes after its own. A photo starts at block nine. Entry nine says sixteen, entry sixteen says three, and entry three says end. The table can be kept in memory, so following a chain is quick, and the data blocks hold only data. FAT file systems, named after this table, are still common on USB sticks and memory cards.

Quick Check

Following a FAT Chain

Quick check, with a new file. Its directory entry says it starts at block five. The table says: entry five holds twelve, entry six holds nine, entry seven holds end, and entry twelve holds seven. In what order are its blocks read: five, twelve, seven; five, six, seven; or five, twelve, nine? Pause, and decide. Five, twelve, seven. Start at five. Entry five says the next block is twelve. Entry twelve says seven, and entry seven says end. Five, six, seven is the tempting answer. But the blocks of a chain don't have to be in order, and entry six belongs to some other file.

Method Three

Indexed Allocation Lists Every Block

The third plan is indexed allocation. Each file gets an index block: a list of all its block numbers, in order. To reach the file's fiftieth block, read entry fifty of the list. Any block is one step away, and the blocks can sit anywhere. The weakness is the list's size. One index block holds only so many pointers, and that limits how big the file can be.

Worked Example

How Far One Index Block Reaches

How many? Pointers are often four bytes each, so a block of four thousand ninety-six bytes holds four thousand ninety-six divided by four: one thousand twenty-four pointers. Each pointer reaches one block of four thousand ninety-six bytes. So one index block can describe a file of four mebibytes, at most. To size any index scheme, ask two questions: how many pointers fit in a block, and what does each one reach? Then multiply.

Inode Pointers

Direct, Single and Double Indirect Pointers

Unix-style file systems stretch this with a clever layout inside the inode, the file's card from lesson six point two. A few direct pointers aim straight at data blocks. In this model there are twelve, which covers forty-nine thousand one hundred fifty-two bytes. Next, a single indirect pointer leads to a block full of more pointers: four mebibytes more. A double indirect pointer leads to a block of those blocks: four gibibytes more. So this model tops out a little above four gibibytes. Real ext2 and ext3 inodes add a triple indirect pointer, and ext4 records runs of blocks, called extents, instead. Most files are small, so most files use only the direct pointers, and stay very fast.

Quick Check

A Photo Past the Direct Pointers

Quick check, with the same model: blocks of four thousand ninety-six bytes, and twelve direct pointers. A photo is one hundred thousand bytes. How many of its blocks are reached through the single indirect block: none, thirteen, or twenty-five? Pause, and decide. Thirteen. One hundred thousand divided by four thousand ninety-six is about twenty-four point four, so the photo needs twenty-five blocks. The first twelve use the direct pointers, and the other thirteen go through the single indirect block. Twenty-five is the tempting answer, but it forgets the twelve direct pointers, which are always used first.

Comparison

Every Plan Has a Trade-Off

So which plan wins? Contiguous gives fast reads and tiny records, but growth is hard, and gaps pile up. Linked and FAT can use any free block, but jumping to the middle means walking the chain. Indexed and inodes jump to any block and grow easily, but the index takes space, and large files need extra levels. No plan wins everywhere.

Real Example

Fragmentation and Defragmenting

Sam, who runs a small online bakery, noticed the old laptop getting slower after a year of saving and deleting photos. Ivy, who looks after the computers at a school, explained: files had grown into gaps all over the drive, so one photo might sit in a dozen places. On a hard disk, the arm has to jump between those places. A solid state drive doesn't mind. That's why defragmenting, gathering each file's blocks back together, helps hard disks, and is rarely needed on solid state drives.

Key Takeaways

Contiguous, Linked, Indexed and Inodes

To recap. Contiguous allocation stores a start and a length: fast, but it fragments. Linked allocation and the FAT follow a chain of next-block entries. Indexed allocation lists every block. One index block holds the block size divided by the pointer size. And inodes reach big files with direct, then indirect, pointers.

About Introduction to Operating Systems at UPI Study

Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About File Allocation Methods

What is external fragmentation in file allocation?
External fragmentation happens when free space is broken into many small gaps, so a large new file finds no single gap big enough even though plenty of space is free in total. It mainly affects contiguous allocation, where each file needs one unbroken run of blocks. Linked and indexed allocation avoid it by letting a file's blocks sit anywhere on the drive.
How does a File Allocation Table work?
A File Allocation Table keeps one entry per block, and each entry names the block that comes next in the same file. The directory records a file's first block, and the system follows the chain until an entry says end. For example, a file starting at block 9 might continue to 16, then 3, then stop. FAT file systems remain common on USB sticks and memory cards.
How do you calculate the maximum file size for an index block?
Multiply the number of pointers that fit in one block by the size of the block each pointer reaches. With 4,096-byte blocks and 4-byte pointers, one block holds 1,024 pointers, and each reaches 4,096 bytes, so one index block describes up to 4 mebibytes. Inodes extend this with indirect pointers, where each extra level multiplies the reach by another 1,024.
Does defragmenting help an SSD?
Defragmenting rarely helps an SSD, because a solid state drive does not slow down when a file's blocks are scattered. On a hard disk, a fragmented file forces the read arm to jump between many places, so gathering each file's blocks back together speeds up reading. That is why defragmenting suits hard disks and is seldom needed on solid state drives.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Introduction to Operating Systems.

83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Introduction to Operating Systems
3 credits · NCCRS
Enroll →