7.1Files, directories and access methods
The idea
A file is a named collection of bytes; directories organise files. A hard link is another name for the same inode; a soft link is a file holding a path.
Think of it like this: A hard link is a second door to the same room; a soft link is a signpost that points to a door and goes wrong if the door moves.
Why it exists
Links explain deletion rules, and the directory structure decides sharing.
How it works
- Tree directories: unique path from the root.
- Hard link: new directory entry, same inode, link count +1; data goes when the count reaches 0.
- Soft link: new inode storing a path; may dangle.
- Hard links cannot cross file systems; soft links can.
Worked example: A file has two hard links and you delete one name
Link count goes from 2 to 1, the data stays. With a soft link, deleting the original leaves the link pointing to nothing.
Now play with it
- →Use the tables to answer: which link type can cross file systems?
- →Decide what happens to each link type after the original is deleted.
| Directory structure | Idea | Problem |
|---|---|---|
| Single-level | one directory for everything | name clashes |
| Two-level | a directory per user | no sharing, no grouping |
| Tree | directories nest; absolute and relative paths | sharing needs links |
| Acyclic graph | tree plus links, shared files | deletion and dangling links |
| General graph | cycles allowed | cycle detection needed in traversals |
| Hard link | Soft (symbolic) link | |
|---|---|---|
| What it is | another name for the same inode | a small file holding a path |
| Across file systems | no | yes |
| If the original is deleted | data stays until the link count is 0 | link dangles |
| Directories | normally not allowed | allowed |
| Extra inode | no | yes |
Check yourself
Deleting a file that has a hard link elsewhere
Exam notes (the dense version)
A file is a named sequence of bytes with attributes (name, size, type, protection, times). Operations: create, open, read, write, seek, close. Access: sequential, direct (random) or indexed. Directories: single-level, two-level, tree (the usual one), acyclic graph (links), general graph. A hard link is another directory entry pointing to the same inode (the file survives until the last link is removed, same file system only); a soft (symbolic) link stores a path name and can dangle. The open-file tables are per process and system-wide.
Previous year questions: File Systems (5)
PYQs are grouped by topic, so this is the full set for File Systems; try the ones that match this subtopic. Open all 5 on the topic page.