0% found this document useful (0 votes)
6 views17 pages

Unit 5 Notes

The document provides an overview of file management, including file systems, file operations, and various file allocation methods. It discusses the importance of files for long-term information storage, different file access methods (sequential, direct, indexed), and the structure of directories. Additionally, it outlines the advantages and disadvantages of various file allocation techniques such as contiguous, linked, indexed, and inode-based allocation.

Uploaded by

Ajit kumar
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)
6 views17 pages

Unit 5 Notes

The document provides an overview of file management, including file systems, file operations, and various file allocation methods. It discusses the importance of files for long-term information storage, different file access methods (sequential, direct, indexed), and the structure of directories. Additionally, it outlines the advantages and disadvantages of various file allocation techniques such as contiguous, linked, indexed, and inode-based allocation.

Uploaded by

Ajit kumar
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/ 17

File Management

Files and File Systems


●​ Every application needs to access and store the information.
●​ The Execution process can keep the information in its address space.
●​ DBMS
●​ Necessities for long term information storage.
○​ To store a very large amount of information.
○​ Information should not be lost after termination of process.
○​ Access information simultaneously
●​ Store information on disks and other secondary storage in units called Files.
●​ A file is a named collection of related information that is recorded on secondary storage.
●​ File System describes how files are structured,named,accessed,used,protected and
implemented..

Files
●​ File naming:
○​ Process gives the name to the file when it creates it.
○​ The rules for file naming(not same for all systems).
○​ Upper and Lower case letters.
○​ File name divided into 2 parts: Name and extension.
○​ In Unix user has a choice of deciding the size of extension.
○​ In UNIX, file can have 2 or more extensions.
○​ The table shows examples of file extension, its meaning and type.

Extension Meaning Type

gif Graphical interchange format image

html Hypertext markup language Web page

obj Compiled machine language Object


exe Ready to execute machine language program executable

pdf Its content can not be changed Portable document


format

File Structure
1.​ Unstructured Sequence of bytes(Ordinary Files)
a.​ Any type of content can be kept in the file.
2.​ Sequence of fixed length records
a.​ Punched cards

b.​
3.​ Tree Structure

File Operations
●​ For storage and retrieval purpose, different types of systems offer different operations.
●​ For the operations like create, write, read operating system offer the system calls.

Common system call relating to files are listed below:

1.​ Create
2.​ Delete
3.​ Open
4.​ Close
5.​ Read
6.​ Write
7.​ Append
8.​ Seek
9.​ Get attributes
10.​ Set attributes
11.​ Rename

File Organization and Access


File Access

Types of File Access Methods in the Operating System


1. Sequential Access
The operating system reads the file word by word in a sequential access method of file accessing.
A pointer is made, which first links to the file's base address. If the user wishes to read the first
word of the file, the pointer gives it to them and raises its value to the next word. This procedure
continues till the file is finished. It is the most basic way of file access. The data in the file is
evaluated in the order that it appears in the file and that is why it is easy and simple to access a
file's data using a sequential access mechanism. For example, editors and compilers frequently
use this method to check the validity of the code.

Advantages of Sequential Access:

●​ The sequential access mechanism is very easy to implement.


●​ It uses lexicographic order to enable quick access to the next entry.

Disadvantages of Sequential Access:


●​ Sequential access will become slow if the next file record to be retrieved is not present
next to the currently pointed record.
●​ Adding a new record may need relocating a significant number of records of the file.

2. Direct (or Relative) Access


A Direct/Relative file access mechanism is mostly required with the database systems. In the
majority of the circumstances, we require filtered/specific data from the database, and in such
circumstances, sequential access might be highly inefficient. Assume that each block of storage
holds four records and that the record we want to access is stored in the tenth block. In such a
situation, sequential access will not be used since it will have to traverse all of the blocks to get
to the required record, while direct access will allow us to access the required record instantly.

The direct access mechanism requires the OS to perform some additional tasks but eventually
leads to much faster retrieval of records as compared to sequential access.

Advantages of Direct/Relative Access:

●​ The files can be retrieved right away with a direct access mechanism, reducing the
average access time of a file.
●​ There is no need to traverse all of the blocks that come before the required block to
access the record.
Disadvantages of Direct/Relative Access:

●​ The direct access mechanism is typically difficult to implement due to its complexity.
●​ Organizations can face security issues as a result of direct access as the users may
access/modify the sensitive information. As a result, additional security processes must
be put in place.

3. Indexed Sequential Access


It's the other approach to accessing a file that's constructed on top of the sequential access
mechanism. This method is practically similar to the pointer-to-pointer concept in which we
store the address of a pointer variable containing the address of some other variable/record in
another pointer variable. The indexes, similar to a book's index (pointers), contain a link to
various blocks present in the memory. To locate a record in the file, we first search the indexes
and then use the pointer-to-pointer concept to navigate to the required file.

Primary index blocks contain the links of the secondary inner blocks which contain links to the
data in the memory.

Advantages of Indexed Sequential Access:

●​ If the index table is appropriately arranged, it accesses the records very quickly.
●​ Records can be added at any position in the file quickly.
Disadvantages of Indexed Sequential Access:

●​ When compared to other file access methods, it is costly and less efficient.
●​ It needs additional storage space.
1.​
Five Fundamental of file organizations

1.​ The pile


a.​ Simply collect the data and save it.
b.​ Records contain same or different type of fields.
c.​ A pile file does not have any structure
d.​ Searching is difficult.
e.​ The complete file must be searched to locate all records of particular field and
value.
2.​ The sequential file
a.​ Records have fixed format
b.​ Each and every record in the file has same length
c.​ The first filed in each record is key field and is used to identify the record.
d.​ The sequential file physically can be organised as a linked list.
e.​ Each block on disk holds a pointer to the next block.
3.​ The indexed sequential file
a.​ Eliminate drawback of sequential file.
b.​ Contains indexed and overflow file.
c.​ In index file, each record contains 2 fields,Key field and pointer
d.​ Searching is easy.
4.​ The indexed file
a.​ Overcome drawback of indexed sequential file
b.​ In this, records are accessed only through their indexes.
c.​ Searching is easy
5.​ The Direct or hashed file.
a.​ A hashing operation is performed on the key value using hash function.

File Directories
●​ Directory Structure:
○​ Directories keep track of files.
○​ Directories are itself files in many system.
○​ In order to manage all these data, we need to organize them.

Common methods for defining the Logical structure of a directory

1.​ Single-level Directory Systems


2.​ Two-level Directory Systems
3.​ Hierarchical Directory Systems

Root Directory Home Directory

The root directory is the topmost level of the The home directory is a subdirectory of the root directory.
system drive.
It is denoted by a slash '/'. It is denoted by '~' and has path "/users/username".

The admin has access to make any changes in No user other than the root user can change the settings of
the files and settings. the entire system.

The admin can create a user. Any user having a home directory cannot create a user.

In the Linux file system, everything comes The home directory contains a particular user's data.
under the root directory.

Path Names
Types of path name

1.​ Absolute
2.​ Relative
Example:
File Sharing
●​ It is necessary to share a file among multiple users in a multiuser system.
●​ It needs to deal with two issues
○​ :that are access rights and
○​ the management of simultaneous access.
●​ Access Rights:
○​ It is important to grant particular access permissions or rights to users or groups of
users to access a particular file.
○​ Examples:
■​ None access right(Directory of file
■​ Knowledge(Owner of file)
■​ Execute
■​ Read
■​ Append
■​ Update
■​ Changing Protection
■​ Delete

_______________________________________________________________

File allocation techniques.​ ​ ​ ​

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 Systems.

●​ Contiguous File allocation


●​ Linked File Allocation
●​ Indexed File Allocation
●​ File Allocation Table (FAT)
●​ Inode

Contiguous File Allocation.

First, let's understand the meaning of contiguous, here contiguous means adjacent or touching.
Now let's understand contiguous file allocation.

What is Contiguous File allocation?

In contiguous file allocation, the block is allocated in such a manner that all the allocated blocks
in the hard disk are adjacent.

Assuming a file needs 'n' number of blocks in the disk and the file begins with a block at
position'x', the next blocks to be assigned to it will be x+1,x+2,x+3,...,x+n-1 so that they are in a
contiguous manner.

Let's understand this diagrammatically.

Example

We have three different types of files that are stored in a contiguous manner on the hard disk.
In the above image on the left side, we have a memory diagram where we can see the blocks of
memory. At first, we have a text file named file1.txt which is allocated using contiguous memory
allocation, it starts with the memory block 0 and has a length of 4 so it takes the 4 contiguous
blocks 0,1,2,3. Similarly, we have an image file and video file named sun.jpg and mov.mp4
respectively, which you can see in the directory that they are stored in the contiguous blocks.
5,6,7 and 9,10,11 respectively.

Here the directory has the entry of each file where it stores the address of the starting block and
the required space in terms of the block of memory.

Advantages and Disadvantages

Advantages

●​ It is very easy to implement.


●​ There is a minimum amount of seek time.
●​ The disk head movement is minimum.
●​ 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. As
●​ Due to its constrained allocation, it is possible that the disk would fragment internally or
externally.

Linked File Allocation.

What is Linked File Allocation?

The Linked file allocation overcomes the drawback of contiguous file allocation. Here the file
which we store on the hard disk is stored in a scattered manner according to the space available
on the hard disk. Now, you must be thinking about how the OS remembers that all the scattered
blocks belong to the same file. So as the name linked File Allocation suggests, the pointers are
used to point to the next block of the same file, therefore along with the entry of each file each
block also stores the pointer to the next block.

Let's understand this better diagrammatically by taking an example.

Example

Here we have one file which is stored using Linked File Allocation.

In the above image on the right, we have a memory diagram where we can see memory blocks.
On the left side, we have a directory where we have the information like the address of the first
memory block and the last memory block.

In this allocation, the starting block given is 0 and the ending block is 15, therefore the OS
searches the empty blocks between 0 and 15 and stores the files in available blocks, but along
with that it also stores the pointer to the next block in the present block. Hence it requires some
extra space to store that link.

Advantages and Disadvantages

Advantages

●​ There is no external fragmentation.


●​ The directory entry just needs the address of the starting block.
●​ The memory is not needed in contiguous form, it is more flexible than contiguous file
allocation.

Disadvantages

●​ It does not support random access or direct access.


●​ If pointers are affected so the disk blocks are also affected.
●​ Extra space is required for pointers in the block.

Indexed File Allocation.

What is Indexed File Allocation?

The indexed file allocation is somewhat similar to linked file allocation as indexed file allocation
also uses pointers but the difference is here all the pointers are put together into one location
which is called index block. That means we will get all the locations of blocks in one index file.
The blocks and pointers were spread over the memory in the Linked Allocation method, where
retrieval was accomplished by visiting each block sequentially. But here in indexed allocation, it
becomes easier with the index block to retrieve.

Let's take an example to explain this better.

Example

As shown in the diagram below block 19 is the index block which contains all the addresses of
the file named text1. In order, the first storage block is 9, followed by 16, 1, then 10, and 25. The
negative number -1 here denotes the empty index block list as the file text1 is still too small to
fill more blocks.
Advantages and Disadvantages

Advantages

●​ It reduces the possibilities of external fragmentation.


●​ Rather than accessing sequentially it has direct access to the block.

Disadvantages

●​ Here more pointer overhead is there.


●​ If we lose the index block we cannot access the complete file.
●​ It becomes heavy for the small files.
●​ It is possible that a single index block cannot keep all the pointers for some large files.

Inode.

In Operating systems based on UNIX, every file is indexed using Inode(information-node). The
inode is the special disk block that is created with the creation of the file system. This special
block is used to store all the information related to the file like name, authority, size, etc along
with the pointers to the other blocks where the file is stored.
Explanation

In this special block, some of its space is used to store the information related to the field as
mentioned above and the remaining space is used to store the addresses of blocks that contain the
actual file.

The first few pointers in Inode point to direct blocks, i.e they contain the addresses of the disk
blocks containing the file data. A few pointers in inode point to the indirect blocks. There are
three types of indirect blocks: single indirect, double indirect, and triple indirect.

A single indirect block contains nothing but the address of the block containing the file data, not
the file itself as shown in the figure below. Furthermore, the double indirect block points to the
pointers which again point to the pointers which point to the data blocks. Further, it goes in a
similar way for triple indirect block.

The diagrammatic representation of Inode is given below -

Advantages and Disadvantages

Advantages

●​ Accessibility of file becomes easy as all the information like metadata and block address
is stored inside inode.
●​ Read-write and creation timestamps are stored inside the inode.
●​ Filenames do not affect inodes. In other words, a single file can be copied and renamed
without losing its address.
Disadvantages

●​ All new files and folders will be rejected as soon as a file system runs out of inodes.
●​ Upon 100% utilization of inodes the system will start to notice OS restarting, data loss,
applications crashing, and more OS-related issues.

__________________________________________________________________________

You might also like