Unit 10 · Self-check
Unit 10 Self-Check Quiz
Twenty-four questions covering the file abstraction, inodes, directory organisation, file allocation, journaling, and modern file system designs. Each question can be expanded to reveal a model answer.
Questions
Multiple choice and short answer
Answer each question before expanding. These span all seven lessons of Unit 10.
Question 1
What is the file abstraction, and what operations does the file system provide on files?
Show answer
create, open, read, write, lseek, close, unlink, truncate, rename, and stat. Everything else — buffering, blocking, allocation, caching, consistency — is the file system's responsibility.
Question 2
What is an inode, and what does it contain? Why is the file name not stored in the inode?
Show answer
Question 3
A file system uses 4 KB blocks and the inode has 12 direct pointers, one single-indirect pointer, one double-indirect pointer, and one triple-indirect pointer. With 4-byte block pointers, what is the maximum file size?
Show answer
- Direct: 12 × 4 KB = 48 KB
- Single-indirect: 1024 × 4 KB = 4 MB
- Double-indirect: 1024 × 1024 × 4 KB = 4 GB
- Triple-indirect: 10243 × 4 KB = 4 TB
Question 4
Explain the difference between a hard link and a symbolic link.
Show answer
Question 5
Compare contiguous, linked, and indexed file allocation. Which is best for sequential access, which for random access, and which is used by modern file systems?
Show answer
Question 6
A file system uses 1 KB blocks. A file is 100 KB in size. How many direct, single-indirect, and double-indirect blocks does it need? (Assume 4-byte pointers and 12 direct pointers.)
Show answer
- The first 12 blocks are accessed through the direct pointers: 12 KB.
- The next 256 blocks are accessed through the single-indirect pointer: 256 KB.
- 100 KB is larger than 12 KB but smaller than 12 KB + 256 KB = 268 KB, so the file needs:
Question 7
Why does a directory need its own inode? What is stored in a directory?
Show answer
Question 8
What is journaling, and what problem does it solve?
Show answer
fsck pass over the entire volume, which can take hours on a large file system. With journaling, recovery is a matter of replaying the small tail of the log, which takes seconds.
Question 9
Describe the three journaling modes of ext4: data=journal, data=ordered, and data=writeback.
Show answer
data=journal: both metadata and data are written to the journal before being written to the file system. This is the strongest consistency guarantee — after a crash, both the metadata and the data are in a consistent state. It is also the slowest, because data is written twice (once to the journal, once to its final location).
data=ordered: only metadata is journaled, but data blocks are written to disk before the metadata that references them. This is the default for ext4. After a crash, the metadata is consistent and the data is present (it was written before the metadata). The cost is the write ordering, which slightly reduces throughput.
data=writeback: only metadata is journaled, and data may be written at any time. This is the fastest option, but after a crash the metadata may reference data blocks that were never written, so a file may contain stale or garbage data. The file system's structures are consistent, but the file's contents are not guaranteed.
Question 10
What is the difference between ext4's "extent" and the classical "block pointer" scheme? Why are extents better?
Show answer
Question 11
What is a copy-on-write file system, and how does it differ from a journaling file system?
Show answer
Question 12
Why does a modern file system store checksums for data and metadata?
Show answer
Question 13
What is the difference between a file's "atime", "mtime", and "ctime"? Which can be changed by a read?
Show answer
noatime or relatime). mtime: the last modification time — updated when the file's contents are written. ctime: the last change time — updated when the file's metadata changes (permissions, owner, link count, size) or when the contents are written (which is a metadata change because the size and mtime are metadata). A read updates only atime. A write updates mtime and ctime. A chmod updates ctime only. The distinction matters for backup tools (which use mtime) and for forensic analysis (which uses all three).
Question 14
A file system's block size is 4 KB. What is the wasted space for a file of 1 byte? What about a file of 1 MB?
Show answer
Question 15
What is the difference between a "block" in the file system sense and a "sector" in the device sense?
Show answer
Question 16
In the ext2/3/4 file system, what is a "block group"? Why is the disk divided into groups?
Show answer
Question 17
A program opens a file, reads 100 bytes, and closes it. List the file system structures that are accessed, in order.
Show answer
- The process's current directory entry is used to resolve the first component of the path (or the root is used if the path is absolute).
- For each path component, the directory's data blocks are read to find the name-to-inode mapping.
- The target file's inode is read from the inode table.
- The file's permissions are checked against the process's effective UID and GID.
- A file descriptor is allocated in the process's file descriptor table, pointing at an entry in the system-wide open file table, which points at the inode.
- On read, the file's data block (or blocks, if the read spans a block boundary) is read from disk (or from the page cache, if cached).
- On close, the file descriptor is freed; the inode's reference count is decremented; if it reaches zero and the link count is also zero, the inode and its data blocks are freed.
Question 18
What is an "orphan" inode, and how does the file system handle it?
Show answer
Question 19
Why do modern file systems use B-trees for directory lookup?
Show answer
Question 20
What is a "sparse file", and how does the file system represent it?
Show answer
Question 21
Explain the difference between "blocking" and "non-blocking" I/O on a file descriptor. Which is the default?
Show answer
read or write call to suspend the calling thread until the operation can complete (or the data is available). This is the default for file descriptors, and it is convenient for programs that expect to wait for their I/O. A non-blocking file descriptor (set with O_NONBLOCK) causes the call to return immediately with an error (EAGAIN or EWOULDBLOCK) if the operation cannot be completed. Non-blocking I/O is used with select or poll to multiplex many file descriptors in a single thread, which is the basis of event-driven servers (nginx, Node.js). It is also used with aio (asynchronous I/O) for high-performance applications.
Question 22
A file system is described as "log-structured". Explain the idea and describe one advantage and one disadvantage.
Show answer
Question 23
What is the difference between the file's "logical" size and its "physical" size? When do they differ?
Show answer
- Sparse files: the logical size includes the zero regions, which occupy no disk blocks.
- Internal fragmentation: the last block is partly unused, so the physical size is rounded up to a block boundary.
- Compression or deduplication: if the file system compresses or deduplicates data, the physical size may be smaller than the logical size.
stat reports the logical size in the size field and the physical size in the blocks field (in 512-byte sectors).
Question 24
In one or two sentences, state the central design problem of a file system and how journaling and copy-on-write each address it.
Show answer
Ready for the graded quiz?
Once you are comfortable with every question above, take the graded Unit 10 quiz in the LMS. It covers the same material with multiple-choice questions, inode-size calculations, and a file-system-layout exercise.