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

file system new

The document provides an overview of file systems in operating systems, detailing the concept of files, their attributes, operations, and types. It discusses various access methods, file structures, allocation methods, and free space management techniques. Key allocation methods include contiguous, linked, and indexed allocation, each with its advantages and disadvantages regarding performance and efficiency.

Uploaded by

nikamsakshi13
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

file system new

The document provides an overview of file systems in operating systems, detailing the concept of files, their attributes, operations, and types. It discusses various access methods, file structures, allocation methods, and free space management techniques. Key allocation methods include contiguous, linked, and indexed allocation, each with its advantages and disadvantages regarding performance and efficiency.

Uploaded by

nikamsakshi13
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to Operating System

File System

8.1 File Concept


8.2 Access Methods
8.3 File Structure
8.4 Allocation Methods
8.5 Free Space Management

Introduction:

 All computer applications need to store and retrieve information while a


process is running
 It can store a limited amount of information within its own address space.
 It must be possible to store a very large amount of information.
 The information must survive the termination of the process using it.
 Multiple processes must be able to access the information concurrently.
 To store the information on disks and other external media in unit is called
Files
8.1 File Concept :

 Computers can store information on various storage media, such as


magnetic disks, magnetic tapes, and optical disks.
 So that the computer system will be convenient to use, the operating system
provides a uniform logical view of information storage.
 The operating system abstracts from the physical properties of its storage
devices to define a logical storage unit, the file. Files are mapped by the
operating system onto physical devices.

8.1
Introduction to Operating System

 These storage devices are usually non-volatile, so the contents are


persistent through power failures and system reboots.
 A file is a named collection of related information that is recorded on
secondary storage.
 . Data files may be numeric, alphabetic, alphanumeric, or binary. Files may
be free form, such as text files, or may be formatted rigidly.
File Attributes:
 A file is named, for the convenience of its human users, and is referred to by
its name.
 A name is usually a string of characters, such as examples. Some systems
differentiate between uppercase and lowercase characters in names,
whereas other systems do not.
 A file's attributes vary from one operating system to another but typically
consist of these:
1) Name:
The symbolic file name is the only information kept in human readable form.
2) Identifier:
This unique tag, usually a number, identifies the file within the file system; it is the
non-human-readable name for the file.
3) Type:
This information is needed for systems that support different types of files.
4) Location:
This information is a pointer to a device and to the location of the file on that device.
5) Size:
The current size of the file (in bytes, words, or blocks) and possibly the maximum
allowed size are included in this attribute.
6) Protection:
Access-control information determines who can do reading, writing, executing, and
so on.
7) Time, date, and user identification:

8.2
Introduction to Operating System

This information may be kept for creation, last modification, and last use. These
data can be useful for protection, security, and usage monitoring.
8.1.1. File Operations:
 A file is an abstract data type.
 To define a file properly, user need to consider the operations that can be
performed on files.
 The operating system can provide system calls to create, write, read,
reposition, delete, and truncate files.
1) 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.
2) Writing a File:
 To write a file, a system call must be made for 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.
3) Reading a File:
 To read from a file, a system call is used 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.
4) 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.

8.3
Introduction to Operating System

 This file operation is also known as a file seeks.


5) Deleting a File:
 To delete a file, the directory is searched for the named file.
 Having found the associated directory entry, all file space is released, so that
it can be reused by other files, and erase the directory entry.
6) Truncating a File:
 Deleting a file and then recreate it.
 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 unchangedexcept for file length; but
lets the file be reset to length zero and its file space released.
8.1.2. File Types:
 To operate on the file in reasonable way an operating system recognizes the
type of a file
 The technique for implementing file types of include the type as a part of the
file name.
 The name is split into two parts a name and an extension.

File Type Usual Extension Function


Executable exe, com, bin Read to run machine language program.
Object obj, o Compiled, machine language, not linked
Source Code c, cc, java, pas, asm, Source code in various language
a
Text txt, doc Textual data, documents
Batch bat, sh Commands to the command interpreter
Archive arc, zip, tar Related files grouped into one files,
sometime compressed.
Library lib, a Libraries of routines for programmers

8.4
Introduction to Operating System

8.2 Access Methods:


 File stores information.
 When it is used, this information must be accessed and read into the
computer's memory.
 There are several ways that the information in the file can be accessed.
 Access is permitted or denied depending on several factors, one of which is
the type of access requested.
 Several different types of operations may be controlled.
There are several ways that the information in the file can be accessed. Some systems
provide only one access method for files. On other systems, many different access
methods are supported, and choosing the right one for a particular application is a
major design problem.
8.2.1 SequentialAccess:
Sequential access is based on the tape model of a file. Information in the file is
processed in order, one record after the other. A read operation reads the next portion
of the file and automatically advances the file pointer.

Sequential Access

Fig 8.4 : Sequential Access


A write operation appends to the end of the file andthe file pointer. It is implemented by
the file system. Data is accessed one record right after the last. It reads cause a pointer
to be moved ahead by one. It writes allocate space for the record and move the pointer
to the new end of file (EOF). Such a method is reasonable for tape.
8.2.2. DirectAccess:

8.5
Introduction to Operating System

 Direct access is based on a disk model of a file. For direct access, the file is
viewed as a numbered sequence of block or records. A direct-access file
allows arbitrary blocks to be read or written.
 There are no restrictions on the order of reading and writing for a direct
access file.
 Direct access files are of great use for intermediate access to large amounts
of information.
 The file operations must be modified to include the block number as a
parameter. Not all OS support both sequential and direct access for files.
Some systems allow only sequential file access; others allow only direct
access.
 Some systems require that a file be defined as sequential or direct when it is
created; such a file can be accessed only in a manner consistent with its
declaration.
8.3 File Structure:
 File types can be used to indicate the internal structure of the file.
1) Stream of Bytes:
 A field is the basic element of data. An individual field contains a single
value.
 OS considers file to be unstructured..
2) Records:
 A file is a collection of similar records.
 A file is a sequence of fixed length record, each with some internal structure.
 Collection of bytes treated as a unit.
 File is a collection of similar records. OS can optimize operation on records.
3) Tree of Records (database):
 A database is a collection of related data.
 A file consist of a tree of records, not necessarily all the same length.
 Record can be variable length.

8.6
Introduction to Operating System

8.4 Allocation Methods:


The direct-access nature of disks allows user flexibility in the implementation of files,
in almost every case. Many files are stored on the same disk. The main problem is how
8.4 File Allocation Methods:
There are different kinds of methods that are used to allocate disk space.
We must select the best method for the file allocation because it will
directly affect the system performance and system efficiency.
With the help of the allocation method, we can utilize the disk, and also
files can be accessed
The main problem is how to allocate space to these files so that disk space
is effectively utilized and files can be quickly accessed.
Several issues are involved in file allocation:
 When a new file is created, is the maximum space required for
the file allocated at once?
 Space is allocated to file as one or more continuous units. What
size of portion should be used for file allocation?
 What sort of data structure is used to keep track of the blocks to a
file? Such a table is typically referred to as File Allocation Table
(FAT).
 File allocation Table:
 A file allocation table is maintained, which gathers all the disk block
links.
 The table has one entry for each disk block and is indexed by block
number.
 A static Allocation requires that the maximum size of file be declared at
that time of file creation request.

8.7
Introduction to Operating System

 In dynamic allocation, which allocates space to a file in blocks are


needed.
 Uses the whole disk block for data.
 A bad disk block doesn't cause all successive blocks lost.
 Random access is provided although it’s not too fast.
 Only FAT needs to be traversed in each file operation.

 File Allocation Table:


File Name Start Block Length

 There are various types of file allocations method:


1. Contiguous Allocation
2. Linked Allocation (Chained Allocation)
3. Indexed Allocation
8.4.1 Contiguous Allocation:
 The contiguous allocation method requires each file to occupy a set of
contiguous address on the disk.
 This is the static allocation methods, using variable-size portion.
 The FAT needs just a entry, for each file, showing starting block and the length
of the file.
 It is best for sequential file
 External fragmentation will occur.
 Making it difficult to find contiguous blocks of space of sufficient length.
 Disk addresses define a linear ordering on the disk. Notice that, with this
ordering, accessing block b+1 after block b normally requires no head
movement.
 When head movement is needed (from the last sector of one cylinder to the
first sector of the next cylinder), it is only one track. Thus, the number of disk
seeks required for accessing contiguous allocated files in minimal, as is seek
time when seek is finally needed.

8.8
Introduction to Operating System

Fig 8.4.1: Contiguous allocation


 Advantages:
 Support both sequential and direct access methods.
 It is easy to retrieve a single block from a file.
 Contiguous allocation is form of allocation for Sequential Files.
 Disadvantages:
 Suffers from external fragmentation.
 Very difficult to find contiguous blocks of space.
 Wastage of Space .
8.4.2 Linked Allocation(Chained Allocation):
 Linked allocation solves all the problem of contiguous allocation, each file is a
linked list of disk blocks.
 The problems in contiguous allocation can be traced directly to the requirement
that the spaces are allocated contiguously and that the files that need these
spaces are of different sizes.
 These requirements can be avoided by using linked allocation.In linked
allocation, each file is a linked list of disk blocks.
 The directory contains a pointer to the first and (optionally the last) block of the
file.

8.9
Introduction to Operating System

 Linked Allocation is inefficient to support a direct access files.

File Allocation TableRecord

ATree

Fig 8.4.2 : Linked Allocation

 Advantages:
 No External Fragmentation
 Any free blocks can be added to a chain.
 No Need to Declare Size
 Improves Disk Throughput
 Disadvantages :
 Linked list allocation does not support direct access or random access.
 In the disk block for the pointer, it needs some extra space.
 In linked list allocation, we need to traverse each block.
 In the disk block for the pointer, it needs some extra space.

8.4.3 Indexed Allocation:


 The indexed allocation method is the solution to the problem of both contiguous
and linked allocation.
 In the index allocation method, we have an additional block, and that block is
known as the index block.

8.10
Introduction to Operating System

 For each file, there is an individual index block.


 In the index block, the ith entry holds the disk address of the ith file block. We can
see in the below figure that the directory entry comprises of the address of the
index block.
 Process of Indexed Allocation:
 Each file has its own index block, which is an array of disk block addresses.
The ith entry in the index block points to the i th block of the file. The directory
contains the address of the index block.
 When the file is created, all pointers in the index block are set to nil. When
the ith block is first written, a block is obtained from the free space manager,
and its address is put in the ith index-block entry.
 Allocation supports direct access, without suffering from external
fragmentation because any free block on the disk may satisfy a request for
more space.

File Allocation Table

Fig 8.4.3: Indexed Allocation


 Advantages:
 The index allocation method solves the problem of external
fragmentation.
 Index allocation provides direct access.

8.11
Introduction to Operating System

 Disadvantages :
 In index allocation, pointer overhead is more.
 We can lose the entire file if an index block is not correct.
 It is totally a wastage to create an index for a small file.

Free Space Management:


 Since there is only a limited amount of disk space, it is necessary to reuse the
space from deleted files for new files, if possible.
 To keep track of free disk space, the system maintains a free-space list. The
free-space list records all free disk blocks-those not allocated to some file or
directory.
 To create a file, user searches the free-space list for the required amount of
space and allocates that space to the new file. This space is then removed from
the free-space list.
 When a file is deleted, its disk space is added to the free-space list. Following are
some ways to manage free space on hard disk:
A) Bit Vector:
 Free-space list is implemented as a bit map or bit vector.
 Each block is represented by one bit.
 If the block is free, the bit is 1;
 if the block is allocated, the bit is 0.
 The main advantage of this approach is that it is relatively simple and efficient to
find n consecutive free blocks on the disk.
 Example:
1. Consider a disk where blocks
2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26, and 27 are free, and the rest of the
blocks are allocated.
The free-space bit map would be =
001111001111110001100000011100000 …..
2. The bit vector is : 001011000110
Then the blocks 0,1,3,6,7,9are Free, and2,4,5,8 are used.

8.12
Introduction to Operating System

3. 0000111000000110

Linked List:
 Another approach is to link together all the free disk blocks, keeping a
pointer to the first free block in a special location on the disk and caching it in
memory.
 This first block contains a pointer to the next free disk block, and so on.
Block 2 would contain a pointer to block 3, which would point to block 4,
which would point to block 5, which would point to block 8, and so on.
 Usually, the operating system simply needs afree block so that it can
allocate that block to a file, so thefirst block in the free list is used.
 Example: 0000111000000110

8.13
Introduction to Operating System

B) Grouping:
 A modification of the free-list approach is to store the addresses of n free
blocks in the first free block.
 The first n-1of these blocks are actually free. The importance of this
implementation is that the addresses of a large number of free blocks can be
found quickly, unlike in the standard linked-list approach.
C) Counting:
 Several contiguous blocks may be allocated or freed simultaneously,
particularly when the space is allocated with the contiguous allocation
algorithm or through clustering.
 In a list of n free disk addresses, user can keep the address of the first free
block and the number n of free contiguous blocks that follow the first block.
Each entry in the free-space list then consists of a disk address and a count.
Although each entry requires more space than would a simple disk address,
the overall list will be shorter, as long as count is generally greater than 1.

Review Questions
MCQ 1Marks
1) _____ is a unique tag, usually a number identifies the file within the file
system.
a)File identifier
b)File name
c)File type
d) None of the mentioned

2) To create a file ____________


a) allocate the space in file system
b) make an entry for new file in directory
c) allocate the space in file system & make an entry for new file in
directory
d) none of the mentioned
3) By using the specific system call, we can ____________
a) open the file

8.14
Introduction to Operating System

b) read the file


c) write into the file
d) all of the mentioned

4) File type can be represented by ____________


a) file name
b) file extension
c) file identifier
d) none of the mentioned

5) Which file is a sequence of bytes organized into blocks understandable by


the system’s linker?
a) object file
b) source file
c) executable file
d) text file

6) When will file system fragmentation occur?


a) unused space or single file are not contiguous
b) used space is not contiguous
c) unused space is non-contiguous
d) multiple files are non-contiguous

7) A file is a sequence of?


a) bits
b) bytes
c) lines
d) All of the above

8) Mapping of file is managed by ____________


a) file metadata
b) page table
c) virtual memory
d) file system

9) In Space Allocation, Which of the following ways are correct to allocate


disk space to files?
a) Contiguous Allocation
b) Linked Allocation

8.15
Introduction to Operating System

c) Indexed Allocation
d) All of the above

10) _________ is a sequence of procedures and functions.


a) object file
b) source file
c) text file
d) None of the above

Q. 1. What is the concept of file? Explain in detail the operations to be performed with
a file and types of access on a file.
Q. 2. Explain in detail the following access methods:
a) Sequential Access.
b) Direct Access.
Q. 3. Explain in detail the structure of a file and its attributes.
Q. 4. What are the advantages and disadvantages of contiguous allocation method?
Explain in detail the process of contiguous allocation method.
Q. 5. Explain the following free space management tools:
a) Bit Vector
b) Linked List.
c) Grouping.
d) Counting.
Q. 6. Explain in detail the process of indexed allocation method. What are the
advantages and disadvantages of the indexed allocation method?
Q. 7. Write short notes on the following:
a) File Attributes.
b) File Types.
c) Advantages and Disadvantages of Linked Allocation.
d) Internal File Structure.
e) Process of Linked Allocation Method.

8.16

You might also like