Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Session 4.7: File-system concepts and access methods

What a file is to the OS: attributes, operations, the open-file tables, file types and structure, and sequential, direct and indexed access.

Module 4 1 hour Theory CO4
← Before
4.6 Page replacement
Thrashing, working set
You are here
4.7 File-system concepts and access methods
Module 4 · Memory and File Management
Next →
4.8 Directories & allocation
Organising and placing files

Learning objectives

By the end of this session you should be able to:

  • List file attributes and explain where they are stored.
  • Describe file operations and the per-process and system-wide open-file tables.
  • Explain file types, extensions and magic numbers.
  • Compare sequential, direct and indexed access with examples.

Lecture notes

1. The file concept

A file is a named collection of related information recorded on secondary storage — the smallest unit of logical storage the user sees. The OS maps files onto physical devices, so users never deal with sectors and tracks.

Name

Human-readable, e.g. report.c.

Identifier

Unique number inside the file system (Linux: inode number, ls -i).

Type

Needed by systems that support types.

Location

Pointer to the device and blocks.

Size

Current size (and possibly maximum).

Protection

Who can read, write, execute (rwx bits).

Time, date, user ID

Creation, last modification, last access — for protection, security and usage monitoring.

This information is kept in the directory structure / file control block (inode), which also lives on disk.

2. File operations and the open-file table

The OS provides system calls (Session 1.3) to create, write, read, reposition (seek), delete and truncate files. To avoid searching the directory on every operation, a process first calls open(): the OS finds the file, copies its information into an open-file table and returns an index — a file descriptor.

Per-process table

File descriptor → current file pointer (position) and access mode. Each process reading a file has its own position.

System-wide table

Location on disk, size, access dates, and an open count; the entry is removed when the count reaches 0 after the last close().

File system calls in C (practised in Lab 15)
int fd = open("data.txt", O_RDWR | O_CREAT, 0644);   /* create/open → descriptor */
write(fd, "Hello\n", 6);                             /* write at the file pointer */
lseek(fd, 0, SEEK_SET);                               /* reposition to the start   */
char buf[16];
int n = read(fd, buf, sizeof buf);                    /* read n bytes              */
close(fd);                                            /* release the descriptor    */
unlink("data.txt");                                   /* delete the file           */

3. File types and structure

A common technique is to include the type in the name as an extension: .c source, .o object, .exe/none executable, .txt text, .zip archive, .mp4 multimedia. Windows relies on extensions; UNIX uses a magic number at the start of the file (try the file command). Internally a file may be unstructured (a sequence of bytes — UNIX), a sequence of fixed-length records, or a complex structure (an executable).

4. Access methods

Sequential access — information is processed in order, one record after another, like a tape. read_next() reads and advances the pointer; write_next() appends; reset rewinds. Used by editors, compilers and most programs.

beginning ▸ [ r0 | r1 | r2 | current | r4 | … ] ◂ end

Direct (relative) access — the file is a numbered sequence of fixed-length blocks/records that can be read or written in any order: read(n), write(n). Ideal for databases: to find flight 713's seats, compute its block and jump there. Sequential access is easy to simulate on direct access (keep a counter cp).

Byte position of record n = n × record length (e.g. record 25 of 80-byte records starts at byte 2000).

Indexed access — an index (like a book's index) holds keys and pointers to blocks. Search the index, then access the block directly. For large files the index itself is indexed: a primary index points to secondary index blocks, which point to data (IBM ISAM).

index: Adams→b3 · Arthur→b7 · Asher→b9 …→relative file blocks

VideoBytes

Files and access methods

Video coming soon

Files and access methods

Recorded by Dr. Krithika L.B. Slot m4-file-concepts

Interactive lessons

Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.

Lab connection

Check your understanding

Answer each question in your own words first, then reveal the model answer.

Revealed 0
Why does the OS require open() before read()?

open() searches the directory once and caches the file's information in the open-file table, so later operations use a descriptor instead of searching again.

Two processes have the same file open. What do they share and what is private?

They share the system-wide entry (location, size, open count); each has a private file pointer and access mode in its per-process table.

Which access method suits a bank's account lookups?

Direct (or indexed) access — jump straight to an account's record.

Records are 120 bytes. At which byte offset does record 10 start?

10 × 120 = 1200 (counting records from 0).

Key takeaways

  • A file is a named collection of data on secondary storage with attributes (name, id, type, location, size, protection, times).
  • open() returns a descriptor; per-process and system-wide open-file tables cache file information.
  • Access methods: sequential (in order), direct (any block by number), indexed (via an index).

Where this leads

Thousands of files need to be organised — directories — and placed on disk blocks — allocation methods. Last session of Module 4.

Continue to 4.8 — Directory structures and file allocation →