0% found this document useful (0 votes)
291 views

File Allocation Methods

The document discusses file attributes, operations, and allocation methods. File attributes include name, identifier, type, location, size, and protection. Common file operations are creating, opening, reading, writing, seeking, deleting, and truncating files. The document also explains three main file allocation methods: contiguous, linked, and indexed allocation.

Uploaded by

Khushbu Ahuja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
291 views

File Allocation Methods

The document discusses file attributes, operations, and allocation methods. File attributes include name, identifier, type, location, size, and protection. Common file operations are creating, opening, reading, writing, seeking, deleting, and truncating files. The document also explains three main file allocation methods: contiguous, linked, and indexed allocation.

Uploaded by

Khushbu Ahuja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

File Allocation Methods:

What are file attributes , file operation , file types?

File Attributes and Operations

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:

 Document Files: These store textual information and formatting, often


used for creating reports, letters, presentations, etc. Examples include
DOCX (Microsoft Word), PDF (Portable Document Format), TXT (plain
text), and ODT (OpenDocument Text).
 Spreadsheet Files: Designed for storing and manipulating numerical data
in rows and columns. They enable calculations and data analysis.
Common spreadsheet file types include XLSX (Microsoft Excel), ODS
(OpenDocument Spreadsheet), and CSV (Comma-Separated Values).
 Image Files: Store digital pictures and graphics. Different file types offer
varying levels of compression and quality. Popular image file formats
include JPG (JPEG), PNG, BMP, GIF (can also be animated), and TIFF.
 Audio Files: Contain digital representations of sound recordings. File
types determine audio quality, compression level, and playback
capabilities. Common audio file formats include MP3, WAV, AAC,
FLAC, and WMA.
 Video Files: Store moving pictures with synchronized sound. Video file
types influence video quality, resolution, compression, and compatibility
with various players. Popular video file formats include MP4, AVI,
MOV, WMV, and FLV.
 Executable Files: These files contain instructions for the computer to
perform specific tasks. They are often launched by double-clicking and
can be programs, applications, or installers. Common executable file
extensions include EXE (Windows), APP (macOS), and SH (Unix-based
systems).
 Archive Files: Used to compress one or more files into a single archive
for easier storage, transmission, or backup purposes. Popular archive file
formats include ZIP, RAR, and 7Z.
 System Files: Essential for operating system functionality and
configuration. Modifying them can impact system stability. These files
are typically hidden and protected by the operating system.

Explain File Allocation methods?

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:

1. Contiguous Allocation (3 marks)

 Concept: Stores all blocks of a file contiguously (adjoining) on the disk.


 Advantages (2 marks):
o Fast access: Direct calculation of block addresses based on starting
block and file size.
o Efficient for sequential access: Minimizes disk head movement for
reading or writing large files sequentially.
 Disadvantages (2 marks):
o External fragmentation: Over time, free space becomes fragmented
as files are created and deleted, leaving unusable pockets between
allocated blocks.
o Difficulty in growing files: Requires finding a large enough
contiguous space to accommodate the entire file, even if smaller
free spaces are available.
2. Linked Allocation (3 marks)

 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:

 Predominant file access patterns (sequential vs. random): Contiguous


allocation is better for sequential access, while indexed allocation offers a
balance for both.
 Average file size: Contiguous allocation might not be suitable for very
large files due to fragmentation concerns.
 Disk space utilization: Linked allocation

What are the major jobs of OS regarding file management?

1. File Creation and Deletion:


 The OS allows creation of new files by allocating space for them on the
storage device and creating directory entries to reference them.
 It also enables deletion of files, which involves releasing the allocated
space and potentially removing directory entries (unless hard links are
involved).

2. File Attributes Management:

 The OS maintains various attributes associated with each file, including:


o Name: Human-readable identifier for the file.
o Identifier: Unique tag (often a number) for internal file tracking.
o Type: Classification of the file based on its content (text, image,
etc.).
o Location: Pointer to the device and location of the file's data
blocks.
o Size: Current size of the file and potentially the maximum allowed
size.
o Protection: Access control information specifying read, write,
execute permissions for different users.
o Timestamps: Information about file creation, last modification, and
last access for security and monitoring purposes.

3. File Operations:

 The OS provides system calls for various file operations:


o Opening: Establishes a file handle for subsequent operations,
verifying file existence, permissions, etc.
o Reading: Reads data from the file into memory, maintaining a read
pointer to track the location for sequential reads.
o Writing: Writes data from memory to the file, maintaining a write
pointer for sequential writes.
o Repositioning (Seeking): Moves the read/write pointer within the
file to a specific location.
o Truncating: Erases the file contents but keeps its attributes (except
size), essentially resetting the file size to zero.

4. Directory Management:

 The OS organizes files in a hierarchical structure using directories.


 It enables creating, deleting, and renaming directories.
 It keeps track of file-directory relationships, allowing users to access files
through their directory paths.

5. File System Management:


 The OS oversees the overall file system, which is a logical structure for
organizing files on storage devices.
 It handles tasks like:
o Mapping logical file names to physical locations on the disk.
o Allocating and managing disk space for files (using methods like
contiguous, linked, or indexed allocation).
o Handling fragmentation issues that arise due to file creation and
deletion over time.

6. Security and Access Control:

 The OS enforces access control mechanisms to protect files from


unauthorized access.
 It uses file permissions to determine who can read, write, or execute a
particular file.

What are the problems when files are mounted simultaneously at more
than one place?

Mounting a file system essentially attaches it to a specific mount point in the


directory tree, making it accessible to the user. However, attempting to mount
the same file system simultaneously at multiple mount points can lead to several
issues:

1. Data Inconsistencies (4 marks):

 Concept: When a file system is writable and mounted at multiple


locations, changes made from one mount point might not be reflected in
the other(s) due to:
o Asynchronous Writes: The operating system might buffer writes
before physically updating the storage device. Writes from one
mount might not be flushed immediately, leading to inconsistencies
if another mount reads the file before the update.
o Caching: The OS or applications might cache file data.
Modifications from one mount point might not invalidate the cache
in other locations, resulting in outdated data being accessed.
 Example (2 marks): Imagine a file named "report.txt" mounted at
both /data/reports and /home/user/projects/report.txt. A user edits the file
at /data/reports, but the OS hasn't flushed the changes to disk yet. Another
user accessing the file from /home/user/projects/report.txt might see an
outdated version.

2. Resource Confusion and Access Conflicts (3 marks):


 Concept: Multiple mount points for the same file system can lead to
confusion about which files and directories are being accessed. This can
cause issues like:
o Overwriting Files: Accidental overwriting of the same file from
different mount points can lead to data loss.
o Incorrect Permissions: If access control lists (ACLs) are set on
the file system, they might only be applied at one mount point,
leading to unintended access permissions at others.
o Directory Conflicts: If the mounted file system contains
directories that already exist in the mount point's location, it can
cause unexpected behavior or errors.
 Example (1 mark): A shared file system containing user home
directories is mounted on two different machines (server1 and server2). A
user logs in on server1 and starts working on a file. If the same file
system is accidentally mounted on server2 at the same location, another
user logging in there might access or modify the same file, potentially
causing conflicts.

Preventing these problems (2 marks):

 Operating systems typically prevent mounting the same file system at


multiple locations simultaneously.
 For specific scenarios where shared access is required, specialized file
systems or network-attached storage (NAS) solutions are designed to
handle concurrent access and data consistency.

You might also like