0% found this document useful (0 votes)
3 views37 pages

Unit IV - File Management

The document discusses file management in operating systems, covering concepts such as file attributes, operations, types, and access methods. It details various directory structures, including single-level, two-level, tree-structured, and acyclic graph directories, along with allocation methods like contiguous, linked, and indexed allocation. Additionally, it explores free space management and directory implementation techniques using linked lists and hash tables.

Uploaded by

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

Unit IV - File Management

The document discusses file management in operating systems, covering concepts such as file attributes, operations, types, and access methods. It details various directory structures, including single-level, two-level, tree-structured, and acyclic graph directories, along with allocation methods like contiguous, linked, and indexed allocation. Additionally, it explores free space management and directory implementation techniques using linked lists and hash tables.

Uploaded by

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

Operating Systems

Unit IV
File Management

06-05-2025 ©Operating Systems @ Srilakshmi V 1


File Concept

• The OS abstracts from the physical properties of its storage devices to define a
logical storage unit, the file.

• File is a named collection of related information that is recorded on a secondary


storage.

• Structure of File may be Text, Source, Object and an Executable file.

06-05-2025 ©Operating Systems @ Srilakshmi V 2


File Attributes

• Name - Some systems give special significance to names, and particularly extensions (
.exe, .txt, etc. ), and some do not. Some extensions may be of significance to the OS ( .exe
), and others only to certain applications ( .jpg )

• Identifier ( e.g. inode number )

• Type - Text, executable, other binary, etc.

• Location - on the hard drive.

• Size

• Protection

• Time & Date

• User ID
06-05-2025 ©Operating Systems @ Srilakshmi V 3
File Operations

• The file ADT supports many common operations:

• Creating a file

• Writing a file

• Reading a file

• Repositioning within a file

• Deleting a file

• Truncating a file.

06-05-2025 ©Operating Systems @ Srilakshmi V 4


File Types

06-05-2025 ©Operating Systems @ Srilakshmi V 5


Internal File Structure

• Disk files are accessed in units of physical blocks, typically 512 bytes or some
power-of-two multiple thereof.

• Internally files are organized in units of logical units.

• The number of logical units which fit into one physical block determines
its packing and has an impact on the amount of internal fragmentation
( wasted space ) that occurs.

• As a general rule, half a physical block is wasted for each file, and the larger the
block sizes the more space is lost to internal fragmentation.

06-05-2025 ©Operating Systems @ Srilakshmi V 6


Access Methods

• Sequential Access

• Direct Access

• Other Access Methods

06-05-2025 ©Operating Systems @ Srilakshmi V 7


Sequential Access

• A sequential access file emulates magnetic tape operation, and generally


supports a few operations:

• read next - read a record and advance the tape to the next position.

• write next - write a record and advance the tape to the next position.

• rewind

• skip n records - May or may not be supported.

06-05-2025 ©Operating Systems @ Srilakshmi V 8


Sequential Access

06-05-2025 ©Operating Systems @ Srilakshmi V 9


Direct Access

• Jump to any record and read that record.

• Operations supported include:

• read n - read record number n.

• write n - write record number n.

• jump to record n - could be 0 or the end of file.

• Query current record - used to return back to this record later.

• Sequential access can be easily emulated using direct access.

• The inverse is complicated and inefficient.

06-05-2025 ©Operating Systems @ Srilakshmi V 10


Simulation of Sequential access on a direct access fileq

06-05-2025 ©Operating Systems @ Srilakshmi V 11


Other Access Methods

• An indexed access scheme can be easily built on top of a direct access system.
• Very large files may require a multi-tiered indexing scheme, i.e. indexes of
indexes.

06-05-2025 ©Operating Systems @ Srilakshmi V 12


File System Organization

• A disk can be used in its entirety for a file system.

• Alternatively a physical disk can be broken up into multiple partitions,


slices, or mini-disks, each of which becomes a virtual disk and can have
its own filesystem. ( or be used for raw storage, swap space, etc. )

• Or, multiple physical disks can be combined into one volume, i.e. a
larger virtual disk, with its own filesystem spanning the physical disks.

06-05-2025 ©Operating Systems @ Srilakshmi V 13


File System Organization

06-05-2025 ©Operating Systems @ Srilakshmi V 14


Directory Overview

• Directory operations to be supported include:

• Search for a file

• Create a file - add to the directory

• Delete a file - erase from the directory

• List a directory - possibly ordered in different ways.

• Rename a file - may change sorting order

• Traverse the file system.

06-05-2025 ©Operating Systems @ Srilakshmi V 15


Single Level Directory

• A single directory for all user called the root directory.

Pros: Simple, easy to quickly locate files

Cons: inconvenient naming (uniqueness), no grouping

06-05-2025 ©Operating Systems @ Srilakshmi V 16


Two Level Directory

• Each user gets their own directory space.

• File names only need to be unique within a given user's directory.

• A master file directory is used to keep track of each users directory, and must be
maintained when users are added to or removed from the system.

• Systems may or may not allow users to access other directories besides their
own

• A search path is the list of directories in which to search for executable


programs, and can be set uniquely for each user.

06-05-2025 ©Operating Systems @ Srilakshmi V 17


Two Level Directory

06-05-2025 ©Operating Systems @ Srilakshmi V 18


Tree Structured Directories

• An obvious extension to the two-tiered directory structure, and the one


with which we are all most familiar.

• Each user / process has the concept of a current directory from which
all ( relative ) searches take place.

• Files may be accessed using either absolute pathnames ( relative to the


root of the tree ) or relative pathnames ( relative to the current directory. )

• One question for consideration is whether or not to allow the removal of


directories that are not empty.
06-05-2025 ©Operating Systems @ Srilakshmi V 19
Tree Structured Directories

06-05-2025 ©Operating Systems @ Srilakshmi V 20


Acyclic Graph Directories
• When the same files need to be accessed in more than one place in the directory structure ,it
can be useful to provide an acyclic-graph structure.

• UNIX provides two types of links for implementing the acyclic-graph structure.

• A hard link ( usually just called a link ) involves multiple directory entries that both refer to
the same file.

• A symbolic link, that involves a special file, containing information about where to find the
linked file.

• Windows only supports symbolic links, termed shortcuts.

• Hard links require a reference count, or link count for each file, keeping track of how many
directory entries are currently referring to this file.

• Whenever one of the references is removed the link count is reduced, and when it reaches zero,
the disk space can be reclaimed.

06-05-2025 ©Operating Systems @ Srilakshmi V 21


Acyclic Graph Directory

06-05-2025 ©Operating Systems @ Srilakshmi V 22


General Graph Directory

06-05-2025 ©Operating Systems @ Srilakshmi V 23


Allocation Methods

• An allocation method refers to how disk blocks are allocated for files:

• Contiguous allocation – each file occupies set of contiguous blocks

• Best performance in most cases

• Simple – only starting location (block #) and length (number of blocks)


are required

• Problems include finding space for file, knowing file size, external
fragmentation, need for compaction

06-05-2025 ©Operating Systems @ Srilakshmi V 24


Contiguous Allocation

• Mapping from logical to physical

• Block to be accessed = Q + starting address

06-05-2025 ©Operating Systems @ Srilakshmi V 25


Linked Allocation

• Each file is a linked list of disk blocks: blocks may be scattered anywhere
on the disk

06-05-2025 ©Operating Systems @ Srilakshmi V 26


File Allocation Table

06-05-2025 ©Operating Systems @ Srilakshmi V 27


Indexed Allocation

• Each file has its own index block(s) of pointers to its data blocks

• Logical view

06-05-2025 index table


©Operating Systems @ Srilakshmi V 28
Indexed Allocation

06-05-2025 ©Operating Systems @ Srilakshmi V 29


Indexed Allocation - Mapping

06-05-2025 ©Operating Systems @ Srilakshmi V 30


Free Space Management

• File system maintains free-space list to track available blocks/clusters


• (Using term “block” for simplicity)
• Bit vector or bit map (n blocks)
• Block number calculation

0 1 2 n-1
(number of bits per word) *

(number of 0-value words) +
offset of first 1 bit


1  block[i] free
bit[i] =
0  block[i] occupied

06-05-2025 ©Operating Systems @ Srilakshmi V 31


Linked Free Space List

Linked list (free list)

Cannot get contiguous space easily

No waste of space

No need to traverse the entire list (if # free) blocks recorded)

06-05-2025 ©Operating Systems @ Srilakshmi V 32


Grouping and Counting

• Grouping
• Modify linked list to store address of next n-1 free blocks in first free block,
plus a pointer to next block that contains free-block-pointers (like this one)

• Counting
• Because space is frequently contiguously used and freed, with contiguous-
allocation allocation, extents, or clustering
• Keep address of first free block and count of following free blocks
• Free space list then has entries containing addresses and counts

06-05-2025 ©Operating Systems @ Srilakshmi V 33


Directory Implementation
Using Single Linked List:
The implementation of directories using a singly linked list is easy to program but is
time-consuming to execute. Here we implement a directory by using a linear list of
filenames with pointers to the data blocks.
• To create a new file the entire list has to be checked such that the new directory does
not exist previously.

• The new directory then can be added to the end of the list or at the beginning of the
list.

• In order to delete a file, we first search the directory with the name of the file to be
deleted. After searching we can delete that file by releasing the space allocated to it.

• To reuse the directory entry we can mark that entry as unused or we can append it
to the list of free directories.

• To delete a file linked list is the best choice as it takes less time.

06-05-2025 ©Operating Systems @ Srilakshmi V 34


Directory Implementation
Using Single Linked List:
Disadvantage
• The main disadvantage of using a linked list is that when the user needs to find
a file the user has to do a linear search. In today’s world directory information is
used quite frequently and linked list implementation results in slow access to a
file.

07-05-2025 ©Operating Systems @ Srilakshmi V 35


Directory Implementation
Using Hash Table:
• An alternative data structure that can be used for directory implementation is
a hash table. It overcomes the major drawbacks of directory implementation
using a linked list.

• In the hash table for each pair in the directory key-value pair is generated. The
hash function on the file name determines the key and this key points to the
corresponding file stored in the directory.

• This method efficiently decreases the directory search time as the entire list will
not be searched on every operation. Using the keys the hash table entries are
checked and when the file is found it is fetched.

07-05-2025 ©Operating Systems @ Srilakshmi V 36


Directory Implementation
Using Hash Table:
Disadvantage:
• The major drawback of using the hash table is that generally, it has a
fixed size and its dependency on size. But this method is usually faster
than linear search through an entire directory using a linked list.

07-05-2025 ©Operating Systems @ Srilakshmi V 37

You might also like