0% found this document useful (0 votes)
20 views36 pages

OS Chap 2

Uploaded by

Prajakta Mhaske
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)
20 views36 pages

OS Chap 2

Uploaded by

Prajakta Mhaske
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/ 36

FILE SYSTEM

MANAGEMENT
• A file is a named collection of related information that is recorded on
secondary storage such as magnetic disks, magnetic tapes and optical
disks.
• • In general, a file is a sequence of bits, bytes, lines or records whose
meaning is defined by the file's creator and user.
Attributes of a File
• Name : It is the only information which is in human-readable form.
• Identifier: The file is identified by a unique tag(number) within file
system.
• Type: It is needed for systems that support different types of files.
• Location: Pointer to file location on device.
• Size: The current size of the file.
• Protection : This controls and assigns the power of reading, writing,
executing.
• Time, date, and user identification: This is the data for protection,
security, and usage monitoring.
File Operations
• Creating a file: Two steps are necessary to create a file. First, space in the file system
must be found for the file. Second, an entry for the new file must be made in the
directory.
• Writing a file: To write a file, we make a system call specifying both the name of the
file and the information to be written to the file. Given the name of the file, the system
searches the directory to find the file's location. The system must keep a write pointer to
the location in the file where the next write is to take place. The write pointer must be
updated whenever a write occurs.
• Reading a file: To read from a file, we use a system call that specifies the name of the
file and where (in memory) the next block of the file should be put. Again, the directory
is searched for the associated entry, and the system needs to keep a read pointer to the
location in the file where the next read is to take place. Once the read has taken place,
the read pointer is updated.
• Repositioning within a file: The directory is searched for the appropriate entry, and
the current-file-position pointer is repositioned to a given value. Repositioning within a
file need not involve any actual I/O. This file operation is also known as a file seek.
• Deleting a file. To delete a file, we search the directory for the named
file. Having found the associated directory entry, we release all file
space, so that it can be reused other files, and erase the directory
entry
• Protection: Access-control information determines who can do
reading, writing, executing, and so on.
• Truncating a file: The user may want to erase the contents of a file
but keep its attributes. Rather than forcing the user to delete the file
and then recreate it, this function allows all attributes to remain
unchanged—except for file length—but lets the tile be reset to length
zero and its file space released.
Common operations
Open
Close
Append
Rename
Copy
Access Methods

Files store information. When it is used, this information must be


accessed and read into computer memory. The information in the file
can be accessed in several ways.
1)Sequential Access
2)Direct Access
Sequential Access
• It is the simplest access method. Information in the file is processed in order
i.e. one record after another.
• A process can read all the data in a file in order starting from beginning but
can’t skip & read arbitrarily from any location. Sequential files can be
rewound.
• It is convenient when storage medium was magnetic tape rather than disk.
Advantages of sequential access
• It is simple to program and easy to design.
• Sequential file is best use if storage space.
Disadvantages of sequential access
• Sequential file is time consuming process.
• It has high data redundancy.
• Random searching is not possible.
Direct Access

• Sometimes it is not necessary to process every record in a file.


• It is not necessary to process all the records in the order in which they
are present in the memory. In all such cases, direct access is used. • The
disk is a direct access device which gives us the reliability to random
access of any file block.
• In the file, there is a collection of physical blocks and the records of
that blocks.
• Example: Databases are often of this type since they allow query
processing that involves immediate access to large amounts of
information. All reservation systems fall into this category
Advantages:
• Direct access file helps in online transaction processing system (OLTP)
like online railway reservation system.
• In direct access file, sorting of the records are not required.
• It accesses the desired records immediately.
• It updates several files quickly.
• It has better control over record allocation.
Disadvantages:
• Direct access file does not provide backup facility.
• It is expensive.
• It has less storage space as compared to sequential file.
Indexed Sequential Access
• The index sequential access method is a modification of the direct access method.
• Basically, it is kind of combination of both the sequential access as well as direct
access.
• The main idea of this method is to first access the file directly and then it accesses
sequentially.
• In this access method, it is necessary for maintaining an index.
• The index is nothing but a pointer to a block.
• The direct access of the index is made to access a record in a file.
• The information which is obtained from this access is used to access the file.
Sometimes the indexes are very big.
• to maintain all these hierarchies of indexes are built in which one direct access of
an index leads to information of another index access.
• It is built on top of Sequential access.
• It uses an Index to control the pointer while accessing files.
Advantages:
• In indexed sequential access file, sequential file and random file
access is possible.
• It accesses the records very fast if the index table is properly
organized.
• The records can be inserted in the middle of the file.
• It provides quick access for sequential and direct processing.
• It reduces the degree of the sequential search.
Disadvantages:
• Indexed sequential access file requires unique keys and periodic
reorganization.
• Indexed sequential access file takes longer time to search the index
for the data access or retrieval.
Directory Structure
• A directory is a container that is used to contain folders and file.
• It organizes files and folders into a hierarchical manner

• Types:
1.Single-level directory
2.Two-level directory
3.Tree-structured directory
Single-level directory
• Single level directory is simplest directory structure.
• In it all files are contained in same directory which make it easy to
support and understand.
• A single level directory has a significant limitation, however, when the
number of files increases or when the system has more than one user.
• Since all the files are in the same directory, they must have the
unique name. if two users call their dataset test, then the unique name
rule violated.
• Advantages:
• Since it is a single directory, so its implementation is very easy.
• If files are smaller in size, searching will 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 cannot have
the same name.
• Searching will become time taking if directory will large.
• In this cannot group the same type of files together
Two-level directory
• As, a single level directory often leads to confusion of files names among
different users hence 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).
• The MFD is indexed by username or account number, and each entry
points to the UFD for that user
Advantages:
• We can give full path like /User-name/directory-name/.
• Different users can have same directory as well as file name.
• Searching of files become more easy due to path name and user-grouping.
Disadvantages:
• A user is not allowed to share files with other users.
• Still it not very scalable, two files of the same type cannot be grouped
together in the same user.
Tree-structured directory
• Once we have seen a two-level directory as a tree of height 2, the
natural generalization is to extend the directory structure to a tree of
arbitrary height.
• This generalization allows the user to create their own subdirectories
and to organize on their files accordingly.
• A tree structure is the most common directory structure. The tree has
a root directory, and every file in the system have a unique path.
• Advantages:
• Very generalize, since full path name can be given.
• Very scalable, the probability of name collision is less.
• Searching becomes very easy, we can use both absolute path as well
as relative.
Disadvantages:
• Every file does not fit into the hierarchical model; files may be saved
into multiple directories.
• We cannot share files.
• It is inefficient, because accessing a file may go under multiple
directories
Allocation Methods
• 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.
1.Contiguous File allocation
2.Linked File Allocation
3.Indexed File Allocation
Contiguous 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
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.
Linked Allocation

• files are stored in non-contiguous blocks of free space on the


disk, and each block is linked to the next block using a pointer.
• When a file is created, the operating system searches for a series
of free blocks that are large enough to store the file, and it links
them together using pointers.
• Each block contains the address of the next block in the file,
allowing the operating system to access the entire file by
following the chain of pointers.
• Advantages:
• This is very flexible in terms of file size. File size can be increased easily since
the system does not have to look for a contiguous chunk of memory.

• This method does not suffer from external fragmentation. This makes it relatively
better in terms of memory utilization.

• Disadvantages:
• Because the file blocks are distributed randomly on the disk, a large number of
seeks are needed to access every block individually. This makes linked allocation
slower.

• It does not support random or direct access. We can not directly access the blocks
of a file. A block k of a file can be accessed by traversing k blocks sequentially
(sequential access ) from the starting block of the file via block pointers.
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,
Free Space Management
• Free space lists contains all free disk blocks.ie blocks which are not
allocated to some file or directory.
Bitmap or Bit vector

• A Bitmap or Bit Vector is series or collection of bits where each bit


corresponds to a disk block.
• The bit can take two values: 0 and 1: 0 indicates that the block is
free and 1 indicates an allocated​block.
• The given instance of disk blocks on the disk in Figure 1 (where green
blocks are allocated) can be represented by a bitmap of 16 bits
as: 1111000111111001.
1111000111111001
• Linked List
• In this approach, the free disk blocks are linked together
i.e. a free block contains a pointer to the next free
block. The block number of the very first disk block is
stored at a separate location on disk and is also cached
in memory.
• Grouping
• This approach stores the address of the free blocks in the first free
block.
• The first free block stores the address of some, say n free blocks. Out
of these n blocks, the first n-1 blocks are actually free and the last
block contains the address of next free n blocks.

You might also like