COS 318: Operating Systems File Layout and DirectoriesTopicsFile System ComponentsSteps to Open A FileFile Read and WriteDisk LayoutData Structures for Disk AllocationContiguous AllocationLinked Files (Alto)File Allocation Table (FAT)Single-Level Indexed FilesDEMOS (Cray-1)Multi-Level Indexed Files (Unix)What’s in Original Unix i-node?ExtentsNamingDirectory Organization ExamplesLinear ListTree Data StructureHashingDisk I/Os to Read/Write A FileLinksOriginal Unix File SystemBSD FFS (Fast File System)FFS Disk LayoutWhat Has FFS Achieved?SummaryCOS 318: Operating SystemsFile Layout and Directories2TopicsFile system structureDisk allocation and i-nodesDirectory and link implementationsPhysical layout for performance3File System ComponentsNamingFile and directory namingLocal and remote operationsFile accessImplement read/write and other functionalitiesBuffer cacheReduce client/server disk I/OsDisk allocationFile data layoutMapping files to disk blocksManagementTools for system administrators to manage file systemsFile namingFile accessBuffer cacheDisk allocationManagementVolume manager4Steps to Open A FileFile name lookup and authenticateCopy the file descriptors into the in-memory data structure, if it is not in yetCreate an entry in the open file table (system wide) if there isn’t oneCreate an entry in PCBLink up the data structuresReturn a pointer to userProcesscontrolblock...OpenfilepointerarrayOpen filetable(system-wide)Filedescriptors(Metadata)FiledescriptorsFile systeminfoDirectoriesFile data5File Read and Write Read 10 bytes from a file starting at byte 2?seek byte 2fetch the blockread 10 bytesWrite 10 bytes to a file starting at byte 2?seek byte 2fetch the blockwrite 10 bytes in memorywrite out the block6Disk LayoutBoot blockCode to bootstrap the operating systemSuper-block defines a file systemSize of the file systemSize of the file descriptor areaFree list pointer, or pointer to bitmapLocation of the file descriptor of the root directoryOther meta-data such as permission and various timesKernel keeps in main memory, and is replicated on disk tooFile descriptorsEach describes a fileFile data blocksData for the files, the largest portion on diskSuperblockFile descriptors(i-node in Unix)File data blocksBootblock7Data Structures for Disk AllocationThe goal is to manage the allocation of a volumeA file header for each fileDisk blocks associated with each fileA data structure to represent free space on diskBit map that uses 1 bit per block (sector)Linked list that chains free blocks together…11111111111111111000000000000000…0000011111111000000000011111111111000001111000111100000000000000linkaddrsizelinkaddrsize…Free8Contiguous AllocationRequest in advance for the size of the fileSearch bit map or linked list to locate a spaceFile headerFirst block in fileNumber of blocksProsFast sequential accessEasy random accessConsExternal fragmentation (what if file C needs 3 blocks)Hard to grow files: may have to move (large) files on diskMay need compactionFile A File B File C9Linked Files (Alto)File header points to 1st block on diskA block points to the nextProsCan grow files dynamicallyFree list is similar to a fileNo external fragmentation or need to move filesConsRandom access: horribleEven sequential access needs one seek per blockUnreliable: losing a block means losing the restFile headernull. . .10217File Allocation Table (FAT)ApproachTable of “next pointers”, indexed by block•Instead of pointer stored with blockDirectory entry points to 1st block of fileProsNo need to traverse list to find a blockCache FAT table and traverse in memoryConsFAT table takes lots of space for large disk•Hard to fit in memory; so may need seeksPointers for all files on whole disk are interspersed in FAT table•Need full table in memory, even for one file•Solution: indexed files•Keep block lists for different files together, and in different parts of disk619399foo217EOFFAT039961911Single-Level Indexed FilesA user declares max sizeA file header holds an array of pointers to point to disk blocksProsCan grow up to a limitRandom access is fastConsClumsy to grow beyond the limitStill lots of seeksFile headerDiskblocks12DEMOS (Cray-1)IdeaUsing contiguous allocationAllow non-contiguousApproach10 (base,size) pointersIndirect for big filesPros & consCan grow (max 10GB)fragmentationfind free blocksdata... (base,size)... (base,size)data...13Multi-Level Indexed Files (Unix)13 Pointers in a header10 direct pointers11: 1-level indirect12: 2-level indirect13: 3-level indirectPros & ConsIn favor of small filesCan growLimit is 16G and lots of seek1 2 datadata...11 12 13 data... ... data... ... data... ...14What’s in Original Unix i-node?Mode: file type, protection bits, setuid, setgid bitsLink count: number of directory entries pointing to thisUid: uid of the file ownerGid: gid of the file ownerFile sizeTimes (access, modify, change)No filename??10 pointers to data blocksSingle indirect pointerDouble indirect pointerTriple indirect pointer15ExtentsInstead of using a fix-sized block, use a number of blocksXFS uses 8Kbyte blockMax extent size is 2M blocksIndex nodes need to haveBlock offsetLengthStarting blockIs this approach better than the Unix i-node approach?Block offsetlengthStarting block . . .16NamingText nameNeed to map it to indexIndex (i-node number)Ask users to specify i-node numberIconNeed to map it to index or map it to text then to index17Directory Organization ExamplesFlat (CP/M)All files are in one directoryHierarchical (Unix)/u/cos318/fooDirectory is stored in a file containing (name, i-node) pairsThe name can be either a file or a directoryHierarchical (Windows)C:\windows\temp\fooUse the extension to indicate whether the entry is a directory19Linear ListMethod<FileName, i-node> pairs are linearly stored in a fileCreate a file•Append <FileName, i-node>Delete a file•Search for FileName•Remove its pair from the directory•Compact by moving the restProsSpace efficientConsLinear
View Full Document