26 - File Systems
Secondary storage management Disk space management Free space management Disk is divided into blocks or sectors.
Disk space management When to allocate space? Portion size Pre-allocation vs. dynamic allocation. Portion size Large variable-sized portions consisting of contiguous blocks Placement algorithms – Best fit, First fit and Next fit Small fixed portions (non-contiguous blocks)
Disk space management File allocation methods Keep track of which sectors/blocks on the disk belong to which logical file/directory.
Contiguous File Allocation What happens if file F requires 6 blocks?
Contiguous allocation
File allocation methods - contiguous Contiguous set of blocks is allocated to a file. File allocation table entry is simple Start of the file and size of the file. Entire file/directory can be read from the disk in one operation. Good for sequential access. External fragmentation occurs Frequent compaction required. Pre-allocation is required. Maximum file size should be known.
File allocation method - Chained allocation/Linked list
Chained allocation/Linked list
Chained allocation after consolidation
Chained allocation/Linked list allocation No external fragmentation File allocation table entry is simple Pointer to first block (and # of blocks) Inefficient with random access files. Consolidation is performed. Pre-allocation is possible, but more common to dynamically allocate.
Linked list allocation with an index File A occupies a total of _______ blocks and they are ________________. File B occupies a total of _____ blocks and they are __________________.
Linked list allocation with index A table is maintained in memory which acts as the linked list. Don’t have to access the disk to get the next pointer More efficient with random access files. Used in MS-DOS
Indexed allocation
Indexed file allocation No external fragmentation. Random access of file is efficient. File allocation table entry is simple Pointer to index-node (i-node) Used in UNIX. Can optimize disk reads as all data blocks are known.
Free space management Disk allocation table to keep track of all the used and unused blocks on the disk.
Free space management Disk allocation table to keep track of all the used and unused blocks on the disk. Bit maps/tables Chained free portions Free block list
Free space management
Bit maps/tables a bit for every block 1 => in-use 0 => available. Relatively small amount of storage required. Easy to find contiguous set of free blocks. The number of blocks required to hold the bit map is fixed. Held in memory
Chained free portions Each free portion has a pointer to the next free portion. No disk allocation table required. Must read a free block before you can write to it. To determine the next free block (for updating).
Free block list Every block is assigned an id in sequential order. In a reserved part of the disk, a list of the ids of free blocks is maintained. Some part of the list can be placed in memory for quick access. The id size depends on the number of blocks on disk. The number of blocks required to hold the ids depends on how many blocks are free.
Indexing Treat free space like a large file Maintain an index of all the free blocks. Use variable-size portions for allocation and this will reduce the size of the index table.