OSY Chapter 6 Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Chapter 6

File Management

Define File
In Operating Systems (OS), a file is a collection of related data or information
that is stored on a computer's storage device, such as a hard drive, solid-state drive,
or flash drive.

File Operations

1. Create: Make a new file.


2. Delete: Remove an existing file.
3. Read: Access and view file contents.
4. Write: Modify or add to file contents.
5. Rename: Change the name of an existing file.
6. Copy: Duplicate a file to another location.
7. Move: Relocate a file to a different directory or location.
8. Append: Add new data to the end of an existing file.
9. Edit: Modify the contents of a file.
10. View: Display the contents of a file without modifying it.
11. Search: Find a specific file or files based on criteria like name, size, or date.
12. Sort: Organize files in a directory based on criteria like name, size, or date.
13. Merge: Combine multiple files into a single, larger file.
File Attributes
File Types
1. Regular Files
2. Directories
3. Character Special File
4. Block Special File

File System Structure

1. Unstructured sequence of bytes

 In this structuring operating system treats


content of the file as sequence of bytes.

 This structuring provides more flexibility


 any types of content can be kept in file

2. Sequence of fixed length records

 In this structuring operating system treats


content of the file as sequence of fixed
length records
 Each records has it’s internal structure

3. Tree Structure

 In this organization a file consists of the


records which are organized in tree
structure

 All the records are not necessarily same


length

 The records in the tree are arranged in the


sorted order
File Access Methods
File Allocation Methods

What is File Allocation in OS?


Whenever a hard disk is formatted, a system has many small
areas called blocks or sectors that are used to store any kind of
file. File allocation methods are different ways by which the
operating system stores information in memory blocks, thus
allowing the hard drive to be utilized effectively and the file to be
accessed. Below are the types of file allocation methods in the
Operating System.
Types of File Allocation Methods in Operating System.
 Contiguous File allocation
 Linked File Allocation
 Indexed File Allocation

Contiguous File allocation


If the blocks are allocated to the file in such a way that all
the logical blocks of the file get the contiguous physical block in
the hard disk then such allocation scheme is known as contiguous
allocation.
Contiguous allocation is a file allocation method where each
file is stored in a single contiguous block of disk space. This
means that all the blocks occupied by a file are next to each other
on the disk.

The primary advantage of contiguous allocation is its


simplicity and efficiency in accessing files. Since the entire file is
stored in a single continuous block, the system can quickly locate
and read the file sequentially, leading to high performance for
sequential file access.
The major drawback of contiguous allocation is the problem
of external fragmentation, where free space is scattered in small,
non-contiguous blocks. This makes it difficult to find large
contiguous spaces for new files, leading to insufficient disk space
utilization. Additionally, resizing files can be problematic, as
there may not be enough contiguous space available to
accommodate the new size.
Every file will contain a directory entry with the information
listed below:
1. Location of the starting block
2. File space requirements in terms of memory blocks (length)

The file ‘mail’ in the following figure starts from the block 19
with length = 6 blocks. Therefore, it occupies 19, 20, 21, 22,
23, 24 blocks.

The file ‘list’ in the following figure starts from the block 28
with length = 4 blocks. Therefore, it occupies 28,29,30,31
blocks.

Advantages

 It is very easy to implement


 There is a minimum amount of seek time
 Memory access is faster
 It supports sequential as well as direct access
Disadvantages
 At the time of creation, the file size must be initialized.
 As it is pre-initialized, the size cannot increase.
 External Fragmentation occurs
 It may be difficult to have a file grow.
Directory Structure

A directory is a container that is used to contain folders and


files. It organizes files and folders in a hierarchical manner. In
other words, directories are like folders that help organize files on
a computer.

Single-Level Directory

 The single-level directory is the simplest directory


structure. In it, all files are contained in the same directory
which makes it easy to support and understand.

 The single directory is also called as Root Directory

 A single level directory has a significant limitation i.e. when


the all the files are in the same directory, they must have
a unique name.
Advantages
 Since it is a single directory, so its implementation is very easy.
 If the files are smaller in size, searching will become faster.
 The operations like file creation, searching, deletion, updating are very
easy in such a directory structure.

Disadvantages
 There may chance of name collision because two files can have the same
name.
 Searching will become time taking if the directory is large.
 Difficult to remember names of each file when there are large amount of
files in a directory

Two-Level Directory

 As we have seen, a single level directory often leads to


confusion of files names among different users. The solution
to this problem is to create a separate directory for each
user.

 In the two-level directory structure, each user has their


own user files directory (UFD).

 All the UFDs have similar structures, but each lists contain
only the files of a single user.
 System’s master file directory (MFD) is searched
whenever a new user id is created.
Advantages
 The main advantage is there can be more than two files with same
name, and would be very helpful if there are multiple users.
 A security would be there which would prevent user to access other
user’s files.
 Searching of the files becomes very easy in this directory structure.

Disadvantages
 As there is advantage of security, there is also disadvantage that the
user cannot share the file with the other users.
 Unlike the advantage users can create their own files, users don’t have
the ability to create subdirectories.
Tree Structure Directory

 Tree directory structure of operating system is most commonly


used in our personal computers. User can create files and
subdirectories too, which was a disadvantage in the previous
directory structures.

 In this directory structure the root directory is at the peak.

 This root contains all the directories for each user. The users can
create subdirectories and even store files in their directory.

 A user do not have access to the root directory data and cannot
modify it. And, even in this directory the user do not have access
to other user’s directories.

 The structure of tree directory is given below which shows how


there are files and subdirectories in each user’s directory.
Advantages
 This directory structure allows subdirectories inside a directory.
 The searching is easier.
 File sorting of important and unimportant becomes easier.
 This directory is more scalable than the other two directory structures
explained.

Disadvantages
 As the user isn’t allowed to access other user’s directory, this prevents
the file sharing among users.
 As the user has the capability to make subdirectories, if the number of
subdirectories increase the searching may become complicated.
 Users cannot modify the root directory data.
Disk Structure

RAID (Redundant Array of Independent Disks) is a


data storage technology that combines multiple
physical disks into a single logical unit to improve
data reliability, performance, and capacity.

RAID Structures:

1. RAID 0 (Striping): Data is split across multiple


disks to improve performance, but there is no
redundancy.

2. RAID 1 (Mirroring): Data is duplicated on two


or more disks to provide redundancy, but it's not
suitable for large data sets.

3. RAID 5 (Striping with Parity): Data is split


across multiple disks, and parity information is
calculated and stored to provide redundancy.

4. RAID 6 (Striping with Dual Parity): Similar to


RAID 5, but with an additional parity block to
provide even greater redundancy.

You might also like