CS Atlas GATE 2027
Operating Systems course
0 / 58 complete

Operating Systems/Phase 6 · File Systems & I/O

Lesson 6.1.1 · Item 45 of 58

Files, directories and access methods

Read at your own pace. Try the questions before opening the answers.

On this page

0 · Recall Warm-up

Answer from memory first. Answers are in the Answer Vault at the bottom.

  1. What does the clock algorithm do with a page whose reference bit is 1? from Lesson 5.3.3
  2. Which system call creates a new process? from Lesson 1.1.2
  3. What does the OS keep about each process in a PCB? from Lesson 1.1.1

1 · The Hook

Your phone has thousands of photos, yet you find one in seconds by opening "Photos → 2026 → Goa". Files give data a name, and directories organise the names. This lesson is light in GATE terms, but the words it introduces (open-file table, hard link, rwx bits) are used in every later file-system question.

2 · Predict First

Try the questions first. Open when you are ready to check.

A file has permissions shown as rwxr-x---. Can a user who is not the owner and not in the file's group read it?

Make a guess in your head. The answer opens Section 3.

3 · Core Concept

Predict First — the answer

No. The last three characters (---) are the permissions for "others": nothing allowed.

In plain words

A file is a named collection of data kept on disk. The OS remembers facts about it (its attributes), offers operations on it (open, read, write, close), and keeps files in directories so names can be found. Permissions say who may do what.

1. File attributes and operations

  • Attributes: name, type, size, location on disk, protection, owner, timestamps. Kept in a per-file record (in UNIX, the inode: Lesson 6.1.2).
  • Operations: create, open, read, write, seek (move the file pointer), close, delete, truncate.
  • open() finds the file once and returns a small number (file descriptor), so later reads don't search again.

2. Open-file tables

  • System-wide open-file table: one entry per open file (location, size, open count).
  • Per-process table: for each file the process opened, its file pointer (current position) and access mode, pointing to the system-wide entry.
  • When the open count drops to 0 on close, the system-wide entry is removed.

3. Access methods

  • Sequential: read the next record, then the next (like a tape). Most common.
  • Direct (relative): jump straight to block n (databases).
  • Indexed: an index of keys points to blocks; search the index, then jump.

4. Directory structures

StructureIdeaProblem / feature
Single-levelone directory for everyonenames clash
Two-levelone directory per userno grouping inside a user
Treedirectories inside directoriesabsolute path (from root) and relative path (from current directory)
Acyclic grapha file can appear in two directories (links)deleting must handle shared files
General graphcycles allowedneeds cycle checks / garbage collection

Links:

  • Hard link: another directory entry for the same inode; the inode keeps a link count, and data is freed only when it reaches 0.
  • Soft (symbolic) link: a small file that stores a path; it breaks if the target is deleted.

5. Protection: UNIX permission bits

Three groups (owner, group, others) × three rights (read r, write w, execute x) = 9 bits, usually written in octal: r = 4, w = 2, x = 1. 754 = owner 7 (rwx), group 5 (r-x), others 4 (r--) → rwxr-xr--. Access-control lists (ACLs) can list rights per individual user.

4 · Visual

A tree directory (blue = directories, green = files). Absolute path of os.pdf: /home/asha/gate/os.pdf; from /home/asha the relative path is gate/os.pdf.

5 · Worked Examples

Example 1 Easy

Write permissions rw-r----- in octal.

Solution

owner rw- = 6, group r-- = 4, others --- = 0 → 640.

Example 2 Medium

A file has two hard links. One of them is deleted. Is the file's data freed?

Solution

No. The link count drops from 2 to 1; data is freed only at 0.

Example 3 GATE

A symbolic link points to /home/asha/a.txt, and a.txt is then deleted. What happens when the link is opened?

Solution

It fails (dangling link): the soft link only stores the path.

6 · GATE Traps

  • Octal digits: r = 4, w = 2, x = 1; order is owner, group, others.
  • Hard links share the inode; soft links store a path.
  • The file pointer is per process (per open), not per file.
  • Sequential access is the default; direct access needs block numbers.

7 · Memory Hook

"rwx = 4 2 1; owner-group-others. Hard link = same inode; soft link = just a path."

8 · Connect the Dots

The directory entry tells us which file; the next lesson shows where its blocks are: contiguous, linked (FAT) or indexed (inodes), and how free blocks are tracked.

9 · Self-Test

GATE format. Try every question before opening the vault.

Q1 · NAT · 1 mark(s) — Permissions

What octal number represents rwxr-x--x?

Numerical answer: ________

Q2 · MCQ · 1 mark(s) — Permissions

Permissions 640 on a file mean the group can:

  1. (A) read only
  2. (B) read and write
  3. (C) nothing
  4. (D) execute only

Q3 · MCQ · 1 mark(s) — Links

Which statement about hard links is true?

  1. (A) Deleting the original name always frees the data
  2. (B) Hard links break when the target is renamed
  3. (C) A hard link is another name for the same inode
  4. (D) A hard link stores the target's path

Q4 · MCQ · 1 mark(s) — Open-file table

Where is the current file pointer (read/write position) kept?

  1. (A) In the inode
  2. (B) In the directory entry
  3. (C) In the disk's boot block
  4. (D) In the per-process open-file entry

Q5 · MCQ · 1 mark(s) — Access methods

Reading record 500 without reading records 0–499 first requires:

  1. (A) a single-level directory
  2. (B) a symbolic link
  3. (C) sequential access
  4. (D) direct access

10 · Rule Card

  • File: attributes + operations; open() returns a descriptor; seek moves the pointer.
  • System-wide table (open count) + per-process table (file pointer).
  • Access: sequential, direct, indexed. Directories: single, two-level, tree (absolute/relative paths), acyclic graph, general graph.
  • Hard link = same inode, link count; soft link = path (can dangle).
  • UNIX rwx bits: owner/group/others, r4 w2 x1 (e.g. 754 = rwxr-xr--).

11 · Concept Ledger

Unlocked in this lesson. From here on, these terms may be used.

filefile attributesfile operationsopen-file tablesfile pointeropen countsequential accessdirect accessindexed accessdirectory structuresabsolute and relative pathshard linksoft (symbolic) linklink countpermission bitsaccess-control list

12 · Answer Vault

Try the questions first. Open when you are ready to check.

🔐 Open the Answer Vault

Recall Warm-up

  1. Clears the bit and moves on (second chance).
  2. fork().
  3. State, PC, registers, memory and file information, etc.

Self-Test

Q1 Answer: 751 · 1 mark(s)

7, 5, 1.

Re-read: Lesson 6.1.1 — Files, directories and access methods

Q2 Answer: (A) · 1 mark(s)

Middle digit 4 = r--.

  • (B) is wrong: That would be 6.
  • (C) is wrong: That would be 0.
  • (D) is wrong: That would be 1.

Re-read: Lesson 6.1.1 — Files, directories and access methods

Q3 Answer: (C) · 1 mark(s)

Same inode, link count increases.

  • (A) is wrong: Only when the count reaches 0.
  • (B) is wrong: Renaming doesn't affect other names.
  • (D) is wrong: That is a soft link.

Re-read: Lesson 6.1.1 — Files, directories and access methods

Q4 Answer: (D) · 1 mark(s)

Each open has its own position.

  • (A) is wrong: The inode is shared.
  • (B) is wrong: Directories hold names.
  • (C) is wrong: No.

Re-read: Lesson 6.1.1 — Files, directories and access methods

Q5 Answer: (D) · 1 mark(s)

Jump to the record.

  • (A) is wrong: Unrelated.
  • (B) is wrong: Unrelated.
  • (C) is wrong: Would read everything before it.

Re-read: Lesson 6.1.1 — Files, directories and access methods

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.