Part III Part III Storage Management Storage Management Chapter 11: File System Implementation Chapter 11: File System Implementation 1 Fall 2010
Layered Layered File System 2
Overview : 1/4 Overview : 1/4 � A file system has on-disk and in-memory information. o o . � A disk may contain the following for implementing a file system on it: � A boot control block per volume � A volume control block per volume � A directory structure per file system � A di t t t fil t � A file control block (FCB) per file � In-memory information include � In-memory information include � An in-memory mounted table has info for each mounted volume � An in-memory directory structure � The system-wide open-file table � The per process open file table � The per-process open-file table � Buffers hold file-system blocks 3
Overview : Overview : Overview : 2/4 Overview : 2/4 2/4 2/4 � A FCB f il � A FCB, f ile c ontrol t l a typical file control block FCB b lock, contains the file permission file permission details of a file. d t il f fil � In Unix, a FCB is file date called an i-node. file owner, group, ACL file size file data blocks 4
Overview : Overview : Overview : 3/4 Overview : 3/4 3/4 3/4 3: read the directory 4: update FCB and directory kernel memory e e e o y d s disk memory e o y user program open(filename) directory structure directory structure 1: 1: create a new file FCB 5: a file descriptor/file handle 5 fil d i /fil h dl 5 is returned 2: allocate a new FCB
Overview : Overview : Overview : 4/4 Overview : 4/4 4/4 4/4 index kernel memory e e e o y disk memory d s e o y user program per-process open-file table Data blocks Data blocks system-wide read(index) open-file table p FCB 6
Directory Directory Directory Implementation Directory Implementation Implementation mplementation � A Fil di � A File directory is usually implemented as a t i ll i l t d linked-list, a tree ( e.g ., B-tree), a hash table with chaining, or the combination of both. ith h i i th bi ti f b th � The problem with the linked-list approach is its poor performance in searching for a file. Directory search is performed very frequently. � The hash table approach speeds up search; however, we must deal with the problem of p collisions. Thus, chaining is necessary. 7
Directory Directory Entries: Directory Directory Entries: Entries: 1/2 ntries: 1/2 1/2 1/2 � A directory is just a file! � A directory is just a file! � A directory entry may be very simple like the one used by MS DOS Or it may be quite one used by MS-DOS. Or, it may be quite complex like the Unix i-node . extended MS-DOS directory entry used in Windows 98 O 9 8
Directory Entries: Directory Entries: 2/2 2/2 find /usr/ast/mbox find /usr/ast/mbox Unix directory entry 9
File Allocation Methods File Allocation Methods � There are three typical file space allocation methods: h d � Contiguous Allocation � Linked Allocation � Indexed Allocation � Indexed Allocation 10
C Con C onti tiguous ti t guous All All Alloca ocati ti tion: on: 1/3 1/3 1/3 1/3 � With the contiguous allocation method, a user � With th ti ll ti th d must indicate the file size before creating a file. � Then, the operating system searches the disk to find contiguous disk blocks for the file. � The directory entry is easy. It contains the initial disk address of this file and the number of disk blocks. � Therefore, if the initial address is b and the � Therefore, if the initial address is b and the number of blocks is n , the file will occupy blocks b , b +1, b +2, …, b + n -1. b 1, b 2, …, b n 1. 11
Contiguous Allocation: Contiguous Allocation: 2/3 2/3 directory directory Since blocks are allocated contiguously, external g y, fragmentation may occur. Thus, compaction may be needed. 12
Contiguous Contiguous Allocation: Contiguous Contiguous Allocation: Allocation: 3/3 Allocation: 3/3 3/3 3/3 � Contiguous allocation is easy to implement � Contiguous allocation is easy to implement. � Its disadvantages are � It can be considered as a form of dynamic memory allocation, and external fragmentation may occur and compaction may be needed. � It is difficult to estimate the file size. The size of a file may grow at run time and may be larger than the specified number of allocated blocks. p In this case, the OS must move the blocks in order to provide more space. In some systems, p p y this is simply an error. 13
Li Li Linked All Li k d All All Alloca ocati ti tion: on: 1/3 1/3 1/3 1/3 � With the linked allocation approach, disk � With th li k d ll ti h di k blocks of a file are chained together with a li k d li t linked-list. � The directory entry of a file contains a pointer to the first block and a pointer to the last block. � To create a file, we create a new directory entry y y and the pointers are initialized to nil. � When a write occurs, a new disk block is � When a write occurs, a new disk block is allocated and appended to the end of the list. 14
Linked Linked Linked Allocation: Linked Allocation: Allocation: 2/3 Allocation: 2/3 2/3 2/3 directory File Name Start End ………… …….. …….. Last Block Last Block 28 B 1 28 ………… …….. …….. � File blocks are chained into a linked-list. linked list. � The directory entry has pointers to the first and last file blocks to the first and last file blocks. � Append is difficult to do without th E d the End pointer. i t 15
Linked Linked Allocation: Linked Linked Allocation: Allocation: 3/3 Allocation: 3/3 3/3 3/3 � Advantages: � Advantages: � File size does not have to be specified. � No external fragmentation � No external fragmentation. � Disadvantages: � It s pports seq ential access efficientl � It supports sequential access efficiently, and is and is not for direct access � Each block contains a pointer � Each block contains a pointer, wasting space asting space � Blocks scatter everywhere and a large number of disk seeks may be necessary of disk seeks may be necessary � Reliability: what if a pointer is lost or damaged? 16
File File File Allocation File Allocation Allocation Table Allocation Table Table (FAT) able (FAT) (FAT) FAT) FAT � This is a variation of the � This is a variation of the 0 0 linked allocation by pulling all pointers into a t bl table, the file allocation th fil ll ti 217 618 directory table (FAT). � The left diagram shows � The left diagram shows test file test has its first 339 end-of-file block at 217 , followed by 618 339 ( 618 , 339 (end of file). d f fil ) 217 � Large no. of disk seeks. 618 339 � Can do direct access � Can do direct access. � FAT needs space. � What if FAT is damaged? � What if FAT is damaged? no. of blocks-1 f bl k 1 We all know it well! 17
Indexed Indexed Indexed Allocation: Indexed Allocation: Allocation: 1/4 Allocation: 1/4 1/4 1/4 � Each file has an index block that is an array of � Each file has an index block that is an array of disk block addresses. � The i -th entry in the index block points to the i -th � Th i th t i th i d bl k i t t th i th block of the file. � A file’s directory entry contains a pointer to its index. Hence, the index block of an indexed allocation plays the same role as a page table does. � Index allocation supports both sequential and pp q direct access without external fragmentation. 18
Indexed Indexed Allocation: Indexed Indexed Allocation: Allocation: 2/4 Allocation: 2/4 2/4 2/4 directory index block 19
Indexed Indexed Allocation: Indexed Indexed Allocation: Allocation: 3/4 Allocation: 3/4 3/4 3/4 � Th i d � The indexed allocation suffers from wasted space. d ll ti ff f t d The index block may not be fully used ( i.e ., internal f fragmentation). t ti ) � The number of entries of an index table determines the size of a file. To overcome this problem, we may � Have multiple index blocks and chain them into p a linked-list � Have multiple index blocks, but make them a � Have multiple index blocks, but make them a tree just like the indexed access method � A combination of both � A combination of both 20
Indexed Allocation: Indexed Allocation: 4/4 4/4 256 entries per index table. What is the maximum size of a file? 21
Free Free Free Space Free Space Space Management Space Management Management Management � How do we keep track free blocks on a disk? � How do we keep track free blocks on a disk? � A free-list is maintained. When a new block is requested, we search this list to find one. t d h thi li t t fi d � The following are commonly used techniques: � Bit Vector � Linked List � Linked List � Linked List + Grouping � Li k d Li t+Add � Linked List+Address+Count +C t 22
Recommend
More recommend