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.
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]
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]
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]
File types and characteristics
2078 · 5 marks
What are different types of file? Describe the sequential and random access of files. [5]
Show solved answerHide answer
Types of Files, Sequential and Random Access
Types of Files
Files can be classified based on their nature and access method:
-
Text Files - Store data as human-readable characters (ASCII/Unicode). Each line ends with a newline character. Example:
.txt,.csv -
Binary Files - Store data in binary format (as bytes), not human-readable. Example:
.exe,.jpg,.mp3 -
Sequential Files - Records are stored and accessed one after another in order.
-
Random Access Files (Direct Access Files) - Records can be accessed directly at any position without reading preceding records.
-
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:
| Operation | Description |
|---|---|
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:
| Function | Description |
|---|---|
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 fileSEEK_CUR- Current positionSEEK_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
| Feature | Sequential Access | Random Access |
|---|---|---|
| Access method | One by one in order | Directly by position |
| Speed | Slow for specific record | Fast for specific record |
| Complexity | Simple | Slightly complex |
| Use case | Batch processing | Databases, real-time |
| File pointer | Moves only forward | Can move anywhere |
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]
Make Unit 10 stick
Practice BIT204 with flashcards & quizzes