Representing Files On Disk: Nachos Representing Files On Disk: Nachos An OpenFile represents a file in OpenFile(sector) active use, with a seek pointer and OpenFile Seek(offset) read/write primitives for arbitrary byte ranges. Read(char* data, bytes) Write(char* data, bytes) once upo File Systems and NFS File Systems and NFS logical n a time block 0 /nin a l A file header describes an on-disk file as an ordered sequence of and far logical block 1 far away sectors with a length, mapped by FileHdr ,/nlived t a logical-to-physical block map. he wise logical and sage block 2 wizard. bytes sectors Allocate(..., filesize) OpenFile* ofd = filesys->Open(“tale”); length =FileLength () ofd ->Read(data, 10) gives ‘ once upon ‘ sector = ByteToSector(offset) ofd ->Read(data, 10) gives ‘ a time/nin ‘ File Metadata File Metadata Representing Large Files Representing Large Files inode On disk, each file is represented by a FileHdr structure. The Nachos FileHdr occupies exactly one disk sector, limiting the maximum file size. The FileHdr object is an in-memory copy of this structure. direct sector size = 128 bytes 120 bytes of block map = 30 entries block The FileHdr is a file system “bookeeping” structure each entry maps a 128-byte sector map that supplements the file data itself: these kinds of file attributes : may include owner, max file size = 3840 bytes structures are called filesystem metadata . (12 entries) access control, time of create/modify/access, etc. indirect In Unix, the FileHdr (called an index - block bytes node or inode ) represents large files using A Nachos FileHdr occupies sectors etc. exactly one disk sector. a hierarchical block map. logical -physical block map (like a translation table) Each file system block is a clump of sectors (4KB, 8KB, 16KB). To operate on the file (e.g., Inodes are 128 bytes, packed into blocks. to open it), the FileHdr must Each inodehas 68 bytes of attributes and 15 block map entries. be read into memory. double suppose block size = 8KB indirect physical block pointers in the 12 direct block map entries in the inodecan map 96KB of data. block Any changes to the attributes block map are sector IDs One indirect block (referenced by theinode) can map 16MB of data. or block map must be written One double indirect block pointer in inodemaps 2K indirect blocks. FileHdr* hdr = new FileHdr(); back to the disk to make them hdr->FetchFrom(sector) permanent. maximum file size is 96KB + 16MB + (2K*16MB) + ... hdr->WriteBack(sector) Representing Small Files Representing Small Files Basics of Directories Basics of Directories Internal fragmentation in the file system blocks can waste A directory is a set of file names, supporting lookup by symbolic name. significant space for small files. E.g., 1KB files waste 87% of disk space (and bandwidth) in a naive In Nachos, each directory is a file containing file system with an 8KB block size. a set of mappings from name-> FileHdr . Most files are small: one study [Irlam93] shows a median of 22KB. Directory(entries) wind: 18 directory sector = Find(name) FFS solution: optimize small files for space efficiency. fileHdr 0 Add(name, sector) snow: 62 • Subdivide blocks into 2/4/8 fragments (or just frags ). Remove(name) 0 • Free block maps contain one bit for each fragment. Each directory entry is a fixed-size rain: 32 slot with space for a FileNameMaxLen byte name. hail: 48 To determine if a block is free, examine bits for all its fragments. • The last block of a small file is stored on fragment(s). Entries or slots are found by a linear scan. If multiple fragments they must be contiguous. sector 32 A directory entry may hold a pointer to another directory, forming a hierarchical name space. 1
A Nachos Filesystem A Nachos FilesystemOn Disk On Disk A Typical Unix File Tree A Typical Unix File Tree An allocation bitmap file maintains A directory maintains the Each volume is a set of directories and files; a host’s file tree is the set of free/allocated state of each physical name->FileHdr mappings for block; its FileHdr is always stored in directories and files visible to processes on a given host. all existing files; its FileHdr is sector 0. always stored in sector 1. sector 0 sector 1 / allocation File trees are built by grafting bitmap file volumes from different volumes or from network servers. wind: 18 directory 11100010 file bin etc tmp usr vmunix 0 00101101 snow: 62 10111101 In Unix, the graft operation is 0 the privileged mount system call, ls sh project users rain: 32 once upo and each volume is a filesystem . 10011010 n a time hail: 48 00110001 /n in a l packages 00010101 mount point mount ( coveredDir, volume) (volume root) coveredDir: directory pathname Every box in this diagram 00101110 and far represents a disk sector. volume : devicespecifier or network volume 00011001 far away volume root contents become visible at pathname coveredDir 01000100 , lived th tex emacs Filesystems Filesystems VFS: the VFS: the Filesystem FilesystemSwitch Switch Each file volume ( filesystem ) has a type , determined by its Sun Microsystems introduced the virtual file system interface disk layout or the network protocol used to access it. in 1985 to accommodate diverse filesystemtypes cleanly. ufs (ffs), lfs, nfs, rfs, cdfs , etc. VFS allows diverse specific file systems to coexist in a file tree, isolating all FS-dependencies in pluggable filesystem modules. Filesystemsare administered independently. Modern systems also include “logical” pseudo-filesystems in user space VFS was an internal kernel restructuring the naming tree, accessible through the file syscalls. with no effect on the syscall interface. syscall layer (file, uio, etc.) procfs : the /proc filesystem allows access to process internals. network Virtual File System (VFS) Incorporates object-oriented concepts: protocol mfs : the memory file system is a memory -based scratch store. stack a generic procedural interface with (TCP/IP) NFS FFS LFS *FS etc. etc. multiple implementations. Processes access filesystems through common system calls. device drivers Based on abstract objects with dynamic Other abstract interfaces in the kernel: device drivers, method binding by type...in C. file objects, executable files, memory objects. Vnodes Vnodes Vnode Vnode Operations and Attributes Operations and Attributes In the VFS framework, every file or directory in active use is vnodeattributes ( vattr ) directories only represented by a vnode object in kernel memory. type (VREG, VDIR, VLNK, etc.) vop_lookup (OUT vpp, name) mode (9+ bits of permissions) vop_create (OUT vpp, name,vattr ) nlink (hard link count) vop_remove ( vp, name) freevnodes owner user ID vop_link ( vp, name) syscall layer owner group ID vop_rename ( vp, name, tdvp, tvp, name) filesystem ID vop_mkdir (OUT vpp, name, vattr ) unique file ID vop_rmdir (vp, name) Each vnodehas a standard file attributes struct. file size (bytes and blocks) vop_symlink (OUT vpp, name, vattr , contents) access time vop_readdir (uio , cookie) Generic vnodepoints at modify time vop_readlink (uio ) filesystem-specific struct generation number (e.g., inode, rnode ), seen files only generic operations only by thefilesystem . vop_getpages (page**, count, offset) Each specific file system vop_getattr (vattr ) vop_putpages (page**, count, sync, offset) maintains a cache of its vop_setattr (vattr ) Vnodeoperations are vop_fsync() resident vnodes. vhold () macros that vector to vholdrele() filesystem-specific NFS UFS procedures. 2
Recommend
More recommend