index.md (2505B)
1 +++ 2 title = 'File system layout' 3 +++ 4 # File system layout 5 on real disk, there are number of partitions (primary, extended, subpartitions). each partition can hold different filesystem 6 7  8 9 one partition is flagged as 'active' partition. 10 MBR has boot code to locate active primary partition and execute boot block 11 12 partitions: primary, extended, and subpartitions 13 14 ## How to store files on disk 15 16 contiguous allocation: 17 18 - files as contiguous stream of bytes 19 - but prone to fragmentation, requires max file size 20 21 block-based (logically contiguous, but actually stored anywhere on disk): 22 23 - linked list 24 - by keeping in-band metadata, end up with strange block size (2 or 4 kb data, with some bytes to hold pointer) 25 - good for sequential access patterns, but random...not so much 26 - pointers are pointing to blocks on disk (NOT memory) 27 -  28 - file allocation table (FAT) 29 - move in-band metadata out of band 30 - the table is stored in kernel memory 31 - holds starting points of files 32 - every row refers to a block of memory 33 - worked well for a while, but for modern sizes it is not possible to hold the table in memory 34 -  35 - I-nodes 36 - just a FUCKTON of indirections 37 -  38 39 ## How to implement directories 40  41  42 43 FAT layout: 44 45 - PBR stores "boot block" 46 - reserved is later used for filesystem info 47 - FAT #: preallocated file allocation table 48 - preallocated root dir (FAT12/FAT16) 49 - clusters are addressable blocks (FAT has chains indexed by starting cluster) 50 -  51 52 UNIX dir entry: 53 54 - dir entry stores only name and inode number 55 - attributes are stored in inode 56 - one inode per file, first inode is root 57 - links: 58 - hard link -- if 10 hard links to a file, then a single file with 10 dir entries pointing to that file (inode) 59 - soft (symbolic) link -- if 10 soft links to a file, literally 10 files. can point to anything, but if file gets deleted, the link is dead. 60 - where are the inode stored? it depends, as always. 61 62  63  64  65 66 how to manage disk space 67 68 - linked list vs bitmap (linked list actually works really well here) 69 70 