4File-System Structure Provide efficient and convenient access to diskEasy access to the data (store, locate and retrieve)Two aspectsUser’s viewDefine files/attributes, operations, directoryImplementing file systemData structures and algorithms to map logical view to physical one
5Disk Layout Files stored on disks. Disks broken up into one or more partitions, with separate file system on each partition
7Directory StructureA collection of nodes containing information about all filesF 1F 2F 3F 4F nDirectoryFiles
8Layered File System Manages FCB Translates logical to physical blocks Issue commandsEach level uses the feature of low levelCreate new features for higher levelR/W Physical block (cylinder, track, sector)Hardware specific instructionDevice driver, transfer information between memory/disk
9Manages meta date about files, file organization, directory structure, file control blocks, etc. Mapping of logical block# (0..n) to physical block# (sector, track #, etc), free space mgmtIssues generic commands to device drive to R/W physical blocks on diskDevice drivers, interrupt service routines, etc
10File System LayersI/O control layer consists of device drivers manage I/O devices at the I/O control layerGiven commands like “read drive1, cylinder 72, track 2, sector 10, into memory location 1060” outputs low-level hardware specific commands to hardware controllerBasic file system Issues commands with physical block address (sector, track)File organization module understands files, logical address, and physical blocksTranslates logical block # to physical block #Manages free space, disk allocation
11File System Layers (Cont.) Logical file system manages metadata informationTranslates file name into file number, file handle, location by maintaining file control blocks (inodes in Unix)Directory managementLayering useful for reducing complexity and redundancy, but adds overhead and can decrease performanceShares the I/O control and basic FSMany file systems, sometimes many within an operating systemEach with its own format (CD-ROM is ISO 9660; Unix has UFS, FFS; Windows has FAT, FAT32, NTFS as well as floppy, CD, DVD, Linux has more than 40 types, with extended file system ext2 and ext3 leading; plus distributed file systems, etc)
13Disk LayoutFiles stored on disks. Disks broken up into one or more partitions, with separate file system on each partitionSector 0 of disk is the Master Boot RecordUsed to boot the computerEnd of MBR has partition table. Has starting and ending addresses of each partition.One of the partitions is marked active in the master boot table
15Booting sequence Checks system integrity Loads and executes the boot loaderMaster Boot RecordOccupies the first sector of the diskSpecifies the disk blocks numbers where second stage boot loader residesGrand Unified Boot Loader
17Disk LayoutBoot control block contains info needed by system to boot OS from that partitionNeeded if partition contains OS, usually first block of partitionPartition control block (superblock, master file table) contains partition detailsTotal # of blocks, # of free blocks, block size, free block pointers or arrayDirectory structure organizes the filesNames and inode numbers, master file tablePer-file File Control Block (FCB) contains many details about the fileInode number, permissions, size, datesNTFS stores into in master file table using relational DB structures
20In-Memory File System Structures In memory directory structure holds the directory information of recently accessed directoriesSystem-wide-open file contains a copy of FCB for each filePer-process open file table: contains pointer to appropriate entry in the system wide open file table
21File handling Create a new file Logical file system Application program calls the logical file systemLogical file systemAllocates a new FCBReads the appropriate directory into memoryUpdates directory with new filename and FCBWrite it back to diskUsing the file (I/O)Open() [filename]Directory is searchedFCB is copied into system wide open file tableEntry made to Per-process open file tablePointer to the system table entryFile descriptor#
24All processes closed the file A process closes a filePer process table entry removedSystem table count decrementedAll processes closed the fileUpdated file info is copied back to diskSystem wide open file table entry removed
25Allocating Blocks to files An allocation method refers to how disk blocks are allocated for filesMost important implementation issueMethodsContiguous allocationLinked list allocationLinked list using tableI-nodes
26Allocation Methods - Contiguous Contiguous allocation – each file occupies set of contiguous blocksBlocks are allocated b, b+1, b+2,…….Best performance in most casesSimple – only starting location (block #) and length (number of blocks) are required (directory)Easy to implementRead performance is great. Only need one seek to locate the first block in the file. The rest is easy.Accessing file is easyMinimum disk head movementSequential and direct access
28Do not know the file size a priori ProblemsFinding space for fileSatisfy the request of size n from the list of holesExternal fragmentationNeed for compaction routineoff-line (downtime) or on-lineDo not know the file size a prioriTerminate and restartOverestimateCopy it in a larger holeAllocate new contiguous space (Extent)
29Extent-Based SystemsMany newer file systems (i.e., Veritas File System) use a modified contiguous allocation schemeExtent-based file systems allocate disk blocks in extentsAn extent is a contiguous block of disksExtents are allocated for file allocationA file consists of one or more extents
30Contiguous Allocation (a) Contiguous allocation of disk space for 7 files.(b) The state of the disk after files D and F have been removed.
31Allocation Methods - Linked Linked allocation – each file a linked list of blocksNo compaction, external fragmentationFree space management system called when new block neededReliability can be a problemLocating a block can take many I/Os and disk seeks
32Linked AllocationEach file is a linked list of disk blocks: blocks may be scattered anywhere on the diskpointerblock =Each block contains pointer to next blockFile ends at nil pointer
33Linked List Allocation Storing a file as a linked list of disk blocks.
35Linked Allocation Disadvantage Free blocks are arranged from the free space managementNo external fragmentationFiles can continue to growDisadvantageEffective only for sequential accessRandom/direct access (i-th block) is difficult2. Space wastageIf block size 512 BDisk address 4BEffective size 508B3. ReliabilityLost/damaged pointerBug in the OS software and disk hardware failure4. Poor performanceSolution: ClustersImproves disk access time (head movement)Decreases the space needed for blockInternal fragmentation
37Linked Allocation FAT (File Allocation Table) variation Beginning of partition has table, indexed by block numberMuch like a linked list, but faster on disk and cacheableNew block allocation simpleSection of the disk at the beginning of the partition contains FAT tableUnused blocks => 0
45Combined Scheme: UNIX UFS (4K bytes per block, 32-bit addresses) Note: More index blocks than can be addressed with 32-bit file pointer
46Implementing Directories OS uses path name supplied by the user to locate the directory entryStores attributesDirectory entry specifies block addresses by providingNumber of first block (contiguous)Number of first block (linked)Number of i-node
47Implementing MS DOS Directories Each entry 32 bytes long
50The UNIX File SystemThe steps in looking up /usr/ast/mbox.
51Directory Implementation Linear list of file names with pointer to the data blocksSimple to programTime-consuming to executeLinear search timeNew file creation / deletionCache the frequently accessed entryBinary search to speedup directory searchCould keep ordered alphabetically via linked listor use B+ tree
52Hash Table – hash data structure Hash value computed from filenameDecreases directory search timeInsertion and deletion simpleCollisions – situations where two file names hash to the same locationChainingHash table of fixed sizeOnly good if entries are fixed size (CD-ROM)Performance depends on hash function
53Free-Space Management File system maintains free-space list to track available blocksBit vector or bit map (n blocks)Each block is represent by 1 bit12n-1…1 block[i] free0 block[i] occupiedbit[i] =MacSimple and Efficient to find first free blocks or n consecutive free blocksCPUs have instructions to return offset within word of first “1” bit1Bit mapword(number of bits per word) *(number of 0-value words) +offset of first 1 bitBlock number calculation=
54Free-Space Management Bit map requires extra spaceExample:block size = 4KB = 212 bytesdisk size = 240 bytes (1 terabyte)Number of blocks n = 240/212 = 228 bits (or 256 MB)if clusters of 4 blocks -> 64MB of memoryKeep the vector in main memory
55Linked Free Space List on Disk Link together all the free disk blocksKeep a pointer to the first free blockCannot get contiguous space easilyTraverse the listGenerally require first free block
56Free-Space Management GroupingReserve few disk blocks for managementModify linked list to store address of next n-1 free blocks in first free block, plus a pointer to next block that contains free-block-pointers
57Keeping Track of Free Blocks (1) Storing the free list using (a) Grouping (b) Bitmap.
581KB block 16 bits block number Each block holds 511 free blocks 20M disk needs 40 blocks for free list How many for bit map?
60Demand Paging Example Memory access time = 200 nanoseconds Average page-fault service time = 8 millisecondsEAT = (1 – p) x p (8 milliseconds)= (1 – p ) x p x 8,000,000= p x 7,999,800If one access out of 1,000 causes a page fault, thenEAT = 8.2 microseconds.This is a slowdown by a factor of 40!!If want performance degradation < 10 percent220 > ,999,800 x p 20 > 7,999,800 x pp << one page fault in every 400,000 memory accessesBetter utilization of swap spaceSwap space
61Layered File System Manages FCB Translates logical to physical blocks Issue commandsEach level uses the feature of low levelCreate new features for higher levelR/W Physical block (cylinder, track, sector)Hardware specific instructionDevice driver, transfer information between memory/disk