Lecture 27 Any issues with finding case study references? Reminder: Homework 6, case study outline with references due on Wednesday Questions? Monday, March 19 CS 470 Operating Systems - Lecture 27 1 Outline Directory ADT Finish up directory structures File system implementation Disk and memory structures Operation implementations Allocation methods Monday, March 19 CS 470 Operating Systems - Lecture 27 2 Directory Structures Recall as discussed last class, first issue regarding files is name clashes. Do not want to require every file in system to have a unique name. The generalized directory structure is the familiar tree structure. Users can create subdirectories in their UFD. Names become path names that can be absolute or relative. Introduce new directory operations: current directory, change directory. New issue: what happens when try to delete a directory? Monday, March 19 CS 470 Operating Systems - Lecture 27 3 Directory Structures Sometimes users may want to share subdirectories (i.e., have them mapped into their UFDs). Acyclic-graph structure provides this functionality. UNIX allows this through the use of links. Links may be hard, creating a full directory entry to the shared data, or soft, creating a directory entry that is simply a path name to the shared data. Monday, March 19 CS 470 Operating Systems - Lecture 27 4 Directory Structures Main issues are in directory traversal - an entry may appear more than once, and in deletion who has the right to delete the shared data. In UNIX, hard links are counted and a file is removed from the physical disk only when there are no hard links to it. Deleting a file simply removes its directory entry and decrements the link count. Soft links can become "dangling pointers", if the named directory entry is removed. Monday, March 19 CS 470 Operating Systems - Lecture 27 5 File System Implementation How is the physical storage of files organized? Most file systems (FS) are on disks. Disks have a natural efficient transfer size called a block. Block sizes range from 32 bytes to 4KB. A common size is 512 bytes. Disks are good for file storage Can rewrite data in place Can randomly access blocks Monday, March 19 CS 470 Operating Systems - Lecture 27 6 File System Implementation Under the OS API, there are several layers to get to the actual disk: Monday, March 19 User access Symbolic name Logical filesystem Symbolic name -> File control block (FCB): logical address, directory, other metadata, protection (Chapter 14) File organization module Logical blocks -> Physical blocks, free space manager (Chapter 11) Basic FS Calls to drivers, physical address may be a VFS or <drive,cylinder,track,sector> I/O Driver Driver hides differences in actual hardware (Chapter 13) Device (e.g. disk) Actually the controller to the device (Chapter 12) CS 470 Operating Systems - Lecture 27 7 File System Implementation There are many file system types ISO 9660 for CD-ROMs U(nix)FS FAT - FAT8, FAT12, FAT16, FAT32... NTFS ext(ended FS) 2/3/4 ... Monday, March 19 CS 470 Operating Systems - Lecture 27 8 File System Disk Structures File systems have both on-disk and in-memory data structures. Depend on particular OS and FS. Most commonly on disk: Boot information, total number of blocks, number and location of free blocks, directory structure, and of course, the actual files. Boot control block per volume - information to boot OS from this volume. Typically the first block of the volume. Also called boot block (UFS) and partition boot sector (NTFS) Monday, March 19 CS 470 Operating Systems - Lecture 27 9 File System Disk Structures On-disk structures, cont'd Volume control block - contains partition/volume details including number of blocks in partition, size of blocks, free-block count and pointers, free FCB count, etc. Also called superblock (UFS), master file table (NTFS). Directory structure per FS. UFS include names and associated inode numbers. This is stored inside the master file table in NTFS. Per file FCB with file attributes. Called an inode in UFS. NTFS stores in the master file table. Monday, March 19 CS 470 Operating Systems - Lecture 27 10 File System Memory Structures In-memory data structures are often used for caching to improve efficiency. Data is loaded at mount time and discarded at unmount. Mount table - information about each mounted volume Directory-structure cache System OFT - copy of FCB of each open file Process local OFT Monday, March 19 CS 470 Operating Systems - Lecture 27 11 Creating a File Applications call the logical FS interface. The LFS knows the format of the directory structures. To create a file it does the following: Allocates/obtains a new FCB Reads the appropriate directory into memory Updates directory with new file name and FCB Writes directory back to disk Monday, March 19 CS 470 Operating Systems - Lecture 27 12 Opening a File If a file has been opened already, it has an entry in the system OFT. Otherwise, the LFS Reads in the appropriate directory into memory Reads in the FCB and stores it in the system OFT The rest of this operation does the following: Sets entry in the process local OFT to point to the system OFT entry and increment the open count Return index of the entry in the process local OFT. Called a file descriptor (UFS), file handle (Win) Monday, March 19 CS 470 Operating Systems - Lecture 27 13 Reading from a File To read from a file, the LFS Follows the file entry in the process local OFT Follows the entry in the system OFT Reads the data blocks Monday, March 19 CS 470 Operating Systems - Lecture 27 14 Closing a File The close operations does the following Removes the file entry in the process local OFT Decrements the open count in the system OFT If the open count becomes 0, writes the metadata back to disk and removes the file entry from the system OFT. Monday, March 19 CS 470 Operating Systems - Lecture 27 15 Virtual File System The VFS is an interface layer between the LFS and an actual concrete FS. It is used to allow applications to operate on any type of file without knowing exactly what kind of file it is. Typically, it is implemented as a table of function pointers. For each FS type there is a table indexed by LFS operation that points to the function that does the actual FS operation. Monday, March 19 CS 470 Operating Systems - Lecture 27 16 Virtual File System Monday, March 19 CS 470 Operating Systems - Lecture 27 17 Allocation Methods As with any resource, there are various ways to allocate disk space into files. Want a method that has effective disk utilization efficient access for a variety of operations; random vs. sequential; read vs. write vs. append Common methods are contiguous, linked, and indexed Monday, March 19 CS 470 Operating Systems - Lecture 27 18 Contiguous Allocation Each file occupies contiguous blocks on the disk. The directory entry is <fileID, startBlockAddr, length> What are the advantages of this organization? What are the disadvantages of this organization? Monday, March 19 CS 470 Operating Systems - Lecture 27 19 Linked Allocation File is a linked list of disk blocks. Directory entry is <fileID, startBlockAddr, endBlockAddr>. Must read the start block to find the next block number. What are the advantages of this organization? What are the disadvantages of this organization? Monday, March 19 CS 470 Operating Systems - Lecture 27 20 Linked Allocation To mitigate some of the disadvantages, can use a file allocation table (FAT - used in DOS). Directory entry is <fileID, startBlock#> FAT is indexed by block number and links the table entries rather than the blocks themselves. Often the FAT is small enough to cache, so can find out what block a random access it in without reading disk. Monday, March 19 CS 470 Operating Systems - Lecture 27 21 Indexed Allocation Each file has an index block that is an array of disk addresses to the blocks that make up the file. What are the advantages of this organization? What are the disadvantages of this organization? Monday, March 19 CS 470 Operating Systems - Lecture 27 22 Indexed Allocation Several ways to handle large files Link index blocks Multiple levels of indexing UNIX UFS - most of the index block is direct address, but second to last entry is two-level (i.e. it points to another index block) and the last entry is three-level. Good compromise: small files do not pay for multi-level, but large files are supported. Monday, March 19 CS 470 Operating Systems - Lecture 27 23 Indexed Allocation - UNIX UFS Monday, March 19 CS 470 Operating Systems - Lecture 27 24