OSY - Chapter - 6 - File Management by PSG
OSY - Chapter - 6 - File Management by PSG
Total Marks:10
Q. What is a File ?
➢ The file can be explained as the smallest unit of storage on a computer system.
➢ A file can be defined as a data structure which stores the sequence of records.
➢ The user can perform file operations like open, close, read, write, and modify.
➢ The operating system can provide a logical view of the information stored in the disks, this logical
unit is known as a file.
➢ The information stored in files is not lost during power failures.
➢ Files are stored in a file system, which may exist on a disk or in the main memory. Files can be
simple (plain text) or complex (specially-formatted).
➢ The collection of files is known as Directory.
➢ The collection of directories at the different levels, is known as File System.
1.Name
Every file carries a name by which the file is recognized in the file system. One directory cannot have two
files with the same name.
2.Identifier
Along with the name, Each File has its own extension which identifies the type of the file. For example, a
text file has the extension .txt, A video file can have the extension .mp4.
3.Type
In a File System, the Files are classified in different types such as video files, audio files, text files,
executable files, etc.
4.Location
In the File System, there are several locations on which, the files can be stored. Each file carries its location
as its attribute.
5.Size
The Size of the File is one of its most important attribute. By size of the file, we mean the number of bytes
acquired by the file in the memory.
6.Protection
The Admin of the computer may want the different protections for the different files. Therefore each file
carries its own set of permissions to the different group of Users.
Every file carries a time stamp which contains the time and date on which the file is last modified.
There are various operations which can be implemented on a file. We will see all of them in detail.
1.Create
Creation of the file is the most important operation on the file. Different types of files are created by
different methods for example text editors are used to create a text file, word processors are used to create
a word file and Image editors are used to create the image files.
2.Write
Writing the file is different from creating the file. The OS maintains a write pointer for every file which
points to the position in the file from which, the data needs to be written.
3.Read
Every file is opened in three different modes : Read, Write and append. A Read pointer is maintained by the
OS, pointing to the position up to which, the data has been read.
4.Re-position
Re-positioning is simply moving the file pointers forward or backward depending upon the user's
requirement. It is also called as seeking.
5.Delete
Deleting the file will not only delete all the data stored inside the file, It also deletes all the attributes of the
file. The space which is allocated to the file will now become available and can be allocated to the other
files.
6.Truncate
Truncating is simply deleting the file except deleting attributes. The file is not completely deleted although
the information stored inside the file get replaced.
1. Executable file:
➢ In an executable file, the binary code that is loaded in the memory for execution is stored.
➢ It is stored in an exe type file.
2. Source file:
➢ The source file has subroutines and functions that are compiled later.
3. Object file:
➢ An object file is a sequence of bytes used by the linker.
4. Text file:
➢ A text file is a sequence of characters.
5. Image file:
➢ An image file is a sequence of visual information, for example, vector art.
• To read a piece of data that is stored at the end of the file, one has to read all of the data that comes
before it-you cannot jump directly to the desired data.
• This is similar to the way cassette tape players work.
• If one wants to listen to the last song on a cassette tape, he has to either fast-forward over all of the
songs that come before it or listen to them.
• There is no way to jump directly to a specific song.
3. Indexed Access
• If a file can be sorted on any of the filed then an index can be assigned to a group of certain records.
• However, A particular record can be accessed by its index. The index is nothing but the address of a
record in the file.
• In index accessing, searching in a large database became very quick and easy but we need to have
some extra space in the memory to store the index value.
4. Swapping
The concept of swapping has divided into two more concepts: Swap-in and Swap-out.
hard disk.
Contiguous Allocation
• The contiguous allocation method requires each file to occupy a set of contiguous address on the
disk.
• Disk addresses define a linear ordering on the disk.
• With this ordering, accessing block b+1 after block b normally requires no head movement
• Contiguous allocation of a file is defined by the disk address and the length of the first block. If the
file is n blocks long, and starts at location b, then it occupies blocks b, b+1, b+2, …, b+n-1.
• The directory entry for each file indicates the address of the starting block and the length of the area
allocated for this file
linked Allocation:
• In this method, each file occupies disk blocks scattered anywhere on the disk.
• It is a linked list of allocated blocks.
• When space has to be allocated to the file, any free block can be used from the disk and system
makes an entry in directory.
• Directory entry for allocated file contains file name, a pointer to the first allocated block and last
allocated block of the file.
• The file pointer is initialized to nil value to indicate empty file.
• A write to a file, causes search of free block.
• After getting free block data is written to the file and that block is linked to the end of the file.
• To read the file, read blocks by following the pointers from block to block starting with block
address specified in the directory entry.
• For example, a file of five blocks starting with block 9 and continue with block 16,then block 1,then
block 10 an finally block 25.each allocated block contains a pointer to the next block.
Indexed Allocation:
• In this method, each file has its own index block.
• This index block is an array of disk block addresses.
• When a file is created, an index block and other disk blocks according to the file size are allocated to
that file.
• Pointer to each allocated block is stored in the index block of that file.
• Directory entry contains file name and address of index block.
• When any block is allocated to the file, its address is updated in the index block.
• Any free disk block can be allocated to the file. Each ith entry in the index block points to the ith
block of the file. To find and read the ith block, we use the pointer in the ith index block entry.
A directory is a container that is used to contain folders and file. It organizes files and folders into a
hierarchical manner.
There are several logical structures of a directory, these are given below.
1. 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 can not have the same name.
• Searching will become time taking if directory will large.
• In this can not group the same type of files together.
2.Two-level directory –
As we have seen, a single level directory often leads to confusion of files names among different users.
the solution to this problem is to create a separate directory for each user.
• In the two-level directory structure, each user has there own user files directory (UFD).
• The UFDs has similar structures, but each lists only the files of a single user.
• system’s master file directory (MFD) is searches whenever a new user id=s logged in.
• 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 there 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 can not share files.
• It is inefficient, because accessing a file may go under multiple directories.
Advantages:
• We can share files.
• Searching is easy due to different-different paths.
Disadvantages:
• We share the files via linking, in case of deleting it may create the problem,
• If the link is soft link then after deleting the file we left with a dangling pointer.
• In case of hard link, to delete a file we have to delete all the reference associated with it.
Advantages:
• It allows cycles.
• It is more flexible than other directories structure.
Disadvantages:
• It is more costly than others.
• It needs garbage collection.
Important Questions
Unit No:06 File Management
Assignment No:06