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
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: File Extensions →← 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 →
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.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
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.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →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?
How does a File Allocation Table work?
How do you calculate the maximum file size for an index block?
Does defragmenting help an SSD?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
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
3 credits · NCCRSEnroll →