Skip to main content

Directory, file path, access methods

Short answer

A directory maps file names to files (i-node pointers), organized hierarchically. File paths (absolute from root, relative from working directory) locate files. Access methods: sequential (simple, whole-file processing but slow random), direct (fast random access for fixed-size records), and indexed sequential (fast keyed lookup with index overhead).

Define directory and file path. Discuss various access methods with advantages and disadvantages of each.

Directory

A directory is a special file that contains information about other files, normally entries of (file name, attributes or pointer to the i-node). It maps file names to files, and is organised as single-level, two-level or hierarchical (tree) structures.

File path

A path name specifies a file's location in the directory tree.

  • Absolute path: starts from the root: /usr/ram/notes.txt (UNIX) or C:\Users\Ram\notes.txt.
  • Relative path: relative to the current working directory: ram/notes.txt or ../ram/notes.txt (. is the current and .. the parent directory).

Access methods

  1. Sequential access: bytes/records are processed in order from the beginning (read next, write next). Advantages: simple, efficient for processing whole files, suits tapes. Disadvantages: slow to reach an arbitrary record, cannot jump.
  2. Direct (random) access: the file is viewed as numbered fixed-length blocks, any of which can be read or written immediately (read(n)). Advantages: fast access to any record, ideal for databases and large files. Disadvantages: requires random-access media and fixed-size records or an offset; more complex.
  3. Indexed sequential access: an index of keys points to records. A lookup in the index finds the block, which is then read directly. Advantages: fast keyed access and also sequential scanning. Disadvantages: index uses extra space, needs maintenance when records change, and large index may need multiple levels.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 5 questions →