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.

How to use this article

  1. 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.
  2. 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.
  3. Write the open questions before looking at the model answer. Then compare with the list “what the marker looks for”.
  4. 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.

Question 1Single choice

Which sentence best describes what a file is for the operating system?

  1. A named object that stores persistent information, still there after switching off
  2. An area of RAM the process reserves with malloc
  3. A row of contiguous disk sectors
  4. 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.

Question 2Match

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).

Question 3Multiple · wrong ticks subtract

Which of these are attributes of a file?

  1. The size
  2. The creation and modification dates
  3. The location on the device
  4. The protection information (permissions)
  5. The PID of the process reading it
  6. 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.

Question 4True or false

About opening and closing files, true or false:

  1. open() copies the file’s control information into main memory so as not to go to the directory on every operation.
  2. In Unix, the descriptor returned by open() is the index of the entry reserved in the process’s open-file table.
  3. Every read() searches for the file name in the directory on disk again.
  4. 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.

Question 5Single choice

You truncate datos.csv, which was 12,288 bytes long. What is left?

  1. It still exists, with its attributes, but with size 0
  2. It disappears from the directory and its blocks become free
  3. It keeps 12,288 bytes, but the current position goes back to the start
  4. 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.

Question 6Fill in the gaps

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.

Question 7Multiple · wrong ticks subtract

The expression “file system” is used with two meanings. Which ones?

  1. The operating system module that provides the file and directory services
  2. The organisation of information created on the disk to store files and directories
  3. Each process’s page table
  4. 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).

Question 8Short answer

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.

Question 9Short answer

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.

Question 10Match

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.

Question 11Order

Order the directory models from the simplest to the most general:

  1. Two levels
  2. Single level
  3. General graph
  4. Acyclic graph
  5. Tree
Solution

Correct order:

  1. Single level
  2. Two levels
  3. Tree
  4. Acyclic graph
  5. General graph

Each model adds something: separating users (two levels), subdirectories (tree), sharing without copying (acyclic) and unrestricted links, with cycles (general).

Question 12Short answer

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.

Question 13Short answer

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).

Question 14Short answer

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 /.

Question 15True or false

About directory models, true or false:

  1. With two levels, sergio and laura can each have a file called practica.c.
  2. The tree model lets one file hang from two different paths.
  3. In an acyclic graph, both paths lead to the same object, not to a copy.
  4. 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.

Question 16Single choice

datos.csv has a hard link called copia-laura.csv. You run rm datos.csv. What happens?

  1. The data is still reachable through copia-laura.csv; the i-node’s link count drops from 2 to 1
  2. copia-laura.csv breaks and points to nothing
  3. Both names are deleted at once
  4. 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.

Question 17Match

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.

Question 18Multiple · wrong ticks subtract

What can be done to avoid the problems of cycles in a general-graph directory?

  1. Allow links only to files, not to directories
  2. Garbage collection for whatever becomes unreachable
  3. Use algorithms that detect cycles while traversing
  4. Switch to contiguous allocation
  5. 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.

Question 19Single choice

You plug in a USB stick and its contents appear inside /media/usb. What has the operating system done?

  1. Mounted the stick’s file system on the mount point /media/usb
  2. Copied the whole stick to the laptop’s disk
  3. Created a hard link to every file on the stick
  4. 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.

Question 20Multiple · wrong ticks subtract

Which of these are file protection mechanisms?

  1. Access control lists (ACL)
  2. Passwords
  3. Encryption
  4. The bitmap
  5. 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.

Question 21Order

Order the file system layers from top (closest to programs) to bottom (closest to the device):

  1. Basic commands layer
  2. Driver layer
  3. Block control layer
  4. Logical layer
Solution

Correct order:

  1. Logical layer
  2. Block control layer
  3. Basic commands layer
  4. 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.

Question 22Match

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.

Question 23Short answer

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.

Question 24Single choice

Which allocation technique does Unix use with its i-nodes?

  1. Multilevel indexed (direct pointers and single, double and triple indirect)
  2. FAT
  3. Contiguous with extents
  4. 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.

Question 25True or false

Fragmentation and space, true or false:

  1. Contiguous allocation suffers external fragmentation: there can be free space in total and a file still does not fit.
  2. Linked allocation suffers external fragmentation.
  3. With indexed allocation, a file with a single data block takes two blocks.
  4. 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).

Question 26Multiple · wrong ticks subtract

What advantages does the FAT have over classic linked allocation?

  1. The links are together and can be cached or brought whole into RAM
  2. Data blocks do not lose bytes to the number of the next one
  3. If a FAT block is damaged it affects no file
  4. 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.

Question 27Fill in the gaps

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).

Question 28Short answer

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).

Question 29Single choice

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)?

  1. The single indirect
  2. A direct pointer
  3. The double indirect
  4. 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.

Question 30Short answer

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.

Question 31True or false

Directory implementation, true or false:

  1. A linear list of entries is easy to program, but very slow with thousands of files.
  2. NTFS and ext4 use B-trees (or variants) for large directories.
  3. With a hash table you have to compare the name with every entry.
  4. 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.
Question 1Calculation

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.

FileSize (B)
notas.txt3,000
grupo.c6,144
memoria.pdf9,000
FileContiguousLinkedFATIndexed
notas.txt
grupo.c
memoria.pdf
Total
Solution
FileContiguousLinkedFATIndexed
notas.txt2223
grupo.c3434
memoria.pdf5556
Total10111013

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.

Question 2Calculation

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.

AllocationBlock 0Block 3Block 4
Contiguous
Linked
FAT (in RAM)
Indexed
Solution
AllocationBlock 0Block 3Block 4
Contiguous111
Linked145
FAT (in RAM)111
Indexed222

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.

Question 3Calculation

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).

LevelData blocksCumulative (KiB)
10 direct
Single indirect
Double indirect
Triple indirect
Maximum (GiB)
Solution
LevelData blocksCumulative (KiB)
10 direct1020
Single indirect5121044
Double indirect262144525332
Triple indirect134217728268960788
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.

Question 4Calculation

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.

FileSize
apuntes.md30 KiB
dataset.csv2 MiB
grabacion.mp4100 MiB
FileDataIndexPointerReads
apuntes.md
dataset.csv
grabacion.mp4
Solution
FileDataIndexPointerReads
apuntes.md80direct1
dataset.csv5121single2
grabacion.mp42560026double3

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.

Question 5Calculation

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).

ItemValue
Disk blocks
Bitmap (MiB)
FAT with 4 B entries (MiB)
3 MiB file, linked (blocks)
3 MiB file, double links + back link (blocks)
Solution
ItemValue
Disk blocks33554432
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.

Question 1Open answer

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
Question 2Open answer

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)
Question 3Open answer

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)
Question 4Open answer

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).

The whole files topic in one drawingReview map: file and attributes, operations and open, access methods, five directory models and links, four allocation methods with pros and cons, i-node, free space and directory implementation.6.1 Interface (what you see)6.2 Implementation (how it is stored)Filenamed objectpersistent data7 attributesOperationscreate, read, write,reposition, delete,truncate · open/closeAccesssequential (tape)direct (lseek)indexed (key)Directoriessingle, two-level,tree, acyclic,general (cycles)Linkshard: same i-nodesymbolic: pathACL, mountingContiguousstart + length+ fast access− fragmentationLinkedchain of blocks+ no fragmentation− slow direct accessFATlinks in a table+ fits in RAM− damaged tableIndexedindex block+ 2 reads− one extra blocki-node (Unix)12 direct + single+ double + triple4 KiB → 4.00 TiBFree space: bitmap · linked list · FAT | Directories: linear list · hash · B-treeCalculations: everything in powers of 2 · blocks = ⌈size / useful⌉ · maximum = pointers × block
From top to bottom, what the user sees; from bottom to top, how the OS stores it in blocks.

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).
I want to…HowResult
Give the same file another nameln datos.csv copia.csvHard link: same i-node, count 2
Make a shortcut (to directories too)ln -s datos.csv atajo.csvSymbolic link: stores the path
Know what happens when deleting the originalrm datos.csvHard: the data stays · Symbolic: broken
Write an absolute pathfrom the //home/sergio/ic2/practica/informe.pdf
Write a relative path from /home/sergio/ic2without the common partpractica/informe.pdf
Use a USB stickmount itit appears under the mount point (/media/usb)

Allocation at a glance

AllocationThe directory storesReads for block kExternal fragmentationWeak point
Contiguousstart + length1Yesgrowing, holes
Linkedfirst (and last) blockk + 1Nodirect access, damaged block
FATfirst block1 (FAT in RAM)Nodamaged FAT block (there are copies)
Indexedindex block2Noextra block, damaged index block

Calculation templates (with results)

I want…CalculationExample
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⌉ + 1410 B with 4 KiB → 1 + 1 = 2
Maximum with a single index block(block / pointer) × block1 KiB and 2 B → 512 × 1 KiB = 512 KiB
Maximum with an i-node(12 + N + N² + N³) × block4 KiB and 4 B → N = 1024 → about 4 TiB
Bitmapblocks / 8 bytes2 TiB with 32 KiB → 2^26 bits = 8 MiB
FATblocks × bytes per entry2^26 × 4 B = 256 MiB

Symptom / Likely cause

SymptomLikely cause
You get one block fewer than the solutionYou divided without subtracting the links or rounded down
Indexed gives you the same as the FATYou forgot the index block
Your bitmap size comes out 8 times too bigYou counted bytes instead of bits per block
The i-node maximum comes out huge or tinyYou mixed KiB and bytes: turn everything into powers of 2
You say the tree allows sharingThat is what the acyclic graph (links) adds
You answer “linked” where a damaged block affects many filesThat is the FAT’s risk

Before handing in, ask yourself

  1. Have I subtracted the link bytes before dividing and rounded up?
  2. Have I counted the index blocks (the indexed one, the single and double ones)?
  3. Have I turned everything into powers of 2 before working with bits and bytes?
  4. 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 articles

Did 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)