File systems — exam-style exercises with blocks, FAT, i-nodes and links (and the shortcut that pointed to nothing)
In the IC2 group project, laura had the good data in her folder and I did not want to copy it (if she fixed it, my copy would go stale). So I did what I had seen in class: ln -s /home/laura/ic2/grupo/datos.csv datos.csv. It worked for two days. On the third, laura “tidied up” her folder, moved datos.csv to grupo/entrada/ and my program started failing with No such file or directory. My shortcut was still there, with its path… to a place where there was nothing any more.
With a hard link it would not have happened: it would have been another name for the same i-node, and moving the original does not break it. That difference, and many like it, is what the exam asks about. Here is the set of exercises for the last topic of the IC2 theory. If something does not ring a bell, review the file systems theory first. And if you want to see the calculations solved step by step, there is the file systems guided practice.
Table of Contents
How to use this article
- Do the test without looking at the theory. Each question has its own “Check” button and an explanation of why the right answer is right and why the others fail. Multiple-answer questions penalise as in the exam: ticking a false option subtracts.
- Do the calculations on paper. Blocks per allocation method, reads to reach a block, maximum size with an i-node and the sizes of the bitmap and the FAT. The boxes mark themselves and accept decimals with a dot or a comma.
- Write the open questions before looking at the model answer. Then compare with the list “what the marker looks for”.
- Finish with the cheat sheet. If you got something wrong, look it up in the “Symptom / Likely cause” table.
Test: files, access, directories and allocation
Thirty-one questions with every exam format: single choice, multiple choice, true or false, gaps, matching, ordering and short answer. The questions are new (not the ones from the exam collection), but they ask about the same things.
Which sentence best describes what a file is for the operating system?
- A named object that stores persistent information, still there after switching off
- An area of RAM the process reserves with malloc
- A row of contiguous disk sectors
- The entry of a process’s open-file table
Solution
Answer: A named object that stores persistent information, still there after switching off
Persistent means non-volatile, durable: the information survives the computer being switched off. The rest are structures the OS uses to manage it.
informe.pdf is not the same for everyone. Match each level with what it sees:
| The user | |
| The system call interface (Unix) | |
| The OS kernel |
Definitions:
- A collection of blocks
- A collection of bytes
- A durable data structure
- A collection of processes
Solution
- The user → A durable data structure
- The system call interface (Unix) → A collection of bytes
- The OS kernel → A collection of blocks
The user sees a document; read() and write() see bytes without caring what they mean; the kernel stores and reads it in blocks (the transfer unit, bigger than a sector).
Which of these are attributes of a file?
- The size
- The creation and modification dates
- The location on the device
- The protection information (permissions)
- The PID of the process reading it
- The RAM frame number where it was loaded
Solution
Answer: The size · The creation and modification dates · The location on the device · The protection information (permissions)
The attributes in the notes are name, type, location, size, protection, dates and version. Remember this question penalises: ticking a distractor subtracts.
About opening and closing files, true or false:
- open() copies the file’s control information into main memory so as not to go to the directory on every operation.
- In Unix, the descriptor returned by open() is the index of the entry reserved in the process’s open-file table.
- Every read() searches for the file name in the directory on disk again.
- close() deletes the file from the disk if nobody else has it open.
Solution
- T — open() copies the file’s control information into main memory so as not to go to the directory on every operation.
- T — In Unix, the descriptor returned by open() is the index of the entry reserved in the process’s open-file table.
- F — Every read() searches for the file name in the directory on disk again.
- F — close() deletes the file from the disk if nobody else has it open.
Opening exists precisely to avoid repeating the search: the directory is looked up once and then the RAM copy is used through the descriptor.
close() only frees the resources the file was using in memory; the file stays on the disk.
You truncate datos.csv, which was 12,288 bytes long. What is left?
- It still exists, with its attributes, but with size 0
- It disappears from the directory and its blocks become free
- It keeps 12,288 bytes, but the current position goes back to the start
- It becomes an empty symbolic link
Solution
Answer: It still exists, with its attributes, but with size 0
Truncate: the contents go, the directory entry and the attributes stay (name, permissions, dates…). Delete takes everything.
Complete how each system recognises the type of a file:
On Windows the type is deduced from the ____ of the name; on Unix the operating system ____ file types; even so, every OS must understand at least the format of the ____ file.
Words:
- does not recognise
- always recognises
- text
- contents
- executable
- extension
Solution
On Windows the type is deduced from the extension of the name; on Unix the operating system does not recognise file types; even so, every OS must understand at least the format of the executable file.
Windows looks at the last letters of the name; Unix treats the contents as plain bytes; and every OS needs to recognise executables to load and start them.
The expression “file system” is used with two meanings. Which ones?
- The operating system module that provides the file and directory services
- The organisation of information created on the disk to store files and directories
- Each process’s page table
- The disk driver
Solution
Answer: The operating system module that provides the file and directory services · The organisation of information created on the disk to store files and directories
One is software (the OS module) and the other is the data structure written on the device (for example, a disk formatted as ext4 or FAT32).
Access method in which each read or write continues right where the previous one stopped, like on a tape:
Solution
Answer: Sequential
It is the basic model of Unix and Windows: open → read → read… The current position advances by itself.
Which Unix system call places the current position at any byte you want before reading (direct access)?
Solution
Answer: lseek
lseek(fd, offset, SEEK_SET) moves the position; the next read() starts there, without going through what comes before.
Match each access method with its image:
| Sequential | |
| Direct | |
| Indexed (ISAM) |
Definitions:
- A tape that only moves forward or back
- A call stack
- A sorted table queried by a key
- An array of blocks you jump into by position
Solution
- Sequential → A tape that only moves forward or back
- Direct → An array of blocks you jump into by position
- Indexed (ISAM) → A sorted table queried by a key
In indexed access, the OS keeps one or more hidden index files to search by key (for example, a surname). Today it is done outside the kernel, in databases.
Order the directory models from the simplest to the most general:
- Two levels
- Single level
- General graph
- Acyclic graph
- Tree
Solution
Correct order:
- Single level
- Two levels
- Tree
- Acyclic graph
- General graph
Each model adds something: separating users (two levels), subdirectories (tree), sharing without copying (acyclic) and unrestricted links, with cycles (general).
A disk has one single directory holding every file of every user, with no subfolders. Which directory model is it?
Solution
Answer: Single level
It is the simplest and the one that scales worst: name clashes between users and slow searches when there are many files.
From the root, the tree goes down home → laura → ic2 → grupo and notas.txt is there. Write its absolute path.
Solution
Answer: /home/laura/ic2/grupo/notas.txt
The absolute path starts at the root, which is the leading /. Do not write “/root/…”: root is another directory (the administrator’s).
Your working directory is /home/sergio/ic2. Write the relative path of /home/sergio/ic2/practica/Makefile.
Solution
Answer: practica/Makefile
The relative path starts at the working directory, so you remove the common beginning (/home/sergio/ic2/) and it does not start with /.
About directory models, true or false:
- With two levels, sergio and laura can each have a file called practica.c.
- The tree model lets one file hang from two different paths.
- In an acyclic graph, both paths lead to the same object, not to a copy.
- In a general graph, a program that walks the directories may never finish.
Solution
- T — With two levels, sergio and laura can each have a file called practica.c.
- F — The tree model lets one file hang from two different paths.
- T — In an acyclic graph, both paths lead to the same object, not to a copy.
- T — In a general graph, a program that walks the directories may never finish.
The tree has exactly that drawback: it does not allow sharing. The acyclic graph solves it with links, and the general one allows links to directories higher up, which form cycles.
datos.csv has a hard link called copia-laura.csv. You run rm datos.csv. What happens?
- The data is still reachable through copia-laura.csv; the i-node’s link count drops from 2 to 1
- copia-laura.csv breaks and points to nothing
- Both names are deleted at once
- rm fails because the file has a link
Solution
Answer: The data is still reachable through copia-laura.csv; the i-node’s link count drops from 2 to 1
A hard link is another name for the same i-node. While any name remains (count > 0), the data stays.
Match each command with what it creates:
| ln -s apuntes.md atajo.md | |
| ln apuntes.md otro.md | |
| cp apuntes.md copia.md |
Definitions:
- A symbolic link
- An independent copy
- A mount point
- A hard link
Solution
- ln -s apuntes.md atajo.md → A symbolic link
- ln apuntes.md otro.md → A hard link
- cp apuntes.md copia.md → An independent copy
The s in -s stands for symbolic. Without -s, ln creates another name for the same i-node. cp duplicates the data: if you change one, the other does not change.
What can be done to avoid the problems of cycles in a general-graph directory?
- Allow links only to files, not to directories
- Garbage collection for whatever becomes unreachable
- Use algorithms that detect cycles while traversing
- Switch to contiguous allocation
- Increase the block size
Solution
Answer: Allow links only to files, not to directories · Garbage collection for whatever becomes unreachable · Use algorithms that detect cycles while traversing
The three are the solutions in the notes. The first is the one Unix uses for hard links: they cannot point to directories.
You plug in a USB stick and its contents appear inside /media/usb. What has the operating system done?
- Mounted the stick’s file system on the mount point /media/usb
- Copied the whole stick to the laptop’s disk
- Created a hard link to every file on the stick
- Formatted the stick
Solution
Answer: Mounted the stick’s file system on the mount point /media/usb
Before using a file system you must mount it: its tree hangs from a directory of the existing tree.
Which of these are file protection mechanisms?
- Access control lists (ACL)
- Passwords
- Encryption
- The bitmap
- The FAT
Solution
Answer: Access control lists (ACL) · Passwords · Encryption
An ACL is a list of <user, permissions> pairs. Encryption protects even if someone takes the physical disk.
Order the file system layers from top (closest to programs) to bottom (closest to the device):
- Basic commands layer
- Driver layer
- Block control layer
- Logical layer
Solution
Correct order:
- Logical layer
- Block control layer
- Basic commands layer
- Driver layer
Logical: directories and i-nodes. Block control: from logical to physical block. Basic commands: reading and writing blocks, buffers. Driver: talking to the controller and interrupts.
Match each allocation method with what the directory entry stores:
| Contiguous | |
| Linked | |
| Indexed |
Definitions:
- The first block (and sometimes the last); the other links live inside the blocks
- The first block and the length
- The full list of free blocks on the disk
- The number of the index block
Solution
- Contiguous → The first block and the length
- Linked → The first block (and sometimes the last); the other links live inside the blocks
- Indexed → The number of the index block
With contiguous allocation start + length is enough because the blocks are consecutive. With linked allocation, each block says which is the next. With indexed allocation, all pointers are together in the index block.
In which allocation method is everything after a block lost if that block is damaged in the middle of the file?
Solution
Answer: Linked
The number of the next block was inside the damaged block: the chain breaks there.
Which allocation technique does Unix use with its i-nodes?
- Multilevel indexed (direct pointers and single, double and triple indirect)
- FAT
- Contiguous with extents
- Linked with double links
Solution
Answer: Multilevel indexed (direct pointers and single, double and triple indirect)
Unix solved the index-block limit with several levels: some pointers lead to data and others to index blocks.
Fragmentation and space, true or false:
- Contiguous allocation suffers external fragmentation: there can be free space in total and a file still does not fit.
- Linked allocation suffers external fragmentation.
- With indexed allocation, a file with a single data block takes two blocks.
- The FAT is a variant of linked allocation.
Solution
- T — Contiguous allocation suffers external fragmentation: there can be free space in total and a file still does not fit.
- F — Linked allocation suffers external fragmentation.
- T — With indexed allocation, a file with a single data block takes two blocks.
- T — The FAT is a variant of linked allocation.
In the article’s IC2 practical, informe.pdf did not fit with contiguous allocation with 11 free blocks because the largest hole was 4.
Linked and indexed allocation use any free block, so they have no external fragmentation (only internal fragmentation in the last block).
What advantages does the FAT have over classic linked allocation?
- The links are together and can be cached or brought whole into RAM
- Data blocks do not lose bytes to the number of the next one
- If a FAT block is damaged it affects no file
- There is no longer any need to mark the end of the file
Solution
Answer: The links are together and can be cached or brought whole into RAM · Data blocks do not lose bytes to the number of the next one
The FAT takes the links out of the blocks and gathers them in a table at the start of the disk: walking the chain means looking at the table, not reading block by block.
Complete the three ways of knowing which blocks are free:
In a ____ there is one bit per block; in a ____ each free block points to the next; and on a ____ disk the table itself marks the free ones.
Words:
- linked list
- page table
- TLB
- bitmap
- FAT
Solution
In a bitmap there is one bit per block; in a linked list each free block points to the next; and on a FAT disk the table itself marks the free ones.
The bitmap is traditional Unix’s. In the linked list, the OS only keeps a pointer to the first free block (or uses that first free block as an index block listing the others).
Indexed allocation with a single index block, 2 KiB blocks and 4-byte pointers. What is the maximum file size in KiB? (just the number)
Solution
Answer: 1024
The index block holds 2048 / 4 = 512 pointers, so the file has at most 512 blocks: 512 × 2 KiB = 1024 KiB (1 MiB).
i-node with 12 direct pointers, 4 KiB blocks and 4-byte pointers. Which pointer leads to logical block 1030 of a file (counting from 0)?
- The single indirect
- A direct pointer
- The double indirect
- The triple indirect
Solution
Answer: The single indirect
With 4 KiB and 4 B pointers, an index block holds 1024 pointers: the single one covers 1024 blocks, from 12 to 1035.
With the same i-node (12 direct, 1024 pointers per block) already in memory, how many disk reads does it take to read logical block 40,000?
Solution
Answer: 3
40,000 is greater than 1035 and less than 1,049,612: it goes through the double indirect. Reads: top index block + bottom index block + data block = 3.
Directory implementation, true or false:
- A linear list of entries is easy to program, but very slow with thousands of files.
- NTFS and ext4 use B-trees (or variants) for large directories.
- With a hash table you have to compare the name with every entry.
- The directory only exists in RAM; only the data is on the disk.
Solution
- T — A linear list of entries is easy to program, but very slow with thousands of files.
- T — NTFS and ext4 use B-trees (or variants) for large directories.
- F — With a hash table you have to compare the name with every entry.
- F — The directory only exists in RAM; only the data is on the disk.
The hash table computes the slot from the name and goes straight there. The directory is stored on the disk (in RAM, at most, a copy to go faster).
If you hesitate between a hard and a symbolic link, ask yourself “does it store a path or share the i-node?”. Almost every link question is solved with that question.
Calculations with boxes
Five problems like the exam ones. Before you start, the recipe that works for all of them:
- Everything in powers of 2: 1 KiB = 2^10, 1 MiB = 2^20, 1 GiB = 2^30, 1 TiB = 2^40.
- Blocks of a file = ⌈size / useful bytes⌉: useful = the block with contiguous, FAT and indexed; block − links with linked allocation. And with indexed, +1 for the index block.
- Pointers per block N = block / pointer. Maximum with an i-node = (direct + N + N² + N³) × block.
- Bitmap: one bit per block. FAT: one entry (of the given number of bytes) per block.
laura’s folder on a disk with 2 KiB blocks (2048 B) and 4-byte links. How many blocks does each file take with each allocation method? For indexed allocation, count its index block too.
| File | Size (B) |
|---|---|
| notas.txt | 3,000 |
| grupo.c | 6,144 |
| memoria.pdf | 9,000 |
| File | Contiguous | Linked | FAT | Indexed |
|---|---|---|---|---|
| notas.txt | ||||
| grupo.c | ||||
| memoria.pdf | ||||
| Total |
Solution
| File | Contiguous | Linked | FAT | Indexed |
|---|---|---|---|---|
| notas.txt | 2 | 2 | 2 | 3 |
| grupo.c | 3 | 4 | 3 | 4 |
| memoria.pdf | 5 | 5 | 5 | 6 |
| Total | 10 | 11 | 10 | 13 |
Blocks = size / useful space, rounded up. With contiguous, FAT and indexed allocation the whole block holds data (2048 B); with linked allocation each block loses 4 B to the number of the next one: 2044 useful bytes.
notas.txt: 3000 / 2048 = 1.46 → 2 in every method (and 2 + 1 = 3 with indexed).
grupo.c is the trap: 6144 = 3 × 2048 fits exactly in 3 blocks, but with linked allocation 3 × 2044 = 6132 < 6144: it is 12 bytes short and needs a fourth block.
memoria.pdf: 9000 / 2048 = 4.39 → 5 and 9000 / 2044 = 4.40 → 5; with indexed, 5 + 1 = 6.
Totals: 10, 11, 10 and 13. Indexed allocation spends one index block per file, however small the file is.
memoria.pdf takes 5 blocks (0 to 4). With the directory already in memory, how many disk reads are needed to read block 0, block 3 and block 4 with each method? Assume the whole FAT is in RAM and that the index block is not cached in indexed allocation.
| Allocation | Block 0 | Block 3 | Block 4 |
|---|---|---|---|
| Contiguous | |||
| Linked | |||
| FAT (in RAM) | |||
| Indexed |
Solution
| Allocation | Block 0 | Block 3 | Block 4 |
|---|---|---|---|
| Contiguous | 1 | 1 | 1 |
| Linked | 1 | 4 | 5 |
| FAT (in RAM) | 1 | 1 | 1 |
| Indexed | 2 | 2 | 2 |
Contiguous: block k is at start + k; it is computed without reading anything else: always 1 read.
Linked: the number of block k is only known by reading block k − 1, and so on backwards: k + 1 reads (1, 4 and 5).
FAT in RAM: the hops along the chain happen in the table, in memory, and then only the data block is read: 1 read.
Indexed: first the index block (its entry k is the address) and then the data block: 2 reads for any k.
An i-node with 10 direct pointers, one single indirect, one double and one triple. 2 KiB blocks and 4-byte pointers. Fill in how many data blocks each level reaches and the cumulative size in KiB; at the end, the maximum size in GiB (two decimals).
| Level | Data blocks | Cumulative (KiB) |
|---|---|---|
| 10 direct | ||
| Single indirect | ||
| Double indirect | ||
| Triple indirect | ||
| Maximum (GiB) |
Solution
| Level | Data blocks | Cumulative (KiB) |
|---|---|---|
| 10 direct | 10 | 20 |
| Single indirect | 512 | 1044 |
| Double indirect | 262144 | 525332 |
| Triple indirect | 134217728 | 268960788 |
| Maximum (GiB) | 256.5 |
Pointers per index block: 2048 / 4 = 512. Each level multiplies by 512: 10, 512, 512² = 262,144 and 512³ = 134,217,728 blocks.
Cumulative (blocks × 2 KiB): 10 × 2 = 20 KiB; (10 + 512) × 2 = 1,044 KiB; (522 + 262,144) × 2 = 525,332 KiB; and with the triple one, 134,480,394 blocks × 2 = 268,960,788 KiB.
In GiB: 268,960,788 / 1,048,576 = 256.5 GiB. The triple level contributes almost everything: 512³ × 2 KiB = 2^27 × 2^11 B = 2^38 B = 256 GiB.
i-node with 12 direct pointers, single, double and triple; 4 KiB blocks and 4-byte pointers. For each file: data blocks, index blocks it needs, which pointer leads to its last block (direct, single, double or triple) and how many reads it takes to read that last block with the i-node in memory.
| File | Size |
|---|---|
| apuntes.md | 30 KiB |
| dataset.csv | 2 MiB |
| grabacion.mp4 | 100 MiB |
| File | Data | Index | Pointer | Reads |
|---|---|---|---|---|
| apuntes.md | ||||
| dataset.csv | ||||
| grabacion.mp4 |
Solution
| File | Data | Index | Pointer | Reads |
|---|---|---|---|---|
| apuntes.md | 8 | 0 | direct | 1 |
| dataset.csv | 512 | 1 | single | 2 |
| grabacion.mp4 | 25600 | 26 | double | 3 |
With 4 KiB and 4 B pointers, 1024 pointers fit in a block. The direct pointers reach blocks 0-11, the single indirect one blocks 12-1035 and the double one blocks 1036-1,049,611.
apuntes.md: 30 / 4 = 7.5 → 8 blocks: all through direct pointers, 0 index blocks; the last one (block 7) takes 1 read.
dataset.csv: 2 MiB / 4 KiB = 512 blocks: 12 direct + 500 through the single indirect → 1 index block. The last one (511) falls in the single level: index + data = 2 reads.
grabacion.mp4: 100 MiB / 4 KiB = 25,600 blocks: 12 direct + 1024 through the single + 24,564 through the double. The double one spends its top block plus ⌈24,564 / 1024⌉ = 24 blocks below: 1 + 1 + 24 = 26 index blocks. The last block is reached through the double: 3 reads.
A 256 GiB disk with 8 KiB blocks. Work out how many blocks it has, how big its bitmap and its FAT (4-byte entries) are and, on another disk with 1 KiB blocks and 8-byte links, how many blocks a 3 MiB file takes with simple linked allocation and with double links plus a back link (three links per block).
| Item | Value |
|---|---|
| Disk blocks | |
| Bitmap (MiB) | |
| FAT with 4 B entries (MiB) | |
| 3 MiB file, linked (blocks) | |
| 3 MiB file, double links + back link (blocks) |
Solution
| Item | Value |
|---|---|
| Disk blocks | 33554432 |
| Bitmap (MiB) | 4 |
| FAT with 4 B entries (MiB) | 128 |
| 3 MiB file, linked (blocks) | 3097 |
| 3 MiB file, double links + back link (blocks) | 3146 |
Everything in powers of 2: 256 GiB = 2^38 B and 8 KiB = 2^13 B → 2^38 / 2^13 = 2^25 = 33,554,432 blocks.
Bitmap: one bit per block → 2^25 bits = 2^22 bytes = 4 MiB.
FAT: one 4 B entry (2^2) per block → 2^25 × 2^2 = 2^27 B = 128 MiB: 32 times the bitmap.
Linked: useful 1024 − 8 = 1016 B; 3 MiB = 3,145,728 B; 3,145,728 / 1016 = 3,096.19 → 3,097 blocks.
With three links: useful 1024 − 24 = 1000 B; 3,145,728 / 1000 = 3,145.728 → 3,146 blocks.
In the grupo.c question, putting 3 blocks for linked allocation. 6144 bytes are exactly 3 blocks of 2048, but each linked block only carries 2044 bytes of data: 4 are needed.
To know which i-node pointer leads to block k, keep subtracting: 12 direct, then N, then N². With N = 1024: up to 11, direct; up to 1035, single; up to 1,049,611, double.
Open questions
In the exam they are written in paragraphs, short but complete, without bullet lists: time is running. For each one, write your answer in the box and then look at the model answer and what the marker looks for.
Compare contiguous, linked and indexed allocation: what the directory stores in each, what direct access is like, what happens with fragmentation and what happens if a block is damaged.
Solution
Model answer:
With contiguous allocation each file takes consecutive blocks and the directory only stores the first block and the length; block k is at start + k, so sequential and direct access are very fast, but it suffers external fragmentation (there may be no hole in a row even if space is left over) and it struggles when the file grows.
With linked allocation the blocks can be anywhere and each one stores the number of the next; the directory stores the first one (and sometimes the last). External fragmentation disappears, but reaching block k means reading the k blocks before it, each block loses a few bytes to the link and, if one is damaged, everything after it is lost. The FAT is its variant with the links gathered in a table.
With indexed allocation all the file’s pointers are in an index block whose address the directory stores; there is no external fragmentation either and direct access costs two reads for any block, at the price of an extra block per file (which hurts small files) and of losing everything if the index block is damaged.
What the marker looks for:
- What the directory stores in each
- Cost of direct access (1 / k + 1 / 2 reads)
- External fragmentation only with contiguous
- Fragility of linked allocation and of the index block
- Mention of the FAT or the i-node as variants
Explain the difference between a hard link and a symbolic link in Unix. What happens to each one if the original file is deleted? Give an example with ln.
Solution
Model answer:
A hard link is another directory entry pointing to the same i-node as the original: there is no original and copy, but two names for the same file, and the i-node counts how many names it has. It is created with ln datos.csv copia.csv. If datos.csv is deleted, the count drops from 2 to 1 and the data is still reachable through copia.csv; it is only freed when the count reaches 0. It can only be made to files and within the same file system.
A symbolic link is a small file that stores the path of the original, like a Windows shortcut. It is created with ln -s datos.csv atajo.csv. It can point to directories and to other file systems, but if the original is deleted it dangles: it points to a path that no longer exists.
What the marker looks for:
- Hard = same i-node and link count
- Symbolic = stores a path
- What happens on deletion in each case
- The two commands (ln and ln -s)
- Restrictions of hard links (files and same file system)
Explain what the Unix i-node is like and why it uses indirect pointers. Work out the maximum file size with 12 direct pointers, one single, one double and one triple indirect, 4 KiB blocks and 8-byte pointers.
Solution
Model answer:
The i-node stores the file’s attributes (mode, owner, size, dates, link count) and the pointers to its blocks. A single index block would limit the file size to the pointers that fit in one block, so Unix uses several levels: 12 direct pointers lead to data blocks (small files spend no index blocks), the single indirect leads to a block of pointers, the double to a block of blocks of pointers and the triple adds one more level.
With 4096-byte blocks and 8-byte pointers, 4096 / 8 = 512 pointers fit per block. The maximum is (12 + 512 + 512² + 512³) blocks × 4 KiB = 48 KiB + 2 MiB + 1 GiB + 512 GiB, about 513 GiB. The triple level contributes almost everything: 512³ × 4 KiB = 2^27 × 2^12 B = 2^39 B = 512 GiB.
What the marker looks for:
- What the i-node stores
- Why one index block is not enough
- Direct pointers for small files
- Pointers per block = block / pointer (512)
- Sum of the four levels (about 513 GiB)
How does the file system know which blocks are free? Explain the bitmap, the linked list and the FAT, and work out the size of the bitmap of a 64 GiB disk with 4 KiB blocks.
Solution
Model answer:
With a bitmap, a fixed area of the disk is reserved with one bit per block saying whether it is free or taken; it is compact and makes it easy to find holes in a row, and it is the method of traditional Unix.
With a linked list, the OS only keeps the number of the first free block and each free block stores the number of the next; it uses no extra space, but walking it means reading blocks. A variant uses the first free block as an index block listing the others.
On FAT systems no other structure is needed: the FAT entry of a free block has a value that marks it as free.
Calculation: 64 GiB / 4 KiB = 2^36 / 2^12 = 2^24 blocks, so the map has 2^24 bits = 2^21 bytes = 2 MiB.
What the marker looks for:
- Bitmap (one bit per block)
- Linked list (pointer to the first free block)
- FAT (the table itself)
- Calculation with powers of 2
- Result of 2 MiB
In comparison questions (allocation methods, links, free-space structures), the mark comes from the axes of comparison: what each one stores, how much access costs, what happens if something fails. A list of loose definitions, with no comparison, falls short.
The whole topic in one drawing
Before the cheat sheet, the whole topic at a glance: on top, what you see as a user (6.1); below, how it is stored (6.2).
If you can explain each box with an example from the practical folder (practica.c, Makefile, datos.csv, informe.pdf), you have the topic.
Cheat sheet: File systems
The essentials in 30 seconds
- File: named object that stores persistent information. User → durable structure; API → bytes; kernel → blocks.
- Attributes: name, type, location, size, protection, dates, version.
- Operations: create, write, read, reposition, delete, truncate (contents only). Opening copies the control information to RAM; the descriptor is an index into the open-file table.
- Access: sequential (tape), direct (
lseek), indexed (key). - Directories: single level → two levels → tree → acyclic graph → general graph.
- Allocation: contiguous, linked, FAT, indexed; Unix = multilevel indexed (i-node).
Directories and links
| I want to… | How | Result |
|---|---|---|
| Give the same file another name | ln datos.csv copia.csv | Hard link: same i-node, count 2 |
| Make a shortcut (to directories too) | ln -s datos.csv atajo.csv | Symbolic link: stores the path |
| Know what happens when deleting the original | rm datos.csv | Hard: the data stays · Symbolic: broken |
| Write an absolute path | from the / | /home/sergio/ic2/practica/informe.pdf |
Write a relative path from /home/sergio/ic2 | without the common part | practica/informe.pdf |
| Use a USB stick | mount it | it appears under the mount point (/media/usb) |
Allocation at a glance
| Allocation | The directory stores | Reads for block k | External fragmentation | Weak point |
|---|---|---|---|---|
| Contiguous | start + length | 1 | Yes | growing, holes |
| Linked | first (and last) block | k + 1 | No | direct access, damaged block |
| FAT | first block | 1 (FAT in RAM) | No | damaged FAT block (there are copies) |
| Indexed | index block | 2 | No | extra block, damaged index block |
Calculation templates (with results)
| I want… | Calculation | Example |
|---|---|---|
| Blocks with linked allocation | ⌈size / (block − links)⌉ | 2 MiB, 1 KiB, 4 B link → ⌈2,097,152 / 1020⌉ = 2057 |
| Blocks with indexed allocation | ⌈size / block⌉ + 1 | 410 B with 4 KiB → 1 + 1 = 2 |
| Maximum with a single index block | (block / pointer) × block | 1 KiB and 2 B → 512 × 1 KiB = 512 KiB |
| Maximum with an i-node | (12 + N + N² + N³) × block | 4 KiB and 4 B → N = 1024 → about 4 TiB |
| Bitmap | blocks / 8 bytes | 2 TiB with 32 KiB → 2^26 bits = 8 MiB |
| FAT | blocks × bytes per entry | 2^26 × 4 B = 256 MiB |
Symptom / Likely cause
| Symptom | Likely cause |
|---|---|
| You get one block fewer than the solution | You divided without subtracting the links or rounded down |
| Indexed gives you the same as the FAT | You forgot the index block |
| Your bitmap size comes out 8 times too big | You counted bytes instead of bits per block |
| The i-node maximum comes out huge or tiny | You mixed KiB and bytes: turn everything into powers of 2 |
| You say the tree allows sharing | That is what the acyclic graph (links) adds |
| You answer “linked” where a damaged block affects many files | That is the FAT’s risk |
Before handing in, ask yourself
- Have I subtracted the link bytes before dividing and rounded up?
- Have I counted the index blocks (the indexed one, the single and double ones)?
- Have I turned everything into powers of 2 before working with bits and bytes?
- For links, have I said whether it stores a path or shares the i-node, and what happens when the original is deleted?
This topic closes the IC2 theory: eleven topics on networks and operating systems. Next will be a mock exam with random questions from every topic, a mark with penalties and a review of your mistakes. Meanwhile, review the topics you find hardest and come back to this test in a few days: if you get it right without looking, T6 is ready.
Keep goingAll Operating systems articlesDid this article help you? Here is how you can support SergioLearns →
Ready for the exam?IC2 theory mock exam — first midterm, second midterm or the full exam, with your real mark and a review of every mistake (as if you were in the exam room)


