1 / 52

O/S 4740

O/S 4740. Chapter 10 File-System Implementation. File system. It gives us access to persistent data Info will survive termination of your process provides a mechanism for inter-process communication ie pipes. File System Implementation.

lori
Download Presentation

O/S 4740

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. O/S 4740 Chapter 10 File-System Implementation

  2. File system • It gives us access to persistent data • Info will survive termination of your process • provides a mechanism for inter-process communication ie pipes

  3. File System Implementation • You must have a method of long term storage ie disk, tape, etc • A disk is divided into equal size blocks. • Blocks are logical – sectors are physical • Block size is (usually) a power of 2. • Input/output is done only in terms of blocks, no addressing of bits on the disk.

  4. File-System Structure • File structure • Logical storage unit • Collection of related information • File system resides on secondary storage (disks). • File system organized into layers.

  5. Boot Control Block • Usually first block, contains information needed by the system to boot. • UFS: Boot block, NTFS: partition boot sector • Partition Control Block • information about the partition • # of blocks, size of blocks, free block count, free block pointers, etc. • UFS: superblock, NTFS: Master File Table

  6. A directory structure block • contains information about directory and pointers to FCB and other directories. • UFS: inode • File control block – storage structure consisting of information about a file. • UFS: inode

  7. A Typical File Control Block Directory structure block looks very similar

  8. In-memory information • partition table information about each mounted partition • System-wide open-file table • copies of FCB of each open file and other info • Per-process open-file table • pointers to enters in System-wide table and other info. • In-memory directory structures which point to mounted partitions. • example: /usr actually points to a partition mounted into the file system at /usr

  9. In-Memory File System Structures

  10. Mount tables • When a partition is mounted into file system (windows and UNIX), a line is added into a mount table. • UNIX example • When a partition is mounted, it is mounted onto a directory. • A flag is set for the in-memory copy of inode and a field points to the mount table entry instead of the block. • The mount table contains a pointer to the superblock on the partition.

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

  12. Schematic View of Virtual File System

  13. Directory Implementation • Linear list of file names with pointer to the data blocks. • simple to program • time-consuming to execute • When block is full, last entry points to the next block where the file list continues. • 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

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

  15. Allocation and De allocation of blocks • How to store a file on disk: • Contiguous Allocation(simplest) • All blocks must be contiguous for each file. • Need only know size and starting address. • problem • if file size changes over time (usually does) • External fragmentation

  16. Contiguous Allocation of Disk Space

  17. During down time, compaction schemes can be used to free up fragmentation • Can be modified with Extent • Extent is chunk of free space. • As file needs more space, another Extent is allocated to the file. • Internal fragmentation now becomes a problem.

  18. Linked Allocation • Directory contains a link to the first block and the last block • Each block in the file contains a pointer to the next block. • Problems: • slow for random access reads • Pointer requires space in each block

  19. pointer block = Linked Allocation

  20. File-Allocation Table

  21. Wasted pointer space can be fixed by using cluster (windows FAT filesystem) • similar to Extents, group a number of blocks together, then only 1 pointer for each cluster • Problems: • Still have the problem the file scattered all over the partition. Slow reads. • Can be fixed with defragmentation programs.

  22. Indexed Allocation • similar to linked, except all pointers are located in an index block. • Directory points to the index block • To allow for large files, directory can point to several index blocks.

  23. Example of Indexed Allocation

  24. Multilevel Index • To represent very large files • A first level index block will point only to second level index blocks. (can be 3 level index blocks, etc). • Very wasteful and slow for small files.

  25. Combined Scheme • UNIX inode: All file information • (index node, then I-node, now just inode) • Size of the file • name • access privileges • modification info • creation time • file type //only partially used in UNIX for file, directory, symbolic link, character device, block device, or socket. Not executable or binary.

  26. There are then 13 block pointers that contain direct addressing as above • 14th block pointer is 1 level index-block. • 15th block pointer is 2 level index-block • 16th (last) block pointer is a 3 level index-block. With a 4K block size, only files bigger than 232 (4GB) would use this block

  27. Combined Scheme: UNIX (4K bytes per block)

  28. Free-Space Management • Bit vector (n blocks) 0 1 2 n-1 … 0  block[i] free 1  block[i] occupied bit[i] = 

  29. Free-Space Management (Cont.) • Bit map requires extra space. Example: block size = 212 bytes disk size = 230 bytes (1 gigabyte) n = 230/212 = 218 bits (or 32K bytes) • Easy to get contiguous files • Linked list (free list) • Cannot get contiguous space easily • No waste of space

  30. Free-Space Management (Cont.) • Need to protect: • Pointer to free list • Bit map • Must be kept on disk • Copy in memory and disk may differ. • Cannot allow for block[i] to have a situation where bit[i] = 1 in memory and bit[i] = 0 on disk. • Solution: • Set bit[i] = 1 in disk. • Allocate block[i] • Set bit[i] = 1 in memory

  31. Linked Free Space List on Disk

  32. Efficiency and Performance • Efficiency dependent on: • disk allocation and directory algorithms • types of data kept in file’s directory entry • Performance • disk cache – separate section of main memory for frequently used blocks • free-behind and read-ahead – techniques to optimize sequential access • improve PC performance by dedicating section of memory as virtual disk, or RAM disk.

  33. Reliability of a filesystem • New disks always have some bad blocks • Disk crashes happen • Processor crashes before updating or while updating (writing an inode) • Atomicity of disk I/O: Either write the entire block or None.

  34. Bad Blocks • Software solution – mark bad blocks as used (allocated) • Hardware solution – dedicate a sector on the disk to substitute for bad blocks (most disks have extra blocks that can be used)

  35. Disk Crash • Keep back ups. • Floppy disk – make 2 copies of the data “at the time” • large disk – back up the files that have changed • Or keeps mirrors of each disk.

  36. Processor Crashes • to keep the file system from becoming corrupted use atomic write (at block level) • keep redundant block. Use a pointer that tells you which block is current and old block. Change the pointer only after the block has been completely written. • wastes a lot of space on a 100meg hard, have to use 50 megs. (ie ½ half the hard drive)

  37. Alternative: just use one extra block: • copy the old block into a new block • then after the write, change the new block to the current block • requires more book keeping. Made more difficult depending on allocation method.

  38. File system consistency • If Log (journaling) File Systems, then recovery is simple. • previously talked about • all directories point to the correct file – can not check at the system level. • requires a two way pointer • dir inode <== ==> file inod

  39. Consistency we can check: • only one file points at any particular block. • fsck (UNIX, linux) //file system check • check block consistency • build a table w/ 2 counters (initially set at 0) • first counter: how many times a block is present in files • second counter: how many times a block is present in the free list • w/bit since it simpler, but other methods are used

  40. read all inodes • from each inode, build a list of blocks used in that file. • for each block increment the first counter • examine free list • for each occurrence of the block in the list, increment the blocks in 2nd counter • Now it is consistent when a row adds up to 1 or 0,1 or 1,0 exists in each row.

  41. Inconsistency • 0 appears in both counters. • Not allocated and not free, so it is a missing block • Recovery: Put it in the free list and set free list bit to 1 • Inconsistency: 1st counter =1 and 2nd counter >1 • Remove it from the free list until it is set at 1 and rebuild the free list 3. Inconsistency: 1 and 1 • could remove from either, but best to allow it to remain w/ the file, so remove it from the free list 4. inconsistency: 1st pointer > 1 • copy the block into an empty block and adjust file until each has only one copy in their inodes.

  42. The Sun Network File System (NFS) • An implementation and a specification of a software system for accessing remote files across LANs (or WANs). • The implementation is part of the Solaris and SunOS operating systems running on Sun workstations using an unreliable datagram protocol (UDP/IP protocol and Ethernet. • Current version is 3. V2 in wide use

  43. NFS (Cont.) • Interconnected workstations viewed as a set of independent machines with independent file systems, which allows sharing among these file systems in a transparent manner. • A remote directory is mounted over a local file system directory. The mounted directory looks like an integral subtree of the local file system, replacing the subtree descending from the local directory. • Specification of the remote directory for the mount operation is nontransparent; the host name of the remote directory has to be provided. Files in the remote directory can then be accessed in a transparent manner. • Subject to access-rights accreditation, potentially any file system (or directory within a file system), can be mounted remotely on top of any local directory.

  44. NFS (Cont.) • NFS is designed to operate in a heterogeneous environment of different machines, operating systems, and network architectures; the NFS specifications independent of these media. • This independence is achieved through the use of RPC primitives built on top of an External Data Representation (XDR) protocol used between two implementation-independent interfaces. • The NFS specification distinguishes between the services provided by a mount mechanism and the actual remote-file-access services.

  45. Three Independent File Systems

  46. NFS Mount Protocol • Establishes initial logical connection between server and client. • Mount operation includes name of remote directory to be mounted and name of server machine storing it. • Mount request is mapped to corresponding RPC and forwarded to mount server running on server machine. • Export list – specifies local file systems that server exports for mounting, along with names of machines that are permitted to mount them. • Following a mount request that conforms to its export list, the server returns a file handle—a key for further accesses. • File handle – a file-system identifier, and an inode number to identify the mounted directory within the exported file system. • The mount operation changes only the user’s view and does not affect the server side.

  47. NFS Protocol • Provides a set of remote procedure calls for remote file operations. The procedures support the following operations: • searching for a file within a directory • reading a set of directory entries • manipulating links and directories • accessing file attributes • reading and writing files • NFS servers are stateless; each request has to provide a full set of arguments. • Modified data must be committed to the server’s disk before results are returned to the client (lose advantages of caching). • The NFS protocol does not provide concurrency-control mechanisms.

  48. Three Major Layers of NFS Architecture • UNIX file-system interface (based on the open, read, write, and close calls, and file descriptors). • Virtual File System (VFS) layer – distinguishes local files from remote ones, and local files are further distinguished according to their file-system types. • The VFS activates file-system-specific operations to handle local requests according to their file-system types. • Calls the NFS protocol procedures for remote requests. • NFS service layer – bottom layer of the architecture; implements the NFS protocol.

  49. Schematic View of NFS Architecture

  50. NFS Path-Name Translation • Performed by breaking the path into component names and performing a separate NFS lookup call for every pair of component name and directory vnode. • To make lookup faster, a directory name lookup cache on the client’s side holds the vnodes for remote directory names.

More Related