Peeking Inside Peeking Inside Persistent storage modeled as a sequence of N blocks Persistent storage modeled as a sequence of N blocks from 0 to N-1 from 0 to N-1 4KB in this example 4KB in this example some blocks store data some blocks store data other blocks store metadata (remember stat() ?) an array of inodes at 256 bytes, 16 per block: file system can have up to 80 files data nodes data nodes data nodes D D D D D D D D D D D D D D D D D D D D D D D D 0 7 8 15 16 23 24 31 0 7 8 15 16 23 24 31 data nodes data nodes data nodes data nodes D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D 32 39 40 47 48 55 56 63 32 39 40 47 48 55 56 63 Peeking Inside Peeking Inside Persistent storage modeled as a sequence of N blocks Persistent storage modeled as a sequence of N blocks from 0 to N-1 from 0 to N-1 4KB in this example 4KB in this example some blocks store data some blocks store data other blocks store metadata (remember stat() ?) other blocks store metadata (remember stat() ?) an array of inodes an array of inodes at 256 bytes, 16 per block: file system can have up to 80 files at 256 bytes, 16 per block: file system can have up to 80 files two blocks with bitmaps tracking free inodes and data blocks free inodes data nodes data nodes data nodes inodes data nodes data nodes data nodes lists I I I I I D D D D D D D D D D D D D D D D i d I I I I I D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D 0 7 8 15 16 23 24 31 0 7 8 15 16 23 24 31 data nodes data nodes data nodes data nodes data nodes data nodes data nodes data nodes D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D 32 39 40 47 48 55 56 63 32 39 40 47 48 55 56 63
<latexit sha1_base64="lZbA8PIsbTA6+UwZ/rInRg+Qew=">ACOnicdVDLTtAFB2ntKTpK5QlmxFRJVCjyC4IkREBuWVDQkUhxF4/E1jBh7rJlrpGD5a/gNuz4A9QtG4TYAOIDmCTtgj7u6uicM/fOUEqhUHX/emUXs28fjNbflt59/7Dx0/Vuc8HRmWaQ4crqXQvYAakSKCDAiX0Ug0sDiR0g+Odsd49AW2ESn7gKIVBzA4TEQnO0FLDat8AR6XpBvUjzXi+JIsDkBTH0UMhvoxwyOBuRGnoKLCyioEf4jLy36dfqV+fULsI9O4HYa6yKf79q29GFZrXsOdDP0/qG09tKzq0prb1i9EPFsxgS5JIZ0/fcFAe53S24hKLiZwZSxo/ZIeST6AX9YqmQRjZBpBKkE/aFj8XGjOLAOsdJzJ/amPyX1s8wag5ykaQZQsKnh6JMUlR03CMNhbZJ5cgCxrWwP6T8iNkK0bZdsdHdxsraqrfi0r/B7+gH3xreaqP53au1N8l0ymSBLJIl4pF10ia7ZI90CcX5Ibckwfn3Ll2bp27qbXk/HozT16M8/QM+Wyx4w=</latexit> Peeking Inside The uperblock Persistent storage modeled as a sequence of N blocks One logical superblock per file system from 0 to N-1 4KB in this example at a well-known location. some blocks store data contains metadata about the file system, including other blocks store metadata (remember stat() ?) how many inodes an array of inodes how many data blocks at 256 bytes, 16 per block: file system can have up to 80 files where the inode table begins two blocks with bitmaps tracking free inodes and data blocks magic number identifying file system type superblock free read first when mounting a file system inodes data nodes data nodes data nodes lists S i d I I I I I D D D D D D D D D D D D D D D D D D D D D D D D 0 7 8 15 16 23 24 31 data nodes data nodes data nodes data nodes D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D 32 39 40 47 48 55 56 63 The ext2 inode The inode (simplified) Size Name What is this inode field for? Low-level file name 2 mode can this file be read/written/ executed? 2 uid who owns this file? Locating an inode on disk 4 size how many bytes are in this file? sector : ( inumber × sizeof ( inode t )) + inodeStartAddr 4 time what time was this file last accessed? sectorSize 4 ctime what time was this file created? 4 mtime what time was this file last modified? iblock 0 iblock 1 iblock 2 iblock 3 iblock 4 4 dtime what time was this inode deleted? 0 1 2 3 16 17 18 19 32 33 34 35 48 49 50 51 64 65 66 67 4 gid which group does this file belong to? 4 5 6 7 20 21 22 23 36 37 38 39 52 53 54 55 68 69 70 71 Super i-bmap d-bmap 8 9 10 11 2 links_count how many hard links are there to this file? 24 25 26 27 40 41 42 43 56 57 58 59 72 73 74 75 12 13 14 15 28 29 30 31 44 45 46 47 60 61 62 63 76 77 78 79 2 blocks how many blocks have been allocated to this file? 0KB 4KB 8KB 12KB 16KB 20KB 24KB 28KB 32KB 4 flags how should ext2 use this inode? 4 osd1 an OS-dependent field inode 32 is on sector 40 60 block a set of disk pointers (15 total) 4 generation file version (used by NFS) can you see why? 4 file_acl a new permissions model beyond mode bits 4 dir_acl called access control lists
File structure Multilevel index Data blocks indirect block } contains pointers to data blocks Inode Array 12 x Each file is a fixed, asymmetric tree, with fixed Inode 4KB = double indirect block contains pointers to indirect blocks 48KB size data blocks (e.g. 4KB) as its leaves File } metadata The root of the tree is the file’ s inode 1K x 4KB at known = 4MB contains a set of pointers 4 Bytes entries location on disk typically 15 } file number = 1K x 1k x inode number = 4KB = first 12 point to data block index in the 4GB array last three point to intermediate blocks, themselves } containing pointers 13: indirect pointer 1K x 1k x 14: double indirect pointer 1k x 15: triple indirect pointer 4KB = triple indirect block 4TB contains pointers to double indirect blocks Multilevel index: Why Unbalanced Trees? key ideas (and other fun facts) Data Most files are small blocks Inode Tree structure array Roughly 2K is the most common size efficient in finding blocks Average file size is growing File High degree metadata Almost 200K is the average efficient in sequential reads Most bytes are stored in large files once an indirect block is read, A few big files use most of the space can read 100s of data block Fixed structure File systems contains lots of files simple to implement Almost 100K on average Asymmetric File systems are roughly half full supports efficiently files big Even as disks grow, file system remain about 50% full and small Directories are typically small Many have few entries; most have 20 or fewer
Directory Looking up a file A file that contains a collection of mapping from file Find file /Users/lorenzo/griso.jpg name to file number file 2 . 1061 “/” bin 438 /Users/lorenzo .. usr 782 256 Users 256 Documents 394 Music 416 chiara 1197 maria 294 griso.jpg file 256 864 lorenzo 1061 “/Users” To look up a file, find the directory that contains the Documents 394 mapping to the file number file 1061 Music 416 “/Users/lorenzo” griso.jpg 864 To find that directory, find the parent directory that contains the mapping to that directory’ s file number... Good news: root directory has well-known number (2) file 864 “/Users/lorenzo/griso.jpg” Directory Layout Reading a File First, must open the file Directory stored as a file open(“/CS4410/roster”, O_RDONLY) Linear search to find filename (small directories) Follow the directory tree, until we get to the inode for “roster” File 1061 Read that inode /Users/lorenzo do a permission check . .. Music Documents griso.jpg return a file descriptor fd End of File Free Space 1061 256 416 394 864 Free Space Then, for each read() read inode read appropriate data block (depending on offset) Larger directories use B trees update last access time in inode update file offset in in-memory open file table for fd searched by hash of file name
Recommend
More recommend