File Management-1
File Management-1
Topics to be Covered
• Concept of File
•Access methods
•File types
• File operation
•Directory structure
•File System structure
•Allocation methods (contiguous, linked, indexed)
•Free-space management (bit vector, linked list, grouping)
• Directory implementation (linear list, hash table)
•Efficiency and performance.
Basic File Concept
File types represents the internal structure of the file. According to the structure,
file is divided into certain types
1. Text file: It is the sequence of characters which are organized into lines. Text
file is a regular file
2. Source file: It contains sequence of subroutines, procedures and functions
3. Executable file: It contains a series of code sections. This file is input to the
loader and loader loads the file into memory then execute
4. Object file: An object file is a binary file that the compiler creates by
converting the source to object code
File types
•A directory file is like a folder that contains other files, including subdirectory files
•Directory files act as a container for the other files, of any category.
•Directory files don’t contain data,they merely contain references to the files
contained within them
•Directory is created in UNIX by the mkdir command
•Directory is removed by using rmdir command.
•Content of directory is displayed by ls command
Device file
1. create
2. write
3. Read
4. reposition within file – file seek
5. delete
6. open
7. Close
8. Truncate
9. Rename
10. Append
File structure
•File structure provides the mechanism for an on-line storage of and access to
both data and program of the OS and all the users of the computer system
•The general file structure are as follows
-Unstructured sequence of bytes
-Sequence of fixed-length records with internal structure
-Tree of records used with mainframe systems
File structure
File access method defines the way process read and write files. Access method
means accesses to files that use a particular file organization are implemented by
an input output control system
•Sequential access
•Index sequential method
•Direct/Random access
Access Methods
Sequential Access
read next
write next
reset
no read after last write
(rewrite)
Direct Access
read n
write n
position to n
read next
write next
rewrite n n = relative block
number
Sequential access method
•At the time of file creation, access method is defined. According to defined access
method, file is accessed
•Sequential access of direct file is possible but direct access of sequential file is
not
•A block number provided by the user to the operating system is normally
a relative block number.
•The first relative block of the file is 0 and then 1 and so on
F1 F2 F4
F3
Fn
Files
Directory structure[2]
Directory structure
There are various structure of directory
Directory
Disadvantages :-
Here several absolute path for files.
Another problem of deletion because when space allocated to shared to be de-
allocated.
General graph directory
•In Acyclic graph there is no cycles.
•When link is add to the existing tree structure directory then it is called general
graph directory.
General graph structure
•In Acyclic graph there is no cycles.
•In fig. avi is subdirectory of book,book is link with avi and avi is link with
book,HERE cycle is created between book and avi.
File sharing and protection
•File owner/creator should be able to control:
what can be done
by whom
•Types of access
Read
Write
Execute
File protection
•All data and information in computer system are stored in the form of files. So
protection of file required from physical damage of system or improper access of
file.
• Access is permitted or denied depending on several factors
Any other operation like Rename, Repositioning, and Truncate may be controlled.
Access list & Groups
Access List.
“Access list” method provide identity dependent file access associated with
each file and directory.
Access list specify the username and type of access allowed to each user,
when user request access to particular file, operating system check the access
list associated with file, if user listed for requested access, than access is
allowed, otherwise user can not access.
By using the command ls –l,we can see the long listing details about the file.
Groups
Many system classify the users in 3 group:
1. Owner: The user who created the file.
2. Group: A Group of user who sharing the file.
3. Universe/Others: All other users in the system.
In this type of protection, only 3 operation are required, Read-r ,Write-w, And
Execute-x .
Value assigned for these protection modes
Read(r) = 4, Write(w)= 2, Execute(x)=1
File sharing and protection
Mode of access: read, write, execute
Three classes of users.
RWX
a)Owner Access 7 111
c) Others/Global 1 001
•Ask manager to create a group (unique name), say G, and add some users to
the group.
•For a particular file (say game) or subdirectory, define an appropriate access.
File sharing and protection
• Attach a group to a file
chgrp G Amit
owner public
group
chmod 761
Amit
File allocation methods
•Many files are stored on the same storage device.
•Allocation of file means allocate the space for store the file on the disk.
•Files are stored in free blocks of disk. each block size is 512 bytes.
•There are three methods are used to allocate the space for file on disk.
-Contiguous allocation method
-Linked allocation method
-Indexed allocation method
Contiguous allocation method
•In this method, contiguously blocks are allocated to the file on disk.
•The first block is generated randomly so the block can be anywhere in memory
•Contiguous Allocation of file define by block address and length( total number of
block)
•For example, if a file requires n blocks and is given a block b as the starting
location, then the blocks assigned to the file will be: b, b+1, b+2,……b+n-1.
•This means that given the starting block address and the length of the file (in
terms of blocks required), we can determine the blocks occupied by the file.
Contiguous allocation method
•As the blocks are not in continuous order it suffers from the disadvantage of
Fragmentation.
•To overcome the disadvantages of Fragmentation, Compaction technique is used.
•In Compaction all the allocated blocks are grouped at the top and all the free
blocks are allocated later.
•So we get continuous block of memory after Compaction.
Contiguous allocation method
•Advantages
•Simple to implement
•Fast access of file
•Disadvantage
-Finding the free space on disk the blocks are not in continuous order it suffers
from the disadvantage of Fragmentation.
-To overcome the disadvantages of Fragmentation, Compaction technique is used.
-In Compaction all the allocated blocks are grouped at the top and all the free
blocks are allocated later.
-So we get continuous block of memory after Compaction.
Linked allocation method
•The file ‘jeep’ in following image shows how the blocks are randomly distributed.
The last block (25) contains -1 indicating a null pointer and does not point to any
other block.
•Here all blocks are linked.
•Same procedure is for other file.
•Linked allocation can support only sequential access. It is not support direct
access.
•Linked allocation is also called chain allocation.
Linked allocation method
Advantages
-Any free block can be allocated
Disadvantages
-In linked allocation is each block contain the pointer to next block of file, 4 byte is
used to store the pointer of block of 512 bytes.
-It users a pointer so if a pointer field consist of error it gives error that a whole file
is corrupted as maintenance of pointer is difficult
-The major problem is that it can be used only for sequential access-files.
-So only 508 byte of data can be stored.
Indexed allocation
•In index allocation all pointer for blocks are bringing together into only one block
of disk. In index allocation all pointers are put into one block. This block is called
index block.
•Each file has its own index block, which contain the pointer address of all blocks
of files which are allocated on disk.
•In index allocation directory entry contain the filename and index block.
Indexed allocation
•For example : In fig file jeep, has index block 19, means blocks 19 will contain the
pointer of all blocks of file.
•here block 19 is containing address of block 1,9,10,16, and 25.
•Every file has only one index block. and it should be unique.
•Index allocation supports direct access.
•No more than one file has same index block.
Disadvantage: - In index allocation there are lot of waste of space into the index
block. Because index block of 512 byte contain only address of pointer, so
maximum space is waste into the index block.
Memory management / Free space management
using Bitmap and Linked list allocation
•Files are created and deleted frequently by the user of Computer system. If the
files are created and its not being used for larger time it unnecessary uses an
memory.
•Since disk space is to be allocated to files, the free space available must be
managed so as to allocate space to the new files being created
•To retain the information about the free disk space, the system maintains a free-
space list. The free-space list keeps information about the free disk blocks
•Two methods are used for free memory management
1) Bit Map
2) Linked List
Memory management by Bitmap
•This method represents the allocation status of disk block as a bit map or bit
vector.
•Each block is represented by 1 bit. If the block is free, the bit is 0; if the block is
allocated, the bit is 1
•For example, consider a disk with 30 blocks
•The bit map can be: 000001111001111110001100000011
•If the blocks 2,3,4,5,8,9,10,11,12,13,17,18,25 are free then
• 001111001111110001100000010000…….
•The main advantages of this method is its relatively simple and n contiguous free
blocks that can be found together
•Each time a new block is to be allocated to a file, the bit vector will be updated
respectively.
Memory management by Linked list
•In this method of free space management, all the free blocks are linked with each
other and the pointer referencing to the first free block is placed in a special
location on the disk and cached in memory
•This first block holds an address pointing to the next free disk block and so on
•However, this method is not efficient because traversing of the list requires the
reading of each block, which consumes more I/O time
Memory management by Linked list
•There are 2 methods to implement file system depend on the types of the
operating system
•On-disk structure
•In-memory structure
On-disk structure for file implementation
implementation
•On disk, file system may contain information about how to boot an operating
system stored there, total number of blocks, the number and location of free
blocks, the directory structure and individual files. Some of these structures are
described as follows:
•Boot control block(per volume): It can contain information needed by the system
to boot an operating system from that volume. If disk does not contain OS, this
block can be empty. This is typically the first block of a volume. In UFS, it is called
boot block; in NTFS it is called partition boot sector
On-disk structure for file implementation
implementation
•Volume control block(per volume): it contains volume (or partition) details, such
as number of blocks in a partition, the size of block, a free block count, a free
block pointers and free FCB count and free FCB pointers. In UFS, it is called
superblock; in NTFS, it is stored in master file table
•A directory structure (per file system) is used to organize the files. In UFS, this
include file names and associated inode number. In NTFS, it is stored in master file
table
•A per-file FCB(File control block) contains many details about the file. It has
unique identifier number to allow association with a directory entry.
Typical FCB is shown in figure
•In NTFS, this information is actually stored within master file table which uses
relational database structure, with a row per file
•The in-memory information is used for both file system management and
enhancing the performance through caching. This structure includes the following:
•In-memory partition table: it contains the information about each mounted
partition.
•An in-memory directory structure: This directory structure cache holds the
directory information of recently accessed directories
•System-wide open-file table: It is used to maintain a copy of FCB of opened file
along with its other information
•Per-process open-file table: it has a pointer to the suitable entry in the system-
wide open-file table along with other information
Directory Implementation
•There are many causes that are responsible for computer crashes or physical
damage, and in this situation, file systems are expected to behave sensibly. These
problem may result in file system consistencies
•In order to check consistency, we need to observe the following:
•All data and control structure, such as descriptors and bitmaps should be in
an appropriate arrangements
•When a system reboots, it should return to a valid state
•It at the time of crash, a write operation is in progress, then the operation is
either finished or rollback completely. This is called atomicity
File system recovery
•Consistency checker: at the time of reboot, a program called consistency checker,
is executed in order to check and correct disk inconsistencies
•The consistency checker matches the data available in the directory structure
with the data stored in blocks of disk and if it finds any inconsistencies, then it
tries to fix it
•Methods of file system recovery
-Backup and restore
-Log-structured file system
Backup and recovery
•When the magnetic disks fails, a backup of disk may be taken on another storage
device in order to restore the system
•For minimizing the copy, the time when the last file was modified and the backup
taken can be considered
•The file’s last write date in the directory structure specifies that the file has not
changed since that date, and then it is not required to copy that file again
Log structured file system
•The main purpose of using the log structured file system is to enhance the write
performance
•It buffers a series of file system changes in the file cache and them write all such
changes to the disk sequentially in a single write operation
•Once the changes are written to the log, user process are allowed to continue
execution
•It transaction is completed, it removes the log files
•If the system crashes, there will be zero or more transactions in a log file.
Therefore they must be completed, and the file system structure remain
consistent.
Virtual file system