Operating Systems · Unit 5 · 6 hrs
File Management
Exam-focused notes for File Management (Operating Systems, CSC264): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.
File Management in short
This chapter covers file management: how the operating system names, structures and stores files, organizes them into directories, and keeps track of which disk blocks are still free.
What this unit covers
- File Overview: File Naming, File Structure, File Types, File Access, File Attributes, File Operations, Single Level, two Level and Hierarchical Directory Systems, File System Layout
- Implementing Files: Contiguous allocation, Linked List Allocation, Linked List Allocation using Table in Memory, Inodes
- Directory Operations
- Path Names
- Directory Implementation
- Shared Files
- Free Space Management: Bitmaps, Linked List
File Overview
2081 · 5 marks
List different file structures and explain them. [5]
Show solved answerHide answer
File Structures
A file structure defines how data is organized and stored within a file. Different types of files have different internal structures depending on their purpose and the programs that use them.
Different File Structures
1. Regular Files (User Files)
Regular files contain user information. They are the most common type of file and are generally of two subtypes:
a) ASCII Files
- Consist of lines of text.
- Each line is terminated by a carriage return or newline character.
- Can be displayed and printed directly.
- Can be created and edited by any ordinary text editor.
- Example:
.txtfiles, source code files.
b) Binary Files
- Consist of a sequence of bytes only.
- They have some internal structure known only to the programs that use them.
- Cannot be read directly as plain text.
- Example: Executable files (compiled programs), object files.
2. Directory Files
- These are system files used for maintaining the structure of the file system.
- A directory file keeps track of the files contained within it, storing their names, identifiers, and locations.
- They form the hierarchical tree structure of the file system.
3. Character Special Files
- Related to Input/Output (I/O) operations of the computer.
- Used to model serial I/O devices such as terminals, printers, and network interfaces.
- They do not store data permanently; instead, they represent device streams.
Summary Table
| File Structure | Description | Example |
|---|---|---|
| ASCII File | Text lines, human-readable | .txt, source code |
| Binary File | Byte sequences, internal structure | Executable, .exe |
| Directory File | Maintains file system structure | Folders/directories |
| Character Special File | Models serial I/O devices | Terminals, printers |
Conclusion
Different file structures serve different purposes in an operating system. Regular files (ASCII and binary) store user data, directory files organize the file system hierarchy, and character special files provide an interface to hardware I/O devices. Understanding these structures is essential for effective file system management.
2078 · 5 marks
What is ment by file attributes? Discuss any one technique of implementing directories in detail. [5]
2080.1 · 5 marks
Why do we need hierarchical directory system? Explain structure of disk. [5]
Implementing Files
2080 · 5 marks
Differentiate between contiguous and linked list file allocation technique. [5]
2079 · 5 marks
Discuss the advantages disadvantages of implementing file system using Linked List. [5]
2080.1 · 5 marks
Discuss about contiguous and linked list file allocation technique. [5]
Show solved answerHide answer
File Allocation Techniques: Contiguous and Linked List
1. Contiguous Allocation
In contiguous allocation, each file is stored as a contiguous run of disk blocks on the disk. The directory entry for each file records the starting block address and the length of the file.
Example:
- On a disk with 1-KB blocks, a 50-KB file is allocated 50 consecutive blocks.
- On a disk with 4-KB blocks, the same file would need 25 consecutive blocks.
- Each file begins at the start of a new block; any wasted space occurs only at the end of the last block.
Advantages
- Simple to implement -- the directory only needs to store the start address and length.
- Excellent read performance -- since blocks are consecutive, sequential and random access are both fast (minimal disk seeks).
Disadvantages
- External fragmentation -- over time, free space becomes scattered in small pieces, making it difficult to find a large contiguous area for new files.
- Difficult to extend files -- if a file needs to grow, there may be no free space immediately after its last block.
- Difficult to find space for new files when free blocks are fragmented.
2. Linked List Allocation
In linked list allocation, each file is stored as a linked list of disk blocks. The first word of each block is used as a pointer to the next block, and the remaining space in the block holds actual data.
Block 4 Block 7 Block 2 Block 9
[ptr=7|data]-->[ptr=2|data]-->[ptr=9|data]-->[EOF|data]
The directory entry stores only the address of the first block of the file; the chain of pointers leads to all subsequent blocks.
Variant: FAT (File Allocation Table)
- The pointers are moved out of the data blocks and stored in a separate table called the FAT.
- The entire block becomes available for data.
- The FAT is used as a linked list; the directory entry contains the block number of the first block, and the FAT is looked up to find the next block until a special end-of-file (EOF) value is reached.
Advantages
- Solves all problems of contiguous allocation -- no external fragmentation, files can grow easily by linking new blocks anywhere on disk.
- No need for compaction of free space.
Disadvantages
- Only efficient for sequential access -- random access is excessively slow because to reach block n, all n-1 preceding blocks must be traversed.
- Space overhead for pointers -- each block loses some bytes to store the next-block pointer.
- Each block access may require a disk seek, increasing access time.
Comparison Summary
| Feature | Contiguous | Linked List |
|---|---|---|
| Implementation | Simple | Moderate |
| Sequential Access | Fast | Moderate |
| Random Access | Fast | Very Slow |
| Fragmentation | External fragmentation | No fragmentation |
| File Extension | Difficult | Easy |
| Space Overhead | None | Pointer per block |
Free Space Management
2078 · 5 marks
What approaches are using for managing free disk spaces? Explain linked list approaches with example. [5]
2076 · 5 marks
How can you manage free disk space? Explain the linked list approach of managing free disk space with example. [5]
Make Unit 5 stick
Practice CSC264 with flashcards & quizzes