More Related Content
Similar to File_mngtChap6.pdf
Similar to File_mngtChap6.pdf (20)
More from DrAmarNathDhebla
More from DrAmarNathDhebla (8)
File_mngtChap6.pdf
- 1. Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10h Edition
Chapter 5: File Management
System
Dr. Amar Nath
AP, SLIET, Longowal
- 2. 14.2 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Outline
▪ File Concept
▪ File Structure
▪ Access Methods
▪ Allocation Method
▪ Directories Structure
- 3. 14.3 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Introduction
▪ File Management System : It includes the tasks like how to create, store and
manipulate the file.
▪
What is a File:
• A file is an object on a computer that stores data, information, settings, or
commands used with a computer program.
• Or A file is sequence of bits, bytes, lines or records created by its
owner.
• On a computer there are three types of files, application files, data files,
and system files.
G:My DriveSLIET
DATASLIET_3Nov_20200_Taught_Courses0_Course_2021-
22_EvenSemOS_CS-122_21CDMy_OS_PPTs
Where are files stored?
Computer files are stored on a drive (e.g.,
the hard drive), disc (e.g., DVD), and
a diskette (e.g., floppy disk) and may be
in a folder (directory) on that medium.
- 4. 14.4 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Files attributes
▪ Name – only information kept in human-readable form
▪ Identifier – unique tag (number) identifies file within file system
▪ Type – needed for systems that support different types
▪ Location – pointer to file location on device
▪ Size – current file size
▪ Protection – controls who can do reading, writing, executing
▪ Time, date, and user identification – data for protection, security,
and usage monitoring
▪ Information about files are kept in the directory structure, which
is maintained on the disk
▪ Many variations, including extended file attributes such as file
checksum
▪ Information kept in the directory structure
- 6. 14.6 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Hide a folder
attrib +h +s +r name_of_the_file_with_extension
i) attrib means attributes.
ii) + means we are adding an attribute.
iii) h means hidden, s means system file, r means read only.
- 8. 13.8 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Directory Structure
A directory is a container that is used to contain
folders and files. It organizes files and folders in a
hierarchical manner.
A collection of nodes containing information about all
files
Both the directory structure and the files reside on
disk
- 10. 13.10 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Types of Directory
Single-level directory
The single-level directory is the simplest directory structure. In it, all
files are contained in the same directory which makes 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 a
unique name. if two users call their dataset test, then the unique
name rule violated.
- 11. 14.11 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Advantages:
•Since it is a single directory, so its implementation is very easy.
•If the files are smaller in size, searching will become 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 have
the same name.
•Searching will become time taking if the directory is large.
•This can not group the same type of files together.
- 12. 14.12 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Two-level directory –
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 their
own user files directory (UFD).
- 13. 14.13 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Advantages:
•We can give full path like /User-name/directory-name/.
•Different users can have the same directory as well as the file
name.
•Searching of files becomes easier due to pathname 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.
- 15. 14.15 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Now let's describe briefly about all the above most common operations that can be
performed with files.
File Create Operation
The file is created with no data.
The file create operation is the first step of the file.
Without creating any file, there is no any operation can be performed.
File Delete Operation
File must has to be deleted when it is no longer needed just to free up the disk space.
The file delete operation is the last step of the file.
After deleting the file, it doesn't exist.
- 16. 14.16 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
File Open Operation
The process must open the file before using it.
File Close Operation
The file must be closed to free up the internal table space, when all the
accesses are finished and the attributes and the disk addresses are no
longer needed.
File Read Operation
The file read operation is performed just to read the data that are stored
in the required file.
- 17. 14.17 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
File Write Operation
The file write operation is used to write the data to the file, again, generally at
the current position.
File Append Operation
The file append operation is same as the file write operation except that the file
append operation only add the data at the end of the file.
File Seek Operation
For random access files, a method is needed just to specify from where to take
the data. Therefore, the file seek operation performs this task.
- 18. 14.18 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
File Rename Operation
The file rename operation is used to change the name of the existing file.
● Truncating a file. 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 unchanged
(except for file length) but lets the file be reset to length zero and its file
space released.
- 19. 14.19 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
n summary, several pieces of information are associated with an
open file.
● File pointer.
● File-open count.
● Disk location of the file. The information needed to locate the
file on disk is kept in memory so that the system does not have
to read it from disk for each operation.
● Access rights
- 20. 14.20 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
File-System Structure
▪ File structure
• Logical storage unit
• Collection of related information
▪ File system resides on secondary storage (disks)
• Provided user interface to storage, mapping logical to physical
• Provides efficient and convenient access to disk by allowing data
to be stored, located retrieved easily
▪ Disk provides in-place rewrite and random access
• I/O transfers performed in blocks of sectors (usually 512 bytes)
▪ File control block (FCB) – storage structure consisting of information
about a file
▪ Device driver controls the physical device
▪ File system organized into layers
- 21. 14.21 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
File System Layers
▪ Device drivers manage I/O devices at the I/O control layer
Given commands like
read drive1, cylinder 72, track 2, sector 10, into memory
location 1060
Outputs low-level hardware specific commands to hardware
controller
▪ Basic file system given command like “retrieve block 123”
translates to device driver
▪ Also manages memory buffers and caches (allocation, freeing,
replacement)
• Buffers hold data in transit
• Caches hold frequently used data
- 22. 14.22 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
▪ Many file systems, sometimes many within an
operating system
• Each with its own format:
• CD-ROM is ISO 9660;
• Unix has UFS, FFS;
• Windows has FAT, FAT32, NTFS as well as
floppy, CD, DVD Blu-ray,
• Linux has more than 130 types, with extended
file system ext3 and ext4 leading; plus
distributed file systems, etc.)
• New ones still arriving – ZFS, GoogleFS, Oracle
ASM, FUSE
File System Layers (Cont.)
- 23. 14.23 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
File Control Block (FCB)
▪ OS maintains FCB per file, which contains many details about
the file
• Typically, inode number, permissions, size, dates
• Example
- 24. 14.24 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
File Access Method in OS
▪ There are three ways to access a file into a computer system:
Sequential-Access,
▪ Direct Access,
▪ Index sequential Method.
Sequential Access –
It is the simplest access method. Information in the file is processed
in order, one record after the other.
▪ 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.
- 25. 13.25 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Sequential Access
Operations
• read next
• write next
• Reset
• no read after last write (rewrite)
Figure
Data is accessed one record right after another record
in an order.
Such a method is reasonable for tape, and cassette.
- 26. 13.26 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Simulation of Sequential Access on Direct-access File
- 27. 13.27 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Direct/Random Access
Operations
• read n
• write n
• position to n
read next
write next
rewrite n
n = relative block number
Relative block numbers allow OS to decide where file
should be placed
It is done in HDD, CD- and DVDs
It is based on the disk-model of a file, as a disk allows random access to
any block.
The Direct Access is mostly required in the case of database systems.
- 29. 13.29 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Example of Index and Relative Files
Here an index contains the pointers to various blocks of the
file.
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.
- 30. 14.30 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Allocation Method
▪ An allocation method refers to
how disk blocks are allocated
for files:
• Contiguous
• Linked
• File Allocation Table (FAT)
Indexed
- 31. 14.31 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Contiguous Allocation Method
▪ An allocation method refers to how disk blocks are
allocated for files:
▪ Each file occupies set of contiguous blocks
• Best performance in most cases
• Simple – only starting location (block #) and length
(number of blocks) are required
• Problems include:
4 Finding space on the disk for a file,
4 Knowing file size,
4 External fragmentation, need for compaction
off-line (downtime) or on-line
- 32. 14.32 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Contiguous Allocation (Cont.)
▪ Mapping from logical to physical
(block size =512 bytes)
▪ Block to be accessed = starting
address + Q
▪ Displacement into block = R
LA/512
Q
R
- 33. 14.33 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Linked Allocation
▪ Each file is a linked list of blocks
▪ File ends at nil pointer
▪ No external fragmentation
▪ Each block contains pointer to next block
▪ No compaction, external fragmentation
▪ Free space management system called when new
block needed
▪ Improve efficiency by clustering blocks into groups but
increases internal fragmentation
▪ Reliability can be a problem
▪ Locating a block can take many I/Os and disk seeks
- 34. 14.34 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Linked Allocation Example
▪ Each file is a linked list of disk blocks: blocks may be scattered
anywhere on the disk
▪ Scheme
- 35. 14.35 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Linked Allocation (Cont.)
▪ Mapping
▪ Block to be accessed is the Qth block in the linked chain
of blocks representing the file.
▪ Displacement into block = R + 1
LA/51
1
Q
R
- 36. 14.36 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
FAT Allocation Method
▪ Beginning of volume has table, indexed by block number
▪ Much like a linked list, but faster on disk and cacheable
▪ New block allocation simple
- 38. 14.38 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Indexed Allocation Method
▪ Each file has its own index block(s) of pointers to its data blocks
▪ Logical view
- 40. 14.40 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Indexed Allocation – Small Files
▪ Need index table
▪ Random access
▪ Dynamic access without external fragmentation, but have
overhead of index block
▪ Mapping from logical to physical in a file of maximum size of 256K
bytes and block size of 512 bytes. We need only 1 block for index
table
▪ Calculation:
• Q = displacement into index table
• R = displacement into block
LA/512
Q
R
- 41. 14.41 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition
Indexed Allocation – Large Files
▪ Mapping from logical to physical in a file of unbounded
length (block size of 512 words)
• Linked scheme – Link blocks of index table (no limit on
size)
• Multi-level indexing