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

Chapter File Allocation Methods and Free Space Management

FIle allocation

Uploaded by

PRINCE RAJ
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Chapter File Allocation Methods and Free Space Management

FIle allocation

Uploaded by

PRINCE RAJ
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 36

Chapter: File-System Interface

File Management

• Process of storing, Controlling, Managing data stored on


secondary storage in the form of files.

• File Management:
– Ensure consistency of data when multiple users access the files
– Provides measures for file security and protection
File Concept
• File is a sequence of bits, bytes, lines, or records, the
meaning of which is defined by the file’s creator and user.
• Field
• Record
• File
• Data Base
File Attributes
• Name – Name is usually a string of characters
• Identifier – unique tag (number) identifies file within file
system
• Type – needed for systems that support different types
• Location – pointer to file location on device
• Size – current file size
• Protection – Access Permissions, controls who can do
reading, writing, executing
• Time, date, and user identification – data for protection,
security, and usage monitoring
• Information about files are kept in the directory structure,
which is maintained on the disk
File Operations
All operations involve some system calls
1. Create: using a specific system call. Two steps are
necessary to create a file.
2. Open a file
3. Delete a file
4. Write in to file
5. Close
6. Reposition within file
Directory Structure
• Symbol table of files that stores all related information about a
file it holds with its contents

Directory

F1 F2 F3 F4
Fn
Files

Both the directory structure and the files reside on disk


Backups of these two structures are kept on tapes
Operations Performed on Directory
Directory: collection of files or directories
• A Symbol Table that translates file names into their directory
entry.

Operations:
• Search for a file
• Create a file
• Delete a file
• List a directory
• Rename a file
• Traverse the file system : Search all directories/ sub directories
and files
Directory Schemes
1. Single Level Directory
One directory many files

Single-Level Directory

Easy to support and understand.


Disadvantage:
Limitation:
1.When
Difficult to remember
number of filesthe name of or
increases files whenthe
when filessystem
increases
has
2.more than
Single one user,
directory for all then
usersNaming problem occurs. All files
3.should have created
File names uniqueby names.
different users should be different.
Two Level
• 2. Two level directory, each user has his own user file
directory(UFD).

• UFDs have the similar structure, but each lists files of a single user.
Tree Structure
• Users can create their sub directories to manage the files.
• Three has Root directory and files have unique file names
Paths
• Absolute Path: Begins at the root and follows a path down to the
specified file giving directory names on the path.

• Relative Path: Defines a path from the current directory.

• Creating a new file is done in current directory


Acyclic-Graph Directories

• Multiple users can Have shared subdirectories and files


• Users have their own working directory and may have
one shared directory
• Shared subdirectory created by one user in one directory is
automatically visible to all users sharing that directory.
• Shared directory or file may exist at multiple places
simultaneously
• Because of sharing, a file may have multiple absolute
paths
• So different names can refer to same file
Acyclic-Graph Directories
General Graph Directories
• Created by adding links to the existing directory
• Allows cycles in the same directory

• As all files are dependent / linked deleting a main file may


harm other files

• In case of deletion: Garbage Collection is used


• In First Pass: Traversing the entire file and marking everything
that can be accessed

• In Second Pass: Collect everything that is not marked as the


free space
General Graph Directories
• There can be cycle in the directory arrangement

General Graph Directory


Directory Implementation
1. Linear List

• In this algorithm, all the files in a directory are maintained


as singly linked list.
• Each file contains the pointers to the data blocks which are
assigned to it and the next file in the directory.
• When a new file is created, then the entire list is checked
whether the new file name is matching to a existing file
name or not.
• In case, it doesn't exist, the file can be created at the
beginning or at the end. Therefore, searching for a unique
name is a big concern because traversing the whole list
takes time.
Directory Implementation
1. Linear List

• The list needs to be traversed in case of every operation


(creation, deletion, updating, etc) on the files therefore the
systems become inefficient.
Directory Implementation
2. Hash Table

•To overcome the drawbacks of singly linked list


implementation of directories, there is an alternative approach
that is hash table.
•This approach suggests to use hash table along with the linked
lists.
•A key-value pair for each file in the directory gets generated
and stored in the hash table.
•The key can be determined by applying the hash function on
the file name.
Directory Implementation
2. Hash Table

Now, entire list will not be searched on every operating.

Only hash table entries are checked using the key and if an
entry found then the corresponding file will be fetched using
the value.
Allocation Methods
• Files are stored on disk

• Main Issue is: how to allocate space to these files so that


disk space is utilized effectively and file can be accessed
quickly.

• There are three major methods of storing files on disks:


– Contiguous file allocation
– Linked file allocation
– Indexed file allocation
Allocation Methods
1. Contiguous File Allocation
• File occupy contiguous blocks
• Directory entry contains: Filename, Starting block , Length (total
blocks)
• File Access possible: Sequential of data, Direct access of data

• Problems:
• Finding space for new file
• External fragmentation
• Determining space requirement of a file
Allocation Methods
1. Contiguous File Allocation
Contiguous Allocation
• Problems can arise:
– Finding space for a new file
– When files grow
– if the exact size of a file is
unknown at creation time
– Suffers from problem of
external fragmentation.
– Difficult to know how much
space is needed for a file
Linked Allocation
• Each file is a linked list of disk blocks
• Disk blocks can be scattered any where in disk
• Directory contains a pointer to first and last block of the
file.
• Exp: if file of 5 blocks might start at block 9, continue at
block 16, then block 1, block 10 and finally block 25.
• Each block contains a pointer to next block.
• To create a new file , create a new entry in directory
• Each directory has a entry has a pointer to first disk
block of file.
• Pointer is initialized to NIL and size / data part is set to 0
Linked Allocation
• Disk files can be stored as linked lists
• Linked allocation does not require pre-known file
sizes, and allows files to grow dynamically at any time.

Drawback
• It is efficient for sequential access files
• To find ith block of a file, we must start at the beginning
of that file and follow the pointers until we go to ith block.
• Requires extra space for pointers

• Problem with linked allocation is reliability:


– If a pointer is lost or damaged
Linked Allocation
Indexed Allocation
• Indexed Allocation combines all of the indexes for accessing file in a
file.
• Create a table of indexes
• Index file contains pointers to blocks.
• Bring all the pointers together into one location : Index Block
• Each ith entry in index block points to ith block of the file
• Create index of linked locations
• Indexed allocation support Direct Access.
– Any free space on the disk can be used for allocation
– Removes external fragmentation
Indexed Allocation
• Advantages:
– Any free space on the disk can be used for allocation
– Removes external fragmentation
• Disadvantages:
– If index block is small, it will not be able to hold enough
pointers
– Entire index will have to be kept in main memory to
make it work
Indexed Allocation

-1 entry in block 19 means it can contain


entries to two other data blocks.
Methods to implement free space list
Bit Map or Bit Vector
• Each block is represented by a bit
• If block is free, bit is set to 1 otherwise 0
Linked List
• Linked list of all the free blocks is maintained
• First free block in the list can be pointed by the head
pointer

• Disadvantage: Traversing is time consuming


Grouping
Grouping

• Store addresses of n free blocks in the first free block


• The first n-1 out of these are free while nth block contains addresses
of another n free blocks.

E.g., Block 2 contains address of next 5 free blocks (3, 4, 5, 9, 10) out of
which blocks 3, 4, 5 and 9 are free while block 10 contains the
address of next five free blocks.
Grouping
4. Counting:
This method keeps the address of first free block and number of free
contiguous blocks that follow the free block.
MCQ

The data structure used to implement directory


is____________
a) mount table
b) hash table
c) file table
d) process table
MCQ

If the block of free-space list is free then bit will


____________
a) 1
b) 0
c) any of 0 or 1
d) none of the mentioned
MCQ

What will happen in the single level directory?


a) All files are contained in different directories all at the
same level
b) All files are contained in the same directory
c) Depends on the operating system
d) None of the mentioned

You might also like