1 / 81

Chapter 11: File System Implementation

Chapter 11: File System Implementation. Chapter 11: File System Implementation. File-System Structure File-System Implementation Directory Implementation Allocation Methods Free-Space Management Efficiency and Performance Recovery NFS Example: WAFL File System. Objectives.

karis
Télécharger la présentation

Chapter 11: File System Implementation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 11: File System Implementation

  2. Chapter 11: File System Implementation File-System Structure File-System Implementation Directory Implementation Allocation Methods Free-Space Management Efficiency and Performance Recovery NFS Example: WAFL File System

  3. Objectives To describe the details of implementing local file systems and directory structures To describe the implementation of remote file systems To discuss block allocation and free-block algorithms and trade-offs

  4. File-System Structure File structure Logical storage unit Collection of related information File system organized into layers File systemresides on secondary storage (disks) Provides efficient and convenient access to disk by allowing data to be stored, located retrieved easily File control block– storage structure consisting of information about a file Device drivercontrols the physical device

  5. Layered File System

  6. File-System Implementation Boot control blockcontains info needed by system to boot OS from that volume Volume control blockcontains volume details Directory structure organizes the files Per-file File Control Block(FCB) contains many details about the file

  7. A Typical File Control Block

  8. In-Memory File System Structures The following figure illustrates the necessary file system structures provided by the operating systems. Figure 12-3(a) refers to opening a file. Figure 12-3(b) refers to reading a file.

  9. In-Memory File System Structures

  10. 12.2 File-System Implementation • On disk, each file system • Boot control block, or called boot block in UFS, or called partition boot sector in NTFS • First block of a partition • Partition control block • Superblock in UFS • Master file block in NTFS • Directory structure • To organize the files • File control block • Could be stored in directory structure, or • Independently • Inode in UFS • Stored within the MFB in NTFS, which uses a relational database structure

  11. File control block

  12. In memory, to improve performance • Partition control block for each mounted partition • Directory structure for recently accessed directories • File descriptor tables • Open file table • Inode table

  13. open() file descriptor read() file descriptor table

  14. Open Files • Several pieces of data are needed to manage open files: • File Descriptor Table (FDT) • Array of pointers • 1 pointer for each file opened by that process • The pointers point to Open File Table entries • File descriptor • Index into the FDT • Used when read(), write(), close(), … • Note: first 3 entries of an FDT are special • stdin • stdout • stderr • 1 per process

  15. Open Files • Several pieces of data are needed to manage open files: • Open File Table (OFT) • Array of entries • 1 entry per open file • If 2 processes open same file, 2 entries will be created • Each entry includes • Pointer to an Inode Table entry • Byte offset • How the file is being used (e.g., reading, writing, both) • # of pointers from FDT's • 1 per system

  16. Open Files • Several pieces of data are needed to manage open files: • Inode Table (IT) • Exactly 1 entry for each open file • Each entry includes • File's inode • # of pointers to the entry from the Open File Table • inode = data structure (1 per file) containing • Uid, gid of file owner • Permission bits • 3 times • Last access • Last file mod • Last mod to i-node itself • Locations of file blocks on disk • 1 per system

  17. Open Files • Note: in response to an "open" call, the OS • Creates an Inode Table entry (including reading the file's inode from disk) • Creates a Open File Table entry • Creates a FDT entry (using the next free slot in the FDT table) • Note: in response to a "close" call, the OS • Clears the FDT entry • Clears the Open File Table entry (unless other FDT entries point to it.) • Clears Inode Table entry (unless other Open File Table entries point to it.)

  18. Open Files • Example • Process 1: fd1a = open("/temp1", O_RDONLY); • Process 2: fd2a = open("/temp1", O_RDWR); • Process 1: fd1b = open("/temp2", O_RDWR); • Process 2: fd2b = open("/temp2", O_WRONLY); • Process 1: fd1c = open("/temp3", O_RDONLY); • Process 2: fd2c = open("/temp4", O_WRONLY);

  19. Open Files • Process 1: fd1a = open("/temp1", O_RDONLY); -- 1 1 1 File Descriptor Table 1 0 RDONLY 1 Open File Table 1 inode for /temp1 Inode Table

  20. Open Files • Process 2: fd2a = open("/temp1", O_RDWR); -- 1 2 1 File Descriptor Table 1 -> 2 1 0 RDWR 2 Open File Table 1 -> 2 Inode Table

  21. Open Files • Process 1: fd1b = open("/temp2", O_RDWR); -- 2 File Descriptor Table Open File Table Inode Table

  22. Open Files • Process 2: fd2b = open("/temp2", O_WRONLY); -- 2 File Descriptor Table Open File Table Inode Table

  23. Open Files • Process 1: fd1c = open("/temp3", O_RDONLY); -- 3 File Descriptor Table Open File Table Inode Table

  24. Open Files • Process 2: fd2c = open("/temp4", O_WRONLY); -- 3 File Descriptor Table Open File Table Inode Table

  25. Open Files • Process 2: write(fd2c, buf, 10); -- 3 File Descriptor Table Open File Table 10 Inode Table

  26. Open Files • Process 1: close(fd1b); -- 2 File Descriptor Table Open File Table 1 1 Inode Table

  27. Open Files • Process 2: close(fd2b); -- 2 File Descriptor Table Open File Table Inode Table

  28. Open Files File Descriptor Table Open File Table Inode Table

  29. Virtual File Systems Virtual File Systems (VFS) provide an object-oriented way of implementing file systems. VFS allows the same system call interface (the API) to be used for different types of file systems. The API is to the VFS interface, rather than any specific type of file system.

  30. File System Implementation Virtual File Systems • Superblock – in memory • Device – device identifier • Inode pointers • Mounted inode pointer • Covered inode pointer • Block size • Superblock operations • A pointer to a set of superblock routines for this file system • File system type • File system specific

  31. File System Implementation Virtual File Systems • Inodes for open files and directories – in memory • Device – device identifier • Inode number • The inode number within this file system • Mode • What it represents • User ids • The owner identifiers • Times • Block size • Inode operations • Count • Lock • Dirty • File system specific information

  32. File System Implementation Virtual File Systems • Finding a file • From the current working directory – e.g., $ ls bin • => Inode on the real device for ‘.’ • File names or directory names with corresponding inodes • => … • From the root directory – e.g., $ ls /usr/src • => Superblock • => Device and inode • => Inode on the real device for ‘/’ • File names or directory names with corresponding inodes • => …

  33. File System Implementation Virtual File Systems • Searching a file, e.g., /home2/guest/tst mlee – inode # guest – inode # usr – inode # home2 – inode # tmp – inode # “/” B S Inode list Data blocks

  34. File System Implementation 12.3 Directory Implementation • Directory contains a list of file names and corresponding additional information how to locate the file • Linear list of file names with pointer to the data blocks. • Advantage • Simple to program • Disadvantage • Time-consuming to execute • Hash Table – linear list with hash data structure. • Advantage • Decreases directory search time • Disadvantage • Collisions – situations where two file names hash to the same location => need to use redundant space • Fixed size => hard to grow • Sorted list, …

  35. File System Implementation • Directory structure in MFT (Master File Table) in NTFS

  36. Schematic View of Virtual File System

  37. Directory Implementation Linear list of file names with pointer to the data blocks. simple to program time-consuming to execute Hash Table – linear list with hash data structure. decreases directory search time collisions– situations where two file names hash to the same location fixed size

  38. Allocation Methods An allocation method refers to how disk blocks are allocated for files: Contiguous allocation Linked allocation Indexed allocation

  39. Contiguous Allocation Each file occupies a set of contiguous blocks on the disk Simple – only starting location (block #) and length (number of blocks) are required Random access Wasteful of space (dynamic storage-allocation problem) Files cannot grow

  40. Contiguous Allocation Mapping from logical to physical Q LA/512 R • Block to be accessed = ! + starting address • Displacement into block = R

  41. Contiguous Allocation of Disk Space

  42. Extent-Based Systems Many newer file systems (i.e., Veritas File System) use a modified contiguous allocation scheme Extent-based file systems allocate disk blocks in extents An extent is a contiguous block of disks Extents are allocated for file allocation A file consists of one or more extents Block size: 512 File pointer: 14000 Reading 200 bytes Block to be accessed: Which block[s] would be retrieved from the file system? Displacement in the first block to be accessed: What displacement is the file pointer in the first block to be accessed?

  43. Linked Allocation Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. pointer block =

  44. Linked Allocation (Cont.) Simple – need only starting address Free-space management system – no waste of space No random access Mapping Q LA/511 R Block to be accessed is the Qth block in the linked chain of blocks representing the file. Displacement into block = R + 1 • File-allocation table (FAT) – disk-space allocation used by MS-DOS and OS/2.

  45. Linked Allocation

  46. File-Allocation Table Block size: 512 Size of the link in FAT: 4 File: test File pointer: 1020 Reading 100 bytes Block to be accessed: Which block[s] would be retrieved from the file system? Displacement in the first block to be accessed: What displacement is the file pointer in the first block to be accessed? The size of FAT?

  47. File-Allocation Table mlee – FAT entry # guest – FAT entry # usr – FAT entry # home2 – FAT entry # tmp – FAT entry # FAT entry # for “/” B S FAT Data blocks Block #[s]

  48. Linked Allocation • Advantages • Simple – need only starting address • Free-space management system – no waste of space • Disadvantages • No random access • The space required for the pointers • A solution • Use of clusters of multiple blocks

  49. Indexed Allocation Brings all pointers together into the index block Logical view index table

  50. Example of Indexed Allocation

More Related