0% found this document useful (0 votes)
14 views21 pages

OSY - Chapter - 6 - File Management by PSG

Uploaded by

info.swiftgroww
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)
14 views21 pages

OSY - Chapter - 6 - File Management by PSG

Uploaded by

info.swiftgroww
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/ 21

File Management

Chapter 6: Memory Management

Total Marks:10

CO6:Apply File Management Techniques

1 P.S.Gaidhani Computer Engineering


File Management

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.

2 P.S.Gaidhani Computer Engineering


File Management

Q. List and explain Attributes of the File

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.

7.Time and Date

Every file carries a time stamp which contains the time and date on which the file is last modified.

3 P.S.Gaidhani Computer Engineering


File Management

Q. List and explain Operations on the File

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.

4 P.S.Gaidhani Computer Engineering


File Management

Q. Explain types of files

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.

5 P.S.Gaidhani Computer Engineering


File Management

Q. With neat diagram, explain file access methods.


There are two method to access file:
1. Sequential access
2. Direct access

• Sequential Access Method:


• Information in the file is processed in order, one record after the other.
• This mode of access is by far the beginning current position most common;
• for example, editors and compilers usually access files in this fashion.

Reads and writes make up the bulk of the operations on a file.


• A read operation read next reads the next portion of the file and automatically advances a file pointer,
which tracks the I/O location.
• Similarly, the write operation write next appends to the end of the file and advances to the end of the
newly written material (the new end of file)

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

6 P.S.Gaidhani Computer Engineering


File Management

2. Direct Access Method:


• A file is made up of fixed-length logical records that allow programs to read and write
records rapidly in no particular order.
• Thus, we may read block 14, then read block 53, and then write block 7.
• There are no restrictions on the order of reading or writing for a direct-access file.
• The direct-access method is based on a disk model of a file, since disks allow random access
to any file block.
• Direct-access files are of great use for immediate access to large amounts of information.
Databases are often of this type.
• For the direct-access method, the file operations must be modified to include the block
number as a parameter.
• The block number provided by the user to the OS is normally a relative block number.
• When you work with a direct access file (which is also known as a random access file), you can jump
directly to any piece of data in the file without reading the data that comes before it.
• This is similar to the way a CD player or an MP3 player works. You can jump directly to any song that
you want to listen to.
• Sequential access files are easy to work with, and you can use them to gain an understanding of basic
file operations.

7 P.S.Gaidhani Computer Engineering


File Management

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.

8 P.S.Gaidhani Computer Engineering


File Management

4. Swapping

• Swapping is a memory management scheme in which any process can be temporarily


swapped from main memory to secondary memory so that the main memory can be made
available for other processes.
• It is used to improve main memory utilization.
• In secondary memory, the place where the swapped-out process is stored is called swap
space.

The concept of swapping has divided into two more concepts: Swap-in and Swap-out.

1. Swap-out is a method of removing a process from RAM and adding it to the

hard disk.

2. Swap-in is a method of removing a program from a hard disk and putting it

back into the main memory or RAM.

9 P.S.Gaidhani Computer Engineering


File Management

Q.List different file allocation methods. Explain any one in detail

File allocation methods are:


• Contiguous Allocation method
• Linked Allocation method
• Indexed Allocation method

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

10 P.S.Gaidhani Computer Engineering


File Management

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.

11 P.S.Gaidhani Computer Engineering


File Management

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.

12 P.S.Gaidhani Computer Engineering


File Management

Q. List different directory structure and explain any one in detail

List of directory structures:


• Single level directory structure
• Two level directory structure
Single level directory structure:
• It is the simplest form of directory structure, having one directory containing all the files, and each
file must have a unique name.
• Software design is simple.
• The advantages of this scheme are its simplicity and the ability to locate files quickly.
• Since all files are in the same directory, they must have unique names.
• If there are two users who call their data file "test", then the unique-name rule is violated.
• Even with a single-user, as the number of files increases, it becomes difficult to remember the
names of all the files in order to create files with unique name.

Two level directory structure:


• In this structure, each user has its own user file directory (UFD).
• The UFD lists only files of a single user.
• System contains a master file directory (MFD) which is indexed by user name or account number.
• Each entry in MFD points to the UFD for that user. When a user refers to a particular file, only his
own UFD is searched. Different users can have files with the same name, as long as all the file names
within each UFD are unique.
• When we create a file for a user, operating system searches only that user’s UFD same name file
already present in the directory For deleting a file again operating system checks the file name in
the user’s UFD only.

13 P.S.Gaidhani Computer Engineering


File Management

Q.Differentiate between contiguous and linked memory allocation method

14 P.S.Gaidhani Computer Engineering


File Management

Q. Explain Structures of Directory in Operating System

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.

15 P.S.Gaidhani Computer Engineering


File Management

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.

16 P.S.Gaidhani Computer Engineering


File Management

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

17 P.S.Gaidhani Computer Engineering


File Management

• Acyclic graph directory –


An acyclic graph is a graph with no cycle and allows to share subdirectories and files. The same file or
subdirectories may be in two different directories. It is a natural generalization of the tree-structured
directory.
It is used in the situation like when two programmers are working on a joint project and they need to
access files. The associated files are stored in a subdirectory, separated them from other projects and
files of other programmers since they are working on a joint project so they want to the
subdirectories into there own directories. The common subdirectories should be shared. So here we
use Acyclic directories.
It is the point to note that shared file is not the same as copy file if any programmer makes some
changes in the subdirectory it will reflect in both subdirectories.

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.

18 P.S.Gaidhani Computer Engineering


File Management

• General graph directory structure –


In general graph directory structure, cycles are allowed within a directory structure where multiple
directories can be derived from more than one parent directory.
The main problem with this kind of directory structure is to calculate total size or space that has been
taken by the files and directories.

Advantages:
• It allows cycles.
• It is more flexible than other directories structure.
Disadvantages:
• It is more costly than others.
• It needs garbage collection.

19 P.S.Gaidhani Computer Engineering


File Management

Important Questions
Unit No:06 File Management

Question for 2 Marks


1 List different Accessing Methods of a File
2 Define Directory.
3 List directory Structure.
4 State any two activities performed by file management component of an OS.
5 Define UFD and MFD.

Questions for 4 Marks


1 Describe sequential and direct access method
2Write unix command for following: (i) Create a folder OSY (ii) Create a file FIRST in
OSY folder (iii) List / display all files and directories. (iv) Write command to clear the
screen
3 List and explain different attributes of file.
4 What are the most common schemes for defining the Logical Structure of a Directory

Questions for 6 Marks


1 Enlist different file allocation methods? Explain contiguous allocation method in detail.
2 Construct and explain directory structure of a file system in terms of single level, two level
and three structure.

20 P.S.Gaidhani Computer Engineering


File Management

Assignment No:06

Question for 2 Marks (05*02=10)


1.List different Accessing Methods of a File
2.Define Directory.
3.List directory Structure.
4.State any two activities performed by file management component of an OS.
5.Define UFD and MFD.

Questions for 4 Marks(04*05=20)


1.Describe sequential and direct access method
2.Write Unix command for following: (i) Create a folder OSY (ii) Create a file FIRST in
OSY folder (iii) List / display all files and directories. (iv) Write command to clear the
screen
3.List and explain different attributes of file.
4.What are the most common schemes for defining the Logical Structure of a Directory
5. Construct and explain directory structure of a file system in terms of single level, two level
and three structure.

21 P.S.Gaidhani Computer Engineering

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy