10 File System And Storage Management

Operating Systems · Unit 10

File System and Storage Management

Exam-focused notes for File System and Storage Management (Operating Systems, BIT204): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.

File System and Storage Management in short

A file is a named set of related data stored on secondary storage. The file system gives users a simple way to store, find and protect data. This chapter covers files, access methods, directories and space allocation.

File System and Storage Management: notes

File types and characteristics

A file has these attributes: name, type, location on disk and size. It also has protection (who can read, write or run it), dates of creation and change, and an owner.

Common file types:

  • Regular files: hold user data. These are text (ASCII) files or binary files.
  • Directories: system files that keep the structure of the file system.
  • Character special files: model devices such as a keyboard or printer.
  • Block special files: model devices such as disks.

File extensions such as .txt, .c and .exe tell the OS and the user the file type.

Basic operations: create, open, read, write, seek, delete, truncate and close.

Sequential file access

In sequential access, the data is read or written one record after another, in order. A pointer moves forward after each read or write.

  • read next reads the next record.
  • write next adds to the end.
  • reset goes back to the start.

It is simple and works on tapes. The disadvantage is that to reach record 500, the system must pass the first 499.

Random file access

In random (direct) access, any record can be read or written directly, without reading the ones before it. The file is seen as a numbered set of blocks.

  • read n reads block number n.
  • write n writes block number n.
  • seek moves the pointer to a position.

It is fast and used by databases and airline booking, where a single record must be found quickly. Disks allow it since they can reach any block directly.

Sequential accessRandom access
Records are processed in order.Any record can be reached directly.
Slow to reach a distant record.Fast to reach any record.
Good for tapes and logs.Good for disks and databases.

What this unit covers

  • File types and characteristics
  • Sequential file access
  • Random file access
  • File system implementation
  • Directory system implementation
  • Bitmap based free space management
  • File Allocation Table
  • Block size and allocation calculations

File system implementation

2082 · 5 marks

Explain about file system and directory system implementation. [5]

Note: Reference notes were not available for this topic. The following answer is based on standard Operating Systems curriculum as taught in BSc CSIT. --- The file system provides a mechanism for storing and accessing both data and programs of the OS. It has two distinct parts: - Logical File Sys...

Open this answer on its own page →

File Allocation Table

2080 · 5 marks

A 2 GB disk has a 4-KB block size, calculate the size of the file allocation table if each entry of the table is 4 bytes. [5]

Parameter Value ------------------ Disk Size 2 GB Block Size 4 KB FAT Entry Size 4 bytes $$\text{Disk Size} = 2 \text{ GB} = 2 \times 2^{30} = 2^{31} \text{ bytes}$$ $$\text{Block Size} = 4 \text{ KB} = 4 \times 2^{10} = 2^{12} \text{ bytes}$$ The FAT holds one entry per disk block: $$\text{Numbe...

Open this answer on its own page →

2079 · 5 marks

Consider 500 GB hard drive with 5 KB block size. Calculate the size of the file allocation table if entry for each block needs 4 bytes. [5]

Parameter Value ------------------ Hard drive size 500 GB Block size 5 KB FAT entry size 4 bytes per block --- $$500 \text{ GB} = 500 \times 1024 \times 1024 \text{ KB} = 524{,}288{,}000 \text{ KB}$$ Each block requires exactly one FAT entry, so first find how many blocks exist. $$\text{Total Blo...

Open this answer on its own page →

File types and characteristics

2078 · 5 marks

What are different types of file? Describe the sequential and random access of files. [5]

Show solved answer

Types of Files, Sequential and Random Access

Types of Files

Files can be classified based on their nature and access method:

  1. Text Files - Store data as human-readable characters (ASCII/Unicode). Each line ends with a newline character. Example: .txt, .csv

  2. Binary Files - Store data in binary format (as bytes), not human-readable. Example: .exe, .jpg, .mp3

  3. Sequential Files - Records are stored and accessed one after another in order.

  4. Random Access Files (Direct Access Files) - Records can be accessed directly at any position without reading preceding records.

  5. Index Sequential Files - Combination of sequential and direct access; uses an index to locate records.


Sequential Access of Files

In sequential access, data is read or written in order from the beginning to the end of the file. To reach a particular record, all preceding records must be read first.

Characteristics:

  • Simple to implement
  • Suitable for batch processing (e.g., payroll, billing)
  • Slow for searching a specific record
  • Pointer moves only forward (one record at a time)

Operations:

OperationDescription
open()Opens file at the beginning
read()Reads next record in sequence
write()Writes next record in sequence
close()Closes the file

Example (in C-like pseudocode):

FILE *fp = fopen("data.txt", "r");
while (!feof(fp)) {
    fscanf(fp, "%s", record);
    // process record
}
fclose(fp);

Diagram:

[Record 1] --> [Record 2] --> [Record 3] --> [Record 4] --> EOF
   Read 1st      Read 2nd      Read 3rd      Read 4th

Random Access of Files

In random access (direct access), any record can be read or written directly by specifying its position (offset) in the file, without reading preceding records.

Characteristics:

  • Faster access to specific records
  • Suitable for databases and real-time systems
  • Uses seek() function to move file pointer to any position
  • Requires knowledge of record size for offset calculation

Key Functions:

FunctionDescription
fseek(fp, offset, origin)Moves file pointer to a specific position
ftell(fp)Returns current position of file pointer
rewind(fp)Moves file pointer back to the beginning

fseek() Origins:

  • SEEK_SET - Beginning of file
  • SEEK_CUR - Current position
  • SEEK_END - End of file

Example (in C):

FILE *fp = fopen("data.bin", "rb");
int recordSize = sizeof(struct Record);
int recordNo = 3;  // Access 3rd record directly

fseek(fp, (recordNo - 1) * recordSize, SEEK_SET);
fread(&record, recordSize, 1, fp);
fclose(fp);

Diagram:

[Record 1] [Record 2] [Record 3] [Record 4] [Record 5]
                          ^
                          |
                    Direct jump using fseek()

Comparison Table

FeatureSequential AccessRandom Access
Access methodOne by one in orderDirectly by position
SpeedSlow for specific recordFast for specific record
ComplexitySimpleSlightly complex
Use caseBatch processingDatabases, real-time
File pointerMoves only forwardCan move anywhere
Open this answer on its own page →

Bitmap based free space management

2078 · 5 marks

A 2 GB hard disk has 2 KB block size, calculate the size of bitmap for bitmap based free space management. [5]

Parameter Value ------------------ Disk size 2 GB Block size 2 KB In bitmap free space management, every disk block is represented by exactly 1 bit (1 = allocated, 0 = free). So the bitmap size in bits equals the total number of blocks. $$2 \text{ GB} = 2 \times 2^{30} = 2^{31} \text{ bytes}$$ $$...

Open this answer on its own page →