CS FundamentalsVery hardGATE CS (PYQ pattern)

A Unix file system contains only these names: directories /, /a, /a/b and /c, a regular file /a/f, and /c/g, which is a hard link to /a/f. Every directory has its '.' and '..' entries (the root's '..' refers to the root itself). What is the sum of the link counts of all inodes in the file system?

  1. A. 11
  2. B. 9
  3. C. 13
  4. D. 12

Correct answer: C. 13

The sum of all link counts equals the number of directory entries that name an inode. / has ., .., a, c (4); /a has ., .., b, f (4); /a/b has ., .. (2); /c has ., .., g (3): 13. Per inode: / = 4 (., .., a's .., c's ..), /a = 3, /a/b = 2, /c = 2, file = 2. Forgetting the root's own '..' and the hard link gives 11.

More Operating Systems questions

Exams that ask this topic