/
Unit V File-System File-System Unit V File-System File-System

Unit V File-System File-System - PowerPoint Presentation

amelia
amelia . @amelia
Follow
65 views
Uploaded On 2023-11-12

Unit V File-System File-System - PPT Presentation

Interface File Concept Access Methods Directory Structure Allocation Methods Objectives To explain the function of file systems To describe the interfaces to file systems To discuss filesystem design tradeoffs including access methods file sharing file locking and directory structures ID: 1031519

block file allocation directory file block directory allocation disk access blocks system index list cont linked data contiguous size

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Unit V File-System File-System" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. Unit VFile-System

2. File-System InterfaceFile ConceptAccess MethodsDirectory StructureAllocation Methods

3. ObjectivesTo explain the function of file systemsTo describe the interfaces to file systemsTo discuss file-system design tradeoffs, including access methods, file sharing, file locking, and directory structuresTo explore file-system protection

4. File ConceptContiguous logical address spaceTypes: DatanumericcharacterbinaryProgram

5. File StructureNone - sequence of words, bytesSimple record structureLines Fixed lengthVariable lengthComplex StructuresFormatted documentRelocatable load file Can simulate last two with first method by inserting appropriate control charactersWho decides:Operating systemProgram

6. File AttributesName – only information kept in human-readable formIdentifier – unique tag (number) identifies file within file systemType – needed for systems that support different typesLocation – pointer to file location on deviceSize – current file sizeProtection – controls who can do reading, writing, executingTime, date, and user identification – data for protection, security, and usage monitoringInformation about files are kept in the directory structure, which is maintained on the disk

7. File OperationsFile is an abstract data typeCreateWriteReadReposition within fileDeleteTruncateOpen(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memoryClose (Fi) – move the content of entry Fi in memory to directory structure on disk

8. Open FilesSeveral pieces of data are needed to manage open files:File pointer: pointer to last read/write location, per process that has the file openFile-open count: counter of number of times a file is open – to allow removal of data from open-file table when last processes closes itDisk location of the file: cache of data access informationAccess rights: per-process access mode information

9. Open File LockingProvided by some operating systems and file systemsMediates access to a fileMandatory or advisory:Mandatory – access is denied depending on locks held and requestedAdvisory – processes can find status of locks and decide what to do

10. File Locking Example – Java APIimport java.io.*;import java.nio.channels.*;public class LockingExample { public static final boolean EXCLUSIVE = false; public static final boolean SHARED = true; public static void main(String arsg[]) throws IOException { FileLock sharedLock = null; FileLock exclusiveLock = null; try { RandomAccessFile raf = new RandomAccessFile("file.txt", "rw"); // get the channel for the file FileChannel ch = raf.getChannel(); // this locks the first half of the file - exclusive exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE); /** Now modify the data . . . */ // release the lock exclusiveLock.release();

11. File Locking Example – Java API (Cont.) // this locks the second half of the file - shared sharedLock = ch.lock(raf.length()/2+1, raf.length(), SHARED); /** Now read the data . . . */ // release the lock sharedLock.release(); } catch (java.io.IOException ioe) { System.err.println(ioe); }finally { if (exclusiveLock != null) exclusiveLock.release(); if (sharedLock != null) sharedLock.release(); } }}

12. File Types – Name, Extension

13. Access MethodsSequential Access read next write next reset no read after last write (rewrite)Direct Access read n write n position to n read next write next rewrite n n = relative block number

14. Sequential-access File

15. Simulation of Sequential Access on Direct-access File

16. Example of Index and Relative Files

17. Directory StructureA collection of nodes containing information about all filesF 1F 2F 3F 4F nDirectoryFilesBoth the directory structure and the files reside on diskBackups of these two structures are kept on tapes

18. Disk StructureDisk can be subdivided into partitionsDisks or partitions can be RAID protected against failureDisk or partition can be used raw – without a file system, or formatted with a file systemPartitions also known as minidisks, slicesEntity containing file system known as a volumeEach volume containing file system also tracks that file system’s info in device directory or volume table of contentsAs well as general-purpose file systems there are many special-purpose file systems, frequently all within the same operating system or computer

19. A Typical File-system Organization

20. Operations Performed on DirectorySearch for a fileCreate a fileDelete a fileList a directoryRename a fileTraverse the file system

21. Organize the Directory (Logically) to ObtainEfficiency – locating a file quicklyNaming – convenient to usersTwo users can have same name for different filesThe same file can have several different namesGrouping – logical grouping of files by properties, (e.g., all Java programs, all games, …)

22. Single-Level DirectoryA single directory for all usersNaming problemGrouping problem

23. Two-Level DirectorySeparate directory for each userPath nameCan have the same file name for different userEfficient searchingNo grouping capability

24. Tree-Structured Directories

25. Tree-Structured Directories (Cont.)Efficient searchingGrouping CapabilityCurrent directory (working directory)cd /spell/mail/progtype list

26. Tree-Structured Directories (Cont)Absolute or relative path nameCreating a new file is done in current directoryDelete a file rm <file-name>Creating a new subdirectory is done in current directory mkdir <dir-name> Example: if in current directory /mail mkdir countmailprogcopyprtexpcountDeleting “mail”  deleting the entire subtree rooted by “mail”

27. Acyclic-Graph DirectoriesHave shared subdirectories and files

28. Acyclic-Graph Directories (Cont.)Two different names (aliasing)If dict deletes list  dangling pointer Solutions:Backpointers, so we can delete all pointersVariable size records a problemBackpointers using a daisy chain organizationEntry-hold-count solutionNew directory entry typeLink – another name (pointer) to an existing fileResolve the link – follow pointer to locate the file

29. General Graph Directory

30. General Graph Directory (Cont.)How do we guarantee no cycles?Allow only links to file not subdirectoriesGarbage collectionEvery time a new link is added use a cycle detection algorithm to determine whether it is OK

31. Allocation Methods - ContiguousAn allocation method refers to how disk blocks are allocated for files:Contiguous allocation – each file occupies set of contiguous blocksBest performance in most casesSimple – only starting location (block #) and length (number of blocks) are requiredProblems include finding space for file, knowing file size, external fragmentation, need for compaction off-line (downtime) or on-line

32. Contiguous AllocationMapping from logical to physicalLA/512QRBlock to be accessed = Q + starting addressDisplacement into block = R

33. Contiguous Allocation of Disk Space

34. 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

35. Allocation Methods - LinkedLinked allocation – each file a linked list of blocksFile ends at nil pointerNo external fragmentationEach block contains pointer to next blockNo 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 volume has table, indexed by block numberMuch like a linked list, but faster on disk and cacheable New block allocation simple

36. Linked AllocationEach file is a linked list of disk blocks: blocks may be scattered anywhere on the diskpointerblock =

37. Linked AllocationMappingBlock to be accessed is the Qth block in the linked chain of blocks representing the file.Displacement into block = R + 1LA/511QR

38. Linked Allocation

39. File-Allocation Table

40. Allocation Methods - IndexedIndexed allocationEach file has its own index block(s) of pointers to its data blocksLogical viewindex table

41. Example of Indexed Allocation

42. Indexed Allocation (Cont.)Need index tableRandom accessDynamic access without external fragmentation, but have overhead of index blockMapping from logical to physical in a file of maximum size of 256K bytes and block size of 512 bytes. We need only 1 block for index tableLA/512QRQ = displacement into index tableR = displacement into block

43. Indexed Allocation – Mapping (Cont.)Mapping from logical to physical in a file of unbounded length (block size of 512 words)Linked scheme – Link blocks of index table (no limit on size)LA / (512 x 511)Q1R1Q1 = block of index tableR1 is used as follows:R1 / 512Q2R2Q2 = displacement into block of index tableR2 displacement into block of file:

44. Indexed Allocation – Mapping (Cont.)Two-level index (4K blocks could store 1,024 four-byte pointers in outer index -> 1,048,567 data blocks and file size of up to 4GB)LA / (512 x 512)Q1R1Q1 = displacement into outer-indexR1 is used as follows:R1 / 512Q2R2Q2 = displacement into block of index tableR2 displacement into block of file:

45. Indexed Allocation – Mapping (Cont.)outer-indexindex tablefile

46. Combined Scheme: UNIX UFS (4K bytes per block, 32-bit addresses)Note: More index blocks than can be addressed with 32-bit file pointer

47. PerformanceBest method depends on file access typeContiguous great for sequential and randomLinked good for sequential, not randomDeclare access type at creation -> select either contiguous or linkedIndexed more complexSingle block access could require 2 index block reads then data block readClustering can help improve throughput, reduce CPU overhead

48. Performance (Cont.)Adding instructions to the execution path to save one disk I/O is reasonableIntel Core i7 Extreme Edition 990x (2011) at 3.46Ghz = 159,000 MIPShttp://en.wikipedia.org/wiki/Instructions_per_secondTypical disk drive at 250 I/Os per second159,000 MIPS / 250 = 630 million instructions during one disk I/O Fast SSD drives provide 60,000 IOPS159,000 MIPS / 60,000 = 2.65 millions instructions during one disk I/O

49. Free-Space ManagementFile system maintains free-space list to track available blocks/clusters(Using term “block” for simplicity)Bit vector or bit map (n blocks)…012n-1bit[i] =1  block[i] free0  block[i] occupiedBlock number calculation(number of bits per word) *(number of 0-value words) +offset of first 1 bitCPUs have instructions to return offset within word of first “1” bit

50. Free-Space Management (Cont.)Bit map requires extra spaceExample: block size = 4KB = 212 bytes disk size = 240 bytes (1 terabyte) n = 240/212 = 228 bits (or 256 MB) if clusters of 4 blocks -> 64MB of memoryEasy to get contiguous files Linked list (free list)Cannot get contiguous space easilyNo waste of spaceNo need to traverse the entire list (if # free blocks recorded)

51. Linked Free Space List on Disk

52. Windows XP Access-Control List Management

53. A Sample UNIX Directory Listing