35 -OutlineFile AllocationRecap: AddressingContiguous AllocationLinked List AllocationFile Allocation TableIndexed Allocation (Inodes)Inode IndirectionExerciseAnnouncementsDirectoriesReading:File AllocationContiguousLinked ListFile Allocation Table (FAT)Indexed (Inodes)DirectoriesEach file occupies a contiguous disk blocksEach file is a linked list of blocksRequires at least 2 disk accesses:Translation from file offset:Pros:Cons:a file is defined by a starting block addressand the number of blocks in the filedirectory stores first and last block addressblocks can be scattered across the disk(start and size stored in directory)blockaddressblockoffset1)a)b)c)d)2)MOS 4.1 - 4.2; 4.3.1 - 4.3.3; 4.3.7Quiz 4 this FridayCreate your project groups on Canvas.Please try to do this by Today.File SystemsDisk (Block Device)File Datalogicalblockkernel block001N12M......file offsetblock address/number/indexblock offsetlogical block address/number/index------------------allocation in blocks (regardless of file size)first bytes of block contain pointer to next1 to read starting block from directory block1 to read starting block from directory blockeach table entry corresponds to a disk blockentry contains pointer to next block or -1load table from disk on startup and periodicallywrite backindex node (inode) keeps block indexes alongwith file metadata/attributesdirectory only needs to map name to inodeSimple to implementSpace inefficiencyFile growthGood performance on accessonly store start block # and # of blocksexternal fragmentation / compaction, etc.files can't grow into other filesentire file can be read sequentially1 to access data at block addressQ accesses to traverse Q blocksMOS Figure 4-12file offsetstartingblock addressfile offsetblock sizeblock size=+=%MOS Figure 4-13Translation from file offset:Requires many accesses:We can improve the random access time with RAM!Keep the pointers in a separate table in memoryinstead of in blocksAvoid traversal by creating data structure foreach file that holds pointers to file's data blocksblocks totraversefile offsetblock size - pointer size=blockoffsetfileoffsetblocksizepointersizepointersize=%-+account for the pointer at thebeginning of the block135791124681012file A startPros:Cons:---Simple to implementInefficient random accessEfficient space usageonly stores the starting addresstraverse linked list on every accesseasy to grow files, no wasted spaceMOS Figure 4-14135791124681012file A startTranslation from file offset:Access performance:Access performance:Inodes are the implementation of choice for manyoperating systems, including Linux's ext4 andWindows NTFSInode entries are pointers:Max file size grows exponentially with indirection!Exact inode structure depends on file systemA file system's inode looks like the following:Disk blocks are 1 kB.What is the maximum file size in this system?Directories map file names to:As mentioned, these can be in-band or out-of-bandDirectory file's contents are entriesblock totraverseblockoffsetfile offsetfile offsetblock sizeblock size==%Don't need to account for pointer anymore---------------------1 read to disk for starting block from directory1 read to disk to get inode # from directorydirectly to data blocks(direct)(contiguous allocation)(linked list / FAT)(indexed allocation)format of the entry can vary by file systemstart block of filestart block of fileinode number of file(singly indirect)(doubly indirect)etc.on Linux, to see inodeshow do we find a file?root has a special inode number (0, 1, 2)inodes can span multiple blockslookup is simplewalk down chain of inodes by searching for pathcomponentsResolving a file from a path starts from root.finding a filefinding an inodeRecall the disk layoutKeep all inodes in a dedicated region as an arrayhow do we find an inode?to blocks of pointers todata blocksto blocks of pointers ofblocks of pointers todata blocks1 access to disk for data1 access to disk for dataQ accesses to RAM to find block number1 read to disk for reading inode index tablePros:Cons:---Same advantages as FATEntire table stored in RAMFaster random access timesimple, efficient space usage1 table entry per block is infeasible for verylarge disks (256 GB - 5 TB)Used on old DOS systems (smaller disks backthen), still used on some USB flash drives andUEFI partitionsRAM is much faster to read than diskMOS Figure 4-15inodesblocksdatablocksTranslation from file offset:file blockindexblockaddressblockoffsetfile offsetinode.blocks[file_block_index]file offsetblock sizeblock size===%Pros:Cons:----Efficient random accessSupporting large filesLower RAM overhead than FATEfficient space usageLimited by inode table entries, but we can getaround this with indirectionblock_t *block_t **block_t ***MOS Figure 4-35direct pointers to data blocksls -istruct inode {  struct attributes; // not important  uint64_t direct[10];  uint64_t indir1[2];}df -ifilefilefilefoofoofoo1223191017startstartinodelengthendMOS Figure 4-16MOS Figure 4-32Example: original FAT (MS-DOS)NavigationExample: UNIX Inodeslater extended with 2 more bytes in FAT32for larger block addresses as disks gotbiggermetadataroot2inode2801inode2859datadirectoryinodedirectorydata block(directory entries)filenamesfilenamesfilenamesfoo.txtbinbashrc45686277554568620481932796110488292801285987292126048882010833bardevhostsbaz.cetcpasswddir1/homedir2/usrinodeinodeinodemap file names to inode numbers2 questions:Example: /etc/passwdSuperblockFree SpaceMgmt.InodesRootDirFiles & Directories