8 File-System Structure Provide efficient and convenient access to diskEasy access to the data (store, locate and retrieve)Two aspectsUser’s viewImplementing file systemData structures and algorithms to map logical view to physical one
9 File-System Structure File structureLogical storage unitCollection of related informationFile system resides on secondary storage (disks)Provides efficient and convenient access to disk by allowing data to be stored, located, retrieved easilyDisk provides in-place rewrite and random accessI/O transfers performed in blocks of sectors (usually 512 bytes)File control block – storage structure consisting of information about a fileDevice driver controls the physical deviceFile system organized into layers
10 Layered 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 instruction
11 File 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
12 File 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 Blu-ray, Linux has more than 40 types, with extended file system ext2 and ext3 leading; plus distributed file systems, etc)
14 Disk 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
15 Disk 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
18 In-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
19 File 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#
21 All 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
22 Allocating 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
23 Allocation 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
24 Do 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)
26 Extent-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
27 Contiguous Allocation (a) Contiguous allocation of disk space for 7 files.(b) The state of the disk after files D and F have been removed.
28 Allocation Methods - Linked Linked allocation – each file a linked list of blocksNo compaction, external fragmentationFree space management system called when new block neededImprove efficiency by clustering blocks into groups but increases internal fragmentationReliability can be a problemLocating a block can take many I/Os and disk seeksFAT (File Allocation Table) variationBeginning of partition has table, indexed by block numberMuch like a linked list, but faster on disk and cacheableNew block allocation simple
29 Linked 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
30 Linked List Allocation Storing a file as a linked list of disk blocks.
32 Linked 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 failureSolution: ClustersImproves disk access time (head movement)Decreases the space needed for blockInternal fragmentation
33 Linked AllocationSection of the disk at the beginning of the partition contains tableUnused blocks => 0
40 Combined Scheme: UNIX UFS (4K bytes per block, 32-bit addresses) Note: More index blocks than can be addressed with 32-bit file pointer
41 Implementing Directories OS uses path name supplied by the user to locate the directory entryStores attributesDirectory entry specifies block addresses by providingAddress of first block (contiguous)Number of first block (linked)Number of i-node
42 Implementing MS DOS Directories Each entry 32 bytes long
45 The UNIX File SystemThe steps in looking up /usr/ast/mbox.
46 Directory 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
47 Hash 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
49 Free-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] =Simple 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=
50 Free-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
51 Linked 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
52 Free-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-pointersCountingBecause space is frequently contiguously used and freed, with contiguous-allocation allocation, extents, or clusteringKeep address of first free block and count of following free blocksFree space list then has entries containing addresses and counts
53 Keeping Track of Free Blocks (1) Storing the free list on a linked list. (b) A bitmap.
54 1KB block 16 bits block number Each block holds 511 free blocks 20M disk needs 40 blocks for free list How many for bit map?