820 likes | 1.1k Views
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.
E N D
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 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
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
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
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.
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
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
open() file descriptor read() file descriptor table
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
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
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
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.)
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);
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
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
Open Files • Process 1: fd1b = open("/temp2", O_RDWR); -- 2 File Descriptor Table Open File Table Inode Table
Open Files • Process 2: fd2b = open("/temp2", O_WRONLY); -- 2 File Descriptor Table Open File Table Inode Table
Open Files • Process 1: fd1c = open("/temp3", O_RDONLY); -- 3 File Descriptor Table Open File Table Inode Table
Open Files • Process 2: fd2c = open("/temp4", O_WRONLY); -- 3 File Descriptor Table Open File Table Inode Table
Open Files • Process 2: write(fd2c, buf, 10); -- 3 File Descriptor Table Open File Table 10 Inode Table
Open Files • Process 1: close(fd1b); -- 2 File Descriptor Table Open File Table 1 1 Inode Table
Open Files • Process 2: close(fd2b); -- 2 File Descriptor Table Open File Table Inode Table
Open Files File Descriptor Table Open File Table Inode Table
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.
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
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
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 • => …
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
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, …
File System Implementation • Directory structure in MFT (Master File Table) in NTFS
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
Allocation Methods An allocation method refers to how disk blocks are allocated for files: Contiguous allocation Linked allocation Indexed allocation
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
Contiguous Allocation Mapping from logical to physical Q LA/512 R • Block to be accessed = ! + starting address • Displacement into block = R
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?
Linked Allocation Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. pointer block =
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.
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?
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]
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
Indexed Allocation Brings all pointers together into the index block Logical view index table