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

OS ch 5

Chapter Five discusses file system management, highlighting the importance of files for data storage and the role of file managers in organizing and accessing files. It covers various file access methods, attributes, operations, and directory structures, including single-level, two-level, and hierarchical systems. Additionally, it explains file allocation techniques such as contiguous, linked list, and indexed allocation, along with their advantages and disadvantages.

Uploaded by

ezedinali84
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)
6 views

OS ch 5

Chapter Five discusses file system management, highlighting the importance of files for data storage and the role of file managers in organizing and accessing files. It covers various file access methods, attributes, operations, and directory structures, including single-level, two-level, and hierarchical systems. Additionally, it explains file allocation techniques such as contiguous, linked list, and indexed allocation, along with their advantages and disadvantages.

Uploaded by

ezedinali84
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/ 32

Chapter Five

File System Management

1
Introduction

 A file is a collection of related information recorded on secondary storage.

 For example, files containing student information, files containing employee information,

files containing C source code, and so on.

 Information in files could be program code ,or data in numeric, alphanumeric, alphabetic, or

binary form either formatted or in free form.

 A file is therefore a collection of records if it is a data file. or a collection of bits/bytes/lines

if it is code. 2
Cont’d
 We used several files to store information on your computer, as the information in them can later be
retrieved and used.

 It is important that the files are managed properly, so that they can be located and accessed easily

without consuming time.

 To organize and manage the files and directories on your computer, OS uses an application called a

file manager.

 A file manager enables you to create, delete, copy, move, rename and view files ,and create and

manage directories (folders). 3

 The way in which OS organizes, names, protects, accesses, and uses files is called a file management system.
Files are required for the following reasons.

 To store data permanently (even after the termination of the process that creates

them).

 To store large data that is beyond the size of a process's address space.

 To enable multiple processes to access data simultaneously as in the case of

databases.

 Part of the operating system that deals with files are known as the file system.
4

 Users and designers of file systems have different views of files .


Cont…

 From the users' point of view, the most important issue is the interface (naming,

protection, and operations allowed.)


 From the designers' point of view, the choice between the use of linked lists

versus bit maps and the number of tracks per block has more importance.

5
Files and Directories – Interface

 Files and File Naming

 Name is used to identify a file with an abstract way. A file name consists of strings.

 The maximum allowed length of a file and case sensitivity of names vary from one operating system to

the other.

 Most operating systems have some characters, called file extensions, as part of the file name following a

period (.).

 In some operating systems (such as Microsoft Windows), the file extension is used to associate the file

with a program.
6

 Some characters, e.g. /, \ >, have special meaning in the file system so that they cannot be used as part of
File Access methods in operating system

 File access methods define how data is read and written from files stored on a disk.

There are three primary file access methods:


 Sequential access: the bytes or records of the file are read from beginning to end

sequentially. Example like a tape recorder


 If you want to access data in the middle of the file, you must read all preceding data.
 Random access/direct accesss: the bytes or records of the file can be read out of
order. Example: Databases where specific records are retrieved using an index.
7
FILE ATTRIBUTES

 A file has a number of attributes. The available attributes of files differ from one

operating system to the other.

 The most common attributes are:

 Attributes for ownership, access permission, and password.

 Flags (bits) for archive, hidden, system, read-only, temporary, etc.

 File size.

 Time of creation, last access, and last modification. 8


Cont’d

9
File Operations

 In order to provide the basic store and retrieval operations of a file and other properties

of files outlined above, operating systems have some common file operations.

 Some of them are: Create, delete, open, close, read, write, append, seek, get attributes,

set attributes, and rename.

10
Seek:
For random access file, a method is
Cont’d needed to specify from where to take the
data.
It repositions the pointer from the current
position to a specific place in the file.

Truncate: Reducing the size of a file to a


specified length. If the file is larger than
the specified length, the extra data is
removed. If the file is smaller, it may be
extended, often filling the new space
with null bytes (\0).

Append:
This call is restricted form of Write. It 11

can only add data to the end of the file.


Directories
 To keep track of files, file systems normally have directories (folders).

 In most operating systems directories themselves are files .

 Single Level Directory Systems

 Two Level Directory Systems

 Hierarchical Directory Systems

12
Single Level Directory Systems
 There is only one directory (the root directory) in the system.
 The advantage of this scheme is its implementation simplicity and ease of locating files.
 The main disadvantage is the need to provide distinct name for each file.
 This kind of directory organization was used in early operating systems.
 Here f1, f2, f3, f4, f5 represent the five different files.
 Practically it can be thought of as a structure where all the files are stored in the same
folder.

13
Two Level Directory Systems

 If two different users wanted to create a file with the same name (say report.doc), it was

not allowed in a single-level directory.

 In a two-level directory structure, there is a master node that has a separate directory for

each user.

 Each user can store the files in that directory.

 It can be practically thought of as a folder that contains many folders, each user can store

files in the allocated directory just like a single-level directory. 14


Cont…

 For every user, there is a separate directory. At the next level, every directory stores the

files just like a single-level directory.

15
Hierarchical Directory Systems

 This type of directory is used in our PCs.

 The biggest disadvantage of a two-level directory was that one could not create sub-

directories in a directory.

 The tree-structured directory solved this problem.

 In a tree-structured directory, there is a root directory at the peak.

 The root directory contains directories for each user.

 The users can, however, create subdirectories inside their directory and also store the files.
16
Hierarchical Directory Systems

17
Directory Operations

 The type of operations on directories varies from one operating system to the other.

 The most common operations are: create, delete, opendir, closedir, and rename.

18
Files and Directories – Implementation

 Implementing Files/File Allocation Methods

 File allocation techniques determine how files are stored on disk.

 The most important issue in file implementation is to keep track of which disk blocks go

to which file.

 There are several alternative ways of allocating disk space for files.

19
Contiguous Allocation
 The block is allocated in such a manner that all the allocated blocks in the hard disk are

adjacent.

 Assuming a file needs 'n' number of blocks in the disk and the file begins with a block at

position 'x', the next blocks to be assigned to it will be x+1,x+2,x+3,...,x+n-1. so that


they are in a contiguous manner.

 Example: We have three different types of files that are stored in a contiguous manner

on the hard disk.


20
Contiguous Allocation

 The file file1.txt requires 4 disk blocks, and its starting disk block address is 0, hence block 0,1,2,3 are
21

allocated.
Contiguous Allocation

 Advantage:

 Simple to implement: we need to keep track of first block of a file and file size to access

 Fast Access: when accessing a file, the only delay is while searching the first block of the file.

 Disadvantage: The file size must be specified at the time of file creation.

 The disk would eventually have many holes (unused blocks) as files are deleted.so it may create

 External Fragmentation: Over time, free spaces become scattered, making it hard to find a large

enough contiguous space for new files.


22

 Fixed File Size Issue: If a file grows larger than expected, it may not fit in its allocated space.
Cont…

(A)Contiguous allocation of disk space for seven files (b) state of disk space after files 23D and
F have been removed.
Linked List Allocation

 Disk blocks are allocated to a file in the form of linked list

 The block are allocated in such a way that every block contains a pointer to the next block

That is allocated to a file.

 Advantage:

 No External Fragmentation: Any free block can be used for storage.

 Efficient use of disk blocks.


24

 Dynamic File Growth: Files can expand easily by adding more blocks.
Cont..

 Disadvantage:

 low Access: Since blocks are scattered, accessing file data takes

longer

 Pointer Overhead: Each block needs extra space to store the

pointer.

 Reliability Issue: If a pointer is lost or damaged, the entire file can

become inaccessible. 25
Cont..

 Example:- Here we have one file which is stored using Linked File Allocation .

26
Cont…

27

Figure 5.2 Implementation of two files (File A and File B) with linked list of disk blocks
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, where

retrieval was accomplished by visiting each block sequentially.


28

 But, here in indexed allocation, it becomes easier with the index block to retrieve.
Cont.…

Example:- The following image is an example of indexed file allocation.

29
Comparison Table

SUMMURY FOR FILE ALLOCATION

Contiguous
Feature Linked Allocation Indexed Allocation
Allocation

Scattered blocks with Index block stores all


Storage Method Consecutive blocks
pointers block locations

Speed Fast Slow Moderate


None (Internal
Fragmentation High (External) None
overhead)
File Expansion Hard Easy Easy
One index block per
Pointer Overhead None One per block
file
30
Sequential access Large, random-access
Best for Small, fixed-size files
files files
Thank You!

31
QUIZ (5%)

1. List at least two main advantages of using file system in our computer system
2. List file Access methods and discuss what will be the advantages and disadvantages
of each access methods?(2 pts.)
3. List atleast 2 file allocation techniques of operating system?

32

You might also like