[go: up one dir, main page]

0% found this document useful (0 votes)
16 views11 pages

Group Assignments

Sequential File Allocation is a method for organizing files on storage media by storing them contiguously, which simplifies implementation and allows for efficient sequential access. However, it suffers from limitations such as fragmentation, restricted file size due to contiguous storage requirements, and inefficiencies in random access. Modern file systems often utilize more advanced allocation strategies to address these issues and enhance performance.

Uploaded by

tekle24walle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

Group Assignments

Sequential File Allocation is a method for organizing files on storage media by storing them contiguously, which simplifies implementation and allows for efficient sequential access. However, it suffers from limitations such as fragmentation, restricted file size due to contiguous storage requirements, and inefficiencies in random access. Modern file systems often utilize more advanced allocation strategies to address these issues and enhance performance.

Uploaded by

tekle24walle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Sequential File Allocation is a strategy used in computer file

systems to allocate and organize files on storage media such


as hard disk drives. It is a simple and straightforward method
where files are stored contiguously on the disk, one after
another, without any gaps.

In sequential file allocation, when a file is created, the


operating system finds a suitable location on the disk where
the entire file can be stored in a continuous block of space.
The starting address of the file and its length are recorded in
the file's directory entry or File Control Block (FCB).

This file allocation strategy has a few characteristics:

1. Contiguity: Sequential file allocation


ensures that files are stored contiguously on the disk. This
means that the file's data blocks are physically adjacent to
each other, making it easy to read or write the entire file
sequentially.

2. Simple Implementation: Sequential file allocation is


relatively simple to implement compared to other allocation
strategies, such as linked allocation or indexed allocation. The
operating system only needs to keep track of the starting
address and length of each file.

3. Efficient Sequential Access: Sequential file allocation is


efficient for accessing files sequentially. Since the files are
stored contiguously, it is easy to read or write the entire file
sequentially without the need for frequent disk head
movement.
However, sequential file allocation has some limitations:

1. Fragmentation: As files are continuously added, modified,


and deleted, free space on the disk becomes fragmented.
This fragmentation can lead to inefficient utilization of disk
space, as free space may be scattered throughout the disk,
making it challenging to find contiguous blocks for new files.

2. Limited File Size: Since files are stored contiguously, the


maximum size of a file is limited by the largest contiguous
block of free space available on the disk. If the disk becomes
fragmented, it may be challenging to find a single contiguous
block large enough to accommodate large files.
3. Inefficient Random Access: Randomly accessing data
within a file can be inefficient in sequential file allocation. If a
file needs to be accessed randomly, the disk head may need
to move back and forth between different parts of the disk,
resulting in slower access times.

While sequential file allocation is simple and suitable for


certain applications, modern file systems often employ more
advanced allocation strategies, such as linked allocation or
indexed allocation, to overcome the limitations of sequential
allocation and improve overall performance and flexibility.

#include <iostream>
#include <string>
#include <vector>
#include <iomanip> // For setw() function

struct File {
std::string name;
int size;
int startAddress;
};

void allocateFile(std::vector<File>& files, int maxDiskSize) {


std::string name;
int size;

std::cout << "Enter the name of the file: ";


std::cin >> name;

std::cout << "Enter the size of the file in bytes: ";


std::cin >> size;

int startAddress = 0;
if (!files.empty()) {
startAddress = files.back().startAddress +
files.back().size;
}

if (startAddress + size > maxDiskSize) {


std::cout << "Not enough space on disk to allocate the
file." << std::endl;
return;
}

files.push_back({name, size, startAddress});


std::cout << "File allocated successfully." << std::endl;
}

void updateFile(std::vector<File>& files) {


std::string name;
std::cout << "Enter the name of the file to update: ";
std::cin >> name;

bool foundFile = false;


for (File& file : files) {
if (file.name == name) {
std::cout << "Enter the new size of the file in bytes: ";
std::cin >> file.size;
std::cout << "File updated successfully." << std::endl;
foundFile = true;
break;
}
}

if (!foundFile) {
std::cout << "File not found." << std::endl;
}
}
void displayFiles(const std::vector<File>& files) {
std::cout << "File Allocation Table:" << std::endl;
std::cout <<" "<< "-------------------------------------------" <<
std::endl;

// Print table headers


std::cout << std::setw(10)<<" " << "File Name" <<" "<<
std::setw(10) << "Size (bytes)" << " "<< std::setw(10) <<
"Start Address" << std::endl;
std::cout <<" "<< "--------------------------------------------" <<
std::endl;

// Print table rows


for (const File& file : files) {
std::cout << std::setw(15) << file.name <<" "<<
std::setw(10) << file.size <<" "<< std::setw(15) <<" "<<
file.startAddress << std::endl;
}

std::cout <<" "<<


"-------------------------------------------‐--------" << std::endl;
}

int main() {
int maxDiskSize;
std::cout << "Enter the maximum size of the disk in bytes:
";
std::cin >> maxDiskSize;

std::vector<File> files;

char choice;
do {
std::cout << "\n1. Allocate a file\n";
std::cout << "2. Update file allocation\n";
std::cout << "3. Display the file
allocation table\n";
std::cout << "4. Exit\n";
std::cout << "Enter your choice: ";
std::cin >> choice;

switch (choice) {
case '1':
allocateFile(files, maxDiskSize);
break;

case '2':
updateFile(files);
break;

case '3':
displayFiles(files);
break;

case '4':
std::cout << "Exiting..." << std::endl;
break;
default:
std::cout << "Invalid choice" << std::endl;
break;
}
} while (choice != '4');

return 0;
}

You might also like