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

Os Module 4 Editted

Uploaded by

shihankv807
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)
18 views

Os Module 4 Editted

Uploaded by

shihankv807
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/ 13

1

MODULE 4
FILE SYSTEM
File system - Concept of file and directory - Various file operations - File
organization concepts – sequential and indexed. Different directory structures –
single level, two-level, and tree structured directories. - Different allocation
methods – contiguous, linked and indexed allocations. Various disk scheduling
algorithms-FCFS, SSTF, Scan, C-Scan, Look & C-Look.

CONCEPT OF FILE
➢ A file is a collection of related information defined by its creator (user).
➢ In general file in a sequence of bits, bytes, lines or records.
File types
➢ Text file: sequence of character organized into lines.
o Eg: .txt file
➢ Source file: sequence of subroutine or functions which are executed and
define to do some specific task.
o Eg: .src file
➢ Object file: collection of words organized into loader record block.
o Eg: .obj file
File attributes
➢ Attributes are the parameters used to keep track of file in os.
• Name: Human readable form. It contains the name of the file.
• Identifier: Unique ID, generally represented by number and identify
the file within the collection of all file in the os.
• Type: It define the file type. Regular, Directory, special file?
• Location: It is the pointer to a device and location of file on the
device.
▪ Telling the os which location at which device the file is store.
• Size: It define the current size of the file
2

• Protection: It is the access control information. Read(r), Write(w), Execute(x)


• Time & Date: It is the information used to maintain the log that when
the file is created, modified, deleted.
• User ID: User identification used to give unique ID to the user or
creator of the file.
FILE OPERATIONS
• Creating a file
➢ To create a file we have two steps.
▪ Found space in the system.
▪ Made an entry for new file.
• Writing a file
➢ The os maintain a write pointer for every file.
➢ It write data all current file position pointer location and update
pointer.
• Reading a file
➢ Every file is opened in three different modes.
▪ Read, write, append
➢ A read pointer is maintained by the os pointing to the position up to
which the data has been read.
• Reposting a file
➢ It doesn’t involve any actual I/O operation.
➢ It simply moving the bfile pointer forward or backward depending
upon user’s requirement (to search a file) also called as seeking.
• Deleting a file
➢ Delete a file entry from the file system.
➢ It will not only delete the data stored inside the file.
➢ It also delete the attributes of the file.
➢ The space allocated to the file will now become available and can be
allocated to other files.
• Truncating a file
➢ Deleting the file content and keep the attributes.
➢ The file is not completely deleted although the information stored
inside the file get replaced.
3

FILE CONTROL BLOCK


➢ FCB (File Control Block) is an internal file system structure used
in DOS for accessing files on disk.
➢ The FCB block contains information about the drive name, filename,
file type and other information that is required by the system when a
file is accessed or created.

FILE ACCESS (ORGANIZATION) MECHANISM


➢ It refers to the manner in which the records of a file may be accessed.
➢ There are three ways to access a file into a computer system
• Sequential
• Direct / Random
• Indexed
SEQUENTIAL
➢ It is the simplest access method.
➢ Information in the file is processed in order, one record after the other.
➢ This mode of access is by far the most common.
➢ For example, editor and compiler usually access the file in this fashion.
4

➢ Read and write make up the bulk of the operation on a file.


➢ A read operation -read_next- read the next position of the file and
automatically advance a file pointer, which keeps track I/O location.
➢ Similarly, for the write, write_next append to the end of the file and
advance to the newly written material.
➢ Rewind: come back to the beginning position or moving back to the
earlier location.
DIRECT / RANDOM
➢ It provides accessing the records directly.
➢ Each record has its own address on the file with by the help of which it
can be directly accessed for reading or writing.
➢ The record need not be in any sequence within the file and they need not
be in adjacent locations on the storage medium.

INDEXED
➢ An indexed file is a computer file with an index that allow easy random
access to any record given its file key.
➢ The key is an attribute that can uniquely identifies a record.
➢ If more than one index is present the other ones are alternate indexes.
➢ Creation of indexes is done with file but maintained by the system.
5

➢ To find a record in the file we first search the index and then by help of
pointer can access the file directly.

DIRECTORY
➢ A directory is a container that is used to contain folders and file.
➢ It organizes files and folders into a hierarchical manner.
➢ Directory can be defined as the listing of the related files on the disk.
➢ The directory may store some or the entire file attributes.
➢ To get the benefit of different file systems on the different operating
systems, A hard disk can be divided into the number of partitions of
different sizes. The partitions are also called volumes or mini disks.
➢ Each partition must have at least one directory in which, all the files of the
partition can be listed.
➢ A directory entry is maintained for each file in the directory which stores all
the information related to that file.
6

OPERATIONS
• Search for a file
➢ Search a directory for a particular file.
➢ File have symbolic name.
➢ Similar name indicate relationship among file.
• Create a new file
➢ New file need to be created and added to the directory.
• Delete a file
➢ Delete / remove no longer needed file.
• List a directory
➢ Can list the files in a directory and contents of directory entry for
each file in the list.
• Rename a file
➢ Name of file represent its content to its users.
➢ When the content or use of the file change must change the name.
➢ Renaming file may allow its position within the directory structure
to be changed.
• Traverse the file
➢ Access every directory and every file wirhin a directory structure.
DIRECTORY STRUCTURES
➢ There are several logical structures of directory.
• Single level
• Two level
• Tree structured
SINGLE LEVEL DIRECTORY
➢ It is the simplest directory structure.
➢ In its all files are contained in same directory which make it easy to support
7

and understand.
➢ All files are in same directory have unique name.
➢ If two users call their dataset test then the unique name rule violated.

Advantage
➢ Implementation is very simple.
➢ If the sizes of the files are very small then the searching becomes faster.
➢ File creation, searching, deletion is very simple since we have only one
directory.

Disadvantage
➢ We cannot have two files with the same name.
➢ The directory may be very big therefore searching for a file may take
so much time.
➢ Protection cannot be implemented for multiple users.
➢ There are no ways to group same kind of files.

TWO LEVEL DIRECTORY

➢ We can create a separate directory for each user.


➢ Each user has their own user file directory (UFD).
➢ UFDs has similar structures but each lists only the files of a single user.
➢ When a user job starts or a user logs in the system’s master file directory
(MFD) is searched.
➢ MFD is indexed by username or account number and each entry points to the
UFD for that user.
8

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 easy due to path name and user grouping.
Disadvantages
➢ A user is not allowed to share files with other users.
➢ It is not very scalable two files of same type can’t be grouped together in
same users.
TREE STRUCTURED DIRECTORY
➢ Two level directory has a tree of height 2.
➢ However natural generalization is to extend the directory structure to a tree
of arbitrary height.
➢ It is the most common directory structure.
➢ Allow user to create their own subdirectories and to organize their files.
9

➢ The tree has a root directory and every file in the system have a unique
path name.
➢ Path name is two type
• Absolute
• Relative
Absolute path name
• Path name starting from root directory and follow a path down to
the specified file.
Relative path name
• A path from the current directory.
➢ Each user has a current directory (working directory)
➢ User logs in assigned a current directory. Whenever need to access the
file, It will be searched first in current directory.
➢ It is possible to change current directory of one user to another directory
using system calls as well as commands.
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.

Disadvantage
• Every file does not fit into the hierarchical model, files may be
saved into multiple directories.
• We can not share files.
• It is inefficient, because accessing a file may go under multiple
directories.

ALLOCATION METHODS
➢ The allocation methods define how the files are stored in the disk blocks.
➢ There are three main disk space or file allocation methods.
• Contiguous Allocation
• Linked Allocation
• Indexed Allocation
10

CONTIGUOUS ALLOCATION
➢ In this scheme, each file occupies a contiguous set of blocks on the disk.
➢ For example, if a file requires n blocks and is given a block b as the
starting location, then the blocks assigned to the file will be: b, b+1,
b+2,……b+n-1.
➢ This means that given the starting block address and the length of the file
(in terms of blocks required), we can determine the blocks occupied by the
file.
➢ The directory entry for a file with contiguous allocation contains
• Address of starting block
• Length of the allocated portion.
➢ 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.

Advantages
➢ Both the Sequential and Direct Accesses are supported by this. For
direct access, the address of the kth block of the file which starts at
block b can easily be obtained as (b+k).
➢ This is extremely fast since the number of seeks are minimal because of
contiguous allocation of file blocks.
Disadvantages
➢ This method suffers from both internal and external fragmentation.
➢ This makes it inefficient in terms of memory utilization.
➢ Increasing file size is difficult because it depends on the availability of
contiguous memory at a particular instance
11

LINKED ALLOCATION
➢ In this scheme, each file is a linked list of disk blocks which need not
be contiguous.
➢ The disk blocks can be scattered anywhere on the disk.
➢ The directory entry contains a pointer to the starting and the ending file
block.
➢ Each block contains a pointer to the next block occupied by the file.

➢ The file ‘jeep’ in following image shows how the blocks are randomly
distributed. The last block (25) contains -1 indicating a null pointer and
does not point to any other block.

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.
➢ Pointers required in the linked allocation incur some extra overhead.
12

INDEXED ALLOCATION
➢ In this scheme, a special block known as the Index block contains the
pointers to all the blocks occupied by a file.
➢ Each file has its own index block.
➢ The ith entry in the index block contains the disk address of the ith file
block.
➢ The directory entry contains the address of the index block ,

Advantages:
➢ This supports direct access to the blocks occupied by the file and
therefore provides fast access to the file blocks.
➢ It overcomes the problem of external fragmentation.

Disadvantages:
➢ The pointer overhead for indexed allocation is greater than linked
allocation.
➢ For very small files, say files that expand only 2-3 blocks, the indexed
allocation would keep one entire block (index block) for the pointers
which is inefficient in terms of memory utilization.
13

❖ Files that are very large, single index block may not be able to hold all the
pointers.
❖ Following mechanisms can be used to resolve this:
➢ Linked scheme: This scheme links two or more index blocks together
for holding the pointers. Every index block would then contain a
pointer or the address to the next index block.
➢ Multilevel index: In this policy, a first level index block is used to
point to the second level index blocks which in turn points to the disk
blocks occupied by the file. This can be extended to 3 or more levels
depending on the maximum file size.
➢ Combined Scheme: In this scheme, a special block called the Inode
(information Node) contains all the information about the file such as
the name, size, authority, etc and the remaining space of Inode is used
to store the Disk Block addresses which contain the actual file.
===========================================================

You might also like