UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 6.2 Free with a free account
The Anatomy of a File System
Introduction to Operating Systems · Chapter 6: File Systems and Data ManagementSection 6.2 · lesson 49 of 837 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 Managers →← The Storage Beneath File SystemsNext lesson: File Managers →
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 directories, metadata and inodes let a file system find files.
- Describe the directory tree and write absolute and relative paths
- Explain what an inode stores and why the file name lives in the directory
- Count the name lookups needed to open a file from its path
- Explain why renaming is instant and why deleted files can sometimes be recovered
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 (941 words). Read along, or search it.
Opening Puzzle
A Four Gigabyte Rename in No Time
Imagine a library with a million books and no catalog. You could still find a book, but only by walking every aisle. A file system is the catalog. It keeps a card for every file, and a set of shelves, the folders, that gives each card a place. Now a puzzle to keep in mind. Sam, who runs a small online bakery, renamed a 4 GB folder of cake photos, and it took no time at all. Four gigabytes, and nothing to wait for. By the end of this lesson, you'll know why.
Directory Tree
Folders Grow From a Single Root
Start with the shelves. Ivy, who looks after the computers at a school, keeps a copy of Sam's shop files on her Linux server. A directory, or folder, is a file whose contents are a list of other names. Some of those names are plain files, and some are more directories. So the shape is a tree: one starting point, the root, with branches that split. Every item has exactly one parent: the directory that lists it. Only the root at the top has none.
Paths
Absolute and Relative Paths
A path names one item by spelling out the route to it from the root: slash home, slash sam, slash shop, slash recipes, slash muffins dot t x t. A relative path starts where you're standing instead. From shop, orders slash twenty twenty-six goes two steps down, and dot dot climbs one step up.
Metadata
Facts About a File, Not the File
Now the cards. Metadata is data about data. A library card holds the title, the author and the shelf, but none of it is the book itself. A file system keeps similar facts for every file: its type, its size in bytes, its permissions, its owner, its times, and how many names point to it. Take muffins dot t x t. It holds flour, sugar, eggs: eighteen characters. Yet its size is nineteen bytes, because the line ends with an invisible newline character. And size isn't space used. Those nineteen bytes still reserve a whole block on the drive, as you saw in lesson six point one.
Inodes
The Inode Holds Everything but the Name
On Unix and Linux file systems, that card is called an inode, short for index node. The inode holds the metadata, and the list of blocks where the contents live. Lesson six point four looks at that list. Here's the surprising part: the inode does not hold the file's name. The name lives in the directory. A directory is just a table of pairs: a name, and an inode number.
Consequences
Names, Renames and Link Counts
That explains three things. One file can have several names, each a row in some directory. Lesson six point six shows these links. Renaming a file, even a huge one, only changes a row in one table. The data never moves. And the inode's link count is simply how many directory rows point to it.
Quick Check
Which Move Takes Real Time
Quick check. Ivy has a four gigabyte video on her server's drive, and tries three things with it. Rename it in the same folder. Move it into another folder on the same partition. Or move it onto a USB stick. Which one takes real time? Pause, and decide. The USB stick. It's a different file system, with its own records and its own blocks, so every byte has to be copied across. Moving to another folder on the same partition is as quick as renaming. The old directory loses a row, and the new one gains it. The inode and the data stay put.
Path Lookup
Walking a Path One Name at a Time
How does the operating system find a file from its path? Say it opens slash home, slash sam, slash shop, slash recipes, slash muffins dot t x t. It starts at the root directory, which sits at a known place on the partition, and it repeats one move. Look up the next name in the current directory, take its inode number, and load that inode. Then do it again. Home, sam, shop, recipes, and finally muffins dot t x t: five lookups, one per name.
Quick Check
Counting Lookups to a File
Quick check. Ivy opens a file at slash home, slash ivy, slash lab, slash notes dot t x t. Starting from the root, how many name lookups does it take to reach the file's inode: three, four, or five? Pause, and decide. Four. Home, ivy, lab, and notes dot t x t: one lookup for each name after the root. The root itself needs no lookup, because the system already knows where it is. That's why it isn't five. Four lookups, then, and no more.
Deleting Files
Removing a Name, Not the Bytes
Now deleting makes sense. When you remove a file, the OS removes its name from the directory, and lowers the inode's link count by one. If the count reaches zero, and no program has the file open, the inode and its blocks are marked free, ready to be reused. Nothing is wiped on the spot. The old bytes stay until new data lands on top. That's why a deleted file can sometimes be recovered, and why you can't count on it. For real secrets, use a tool made for secure erasing.
Puzzle Solved
Why the Big Rename Was Instant
Back to Sam's four gigabyte folder. The rename changed one name, in one row of one directory. Windows calls its cards file records rather than inodes, but the idea is the same. Every block of every photo stayed exactly where it was, so there was nothing to wait for.
Key Takeaways
Directories, Inodes and Lookups
To recap. A directory is a list of names, and directories form a tree that grows from the root. The facts about a file, its metadata, live in its inode. The name doesn't. A directory row pairs a name with an inode number, and the link count counts those rows. Opening a path takes one lookup per name, and deleting removes a row.
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 The Anatomy of a File System
What is an inode in Linux?
How do absolute and relative paths walk the folder tree?
Why is renaming a large file instant?
Can a deleted file be recovered?
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 →