File Allocation Methods
File Allocation Methods
File Attributes:
Name: The user-assigned identifier for the file. It's a string of characters
and the only human-readable attribute. (OS Concept by Galvin)
Identifier: A unique tag (usually a number) used by the operating system
to internally identify the file. (OS Concept by Galvin)
Type: Classification of the file based on its content (e.g., text file,
executable file, image file).
Location: Pointer to the device and location where the file resides on that
device.
Size: Current size of the file (in bytes, words, or blocks) and potentially
the maximum allowed size.
Protection: Access control information specifying who can read, write,
execute, etc., the file.
Timestamps and User Identification: Information about file creation,
last modification, and last access. Useful for security and monitoring
purposes. (OS Concept by Galvin)
File Operations:
Creating a File:
1. Allocate space in the file system for the file (discussed in Chapter
14 of OS Concept by Galvin).
2. Create a directory entry for the new file.
Opening a File:
1. System call open() to establish a file handle for subsequent
operations.
2. Verifies file name, access permissions, etc.
Writing to a File:
1. System call specifying the file handle and data to write.
2. Maintains a write pointer to track the next write location for
sequential writes and updates it after each write.
Reading from a File:
1. System call specifying the file handle and memory location to store
the read data.
2. Maintains a read pointer to track the next read location for
sequential reads and updates it after each read.
3. Often utilizes a single current-file-position pointer for both read
and write operations to optimize resource usage.
Repositioning within a File (File Seek):
1. System call to modify the current-file-position pointer to a specific
value within the file, without necessarily involving actual I/O.
Deleting a File:
1. Locate the file entry in the directory.
2. Release the allocated file space for reuse.
3. Erase or mark the directory entry as free.
4. In systems with hard links (multiple directory entries for a single
file), the actual file content is only deleted when the last link is
removed.
Truncating a File:
1. Erases the file contents but preserves its attributes (except file
length).
2. Resets the file size to zero and releases the associated file space.
Files can be broadly categorized into different types based on their content and
functionality. Here are some common file types:
File allocation methods determine how the operating system stores a file on a
disk by dividing the disk space into fixed-size blocks. Here, we'll explore three
main methods with their advantages, disadvantages, and examples:
Concept: Each block of a file contains a pointer to the next block in the
sequence, forming a linked list scattered across the disk.
Advantages (2 marks):
o Reduces external fragmentation: Allows efficient use of free space
regardless of location.
o Easier file growth: New blocks can be easily appended to the end
of the linked list.
Disadvantages (2 marks):
o Slower access: Requires following pointers to locate all file blocks,
increasing seek time.
o Overhead for storing pointers: Wasting some disk space for storing
the pointers in each block.
3. Indexed Allocation (3 marks)
Concept: Stores the file's block addresses in a separate index table. The
index table can be located within the file itself or elsewhere on the disk.
Advantages (2 marks):
o Reduces external fragmentation: Similar to linked allocation.
o Faster access compared to linked allocation: Index table provides
direct access to block locations.
o Easier file growth: The index table can be dynamically extended to
accommodate additional blocks.
Disadvantages (2 marks):
o Overhead for index table: Requires additional disk space for the
index table.
o Increased complexity: Managing the index table adds complexity
to file system operations.
The selection of a file allocation method depends on factors like:
3. File Operations:
4. Directory Management:
What are the problems when files are mounted simultaneously at more
than one place?