Lecture 13 File Systems CSE 120 Principles of Operating Systems Alex C Snoeren HW 3 Due 11 9 Lab 2 Due 11 14 File Systems First we ll discuss properties of physical disks Structure Performance Scheduling Then we ll discuss how we build file systems on them Files Directories Sharing Protection File System Layouts File Buffer Cache Read Ahead CSE 120 Lecture 13 File Systems 2 Disks and the OS Disks are messy physical devices The job of the OS is to hide this mess from higher level software Errors bad blocks missed seeks etc Low level device control initiate a disk read etc Higher level abstractions files databases etc The OS may provide different levels of disk access to different clients Physical disk surface cylinder sector Logical disk disk block Logical file file block record or byte CSE 120 Lecture 13 File Systems 3 Physical Disk Structure Disk components Platters Surfaces Tracks Sectors Cylinders Arm Heads Track Sector Arm Surface Cylinder Heads Platter Logically disk broken down into sectors Addressed by cylinder head sector CHS CSE 120 Lecture 13 File Systems 4 Disk Interaction Specifying disk requests requires a lot of info Older disks required the OS to specify all of this The OS needed to know all disk parameters Modern disks are more complicated Cylinder surface track sector transfer size Not all sectors are the same size sectors are remapped etc Current disks provide a higher level interface SCSI The disk exports its data as a logical array of blocks 0 N Disk maps logical blocks to cylinder surface track sector Only need to specify the logical block to read write But now the disk parameters are hidden from the OS CSE 120 Lecture 13 File Systems 5 Disk Parameters 2006 Seagate Barracuda ES largest SATA drive available Form factor 3 5 Capacity 750 GB Rotation rate 7 200 RPM Platters 4 Surfaces 8 Sector size 512 bytes Cache 16MB Transfer rate 40 MB s inner 78 MB s outer Average seek 9 5 ms CSE 120 Lecture 13 File Systems 6 Disk Performance Disk request performance depends upon a number of steps Seek moving the disk arm to the correct cylinder Depends on how fast disk arm can move increasing very slowly Rotation waiting for the sector to rotate under the head Depends on rotation rate of disk increasing but slowly Transfer transferring data from surface into disk controller electronics sending it back to the host Depends on density increasing quickly When the OS uses the disk it tries to minimize the cost of all of these steps Particularly seeks and rotation CSE 120 Lecture 13 File Systems 7 Disk Scheduling Because seeks are so expensive milliseconds the OS tries to schedule disk requests that are queued waiting for the disk FCFS do nothing Reasonable when load is low Long waiting times for long request queues SSTF shortest seek time first Minimize arm movement seek time maximize request rate Favors middle blocks SCAN elevator Service requests in one direction until done then reverse C SCAN Like SCAN but only go in one direction typewriter CSE 120 Lecture 13 File Systems 8 Disk Scheduling 2 In general unless there are request queues disk scheduling does not have much impact Important for servers less so for PCs Modern disks often do the disk scheduling themselves Disks know their layout better than OS can optimize better Ignores undoes any scheduling done by OS CSE 120 Lecture 13 File Systems 9 File Systems File systems Implement an abstraction files for secondary storage Organize files logically directories Permit sharing of data between processes people and machines Protect data from unwanted access security CSE 120 Lecture 13 File Systems 10 Files A file is data with some properties Contents size owner last read write time protection etc A file can also have a type Understood by the file system Block character device portal link etc Understood by other parts of the OS or runtime libraries Executable dll souce object text etc A file s type can be encoded in its name or contents Windows encodes type in name com exe bat dll jpg etc Unix encodes type in contents Magic numbers initial characters e g for shell scripts CSE 120 Lecture 13 File Systems 11 Basic File Operations Unix creat name open name how read fd buf len write fd buf len sync fd seek fd pos close fd unlink name NT CSE 120 Lecture 13 File Systems CreateFile name CREATE CreateFile name OPEN ReadFile handle WriteFile handle FlushFileBuffers handle SetFilePointer handle CloseHandle handle DeleteFile name CopyFile name MoveFile name 12 File Access Methods Some file systems provide different access methods that specify different ways for accessing data in a file Sequential access read bytes one at a time in order Direct access random access given block byte number Record access file is array of fixed or variable length records read written sequentially or randomly by record Indexed access file system contains an index to a particular field of each record in a file reads specify a value for that field and the system finds the record via the index DBs What file access method does Unix NT provide Older systems provide more complicated methods CSE 120 Lecture 13 File Systems 13 Directories Directories serve two purposes Most file systems support multi level directories For users they provide a structured way to organize files For the file system they provide a convenient naming interface that allows the implementation to separate logical file organization from physical file placement on the disk Naming hierarchies usr usr local Most file systems support the notion of a current directory Relative names specified with respect to current directory Absolute names start from the root of directory tree CSE 120 Lecture 13 File Systems 14 Directory Internals A directory is a list of entries List is usually unordered effectively random name location Name is just the name of the file or directory Location depends upon how file is represented on disk Entries usually sorted by program that reads directory Directories typically stored in files Only need to manage one kind of secondary storage unit CSE 120 Lecture 13 File Systems 15 Basic Directory Operations Unix Directories implemented in files Use file ops to create dirs C runtime library provides a higher level abstraction for reading directories NT opendir name readdir DIR seekdir DIR closedir DIR CSE 120 Lecture 13 File Systems Explicit dir operations CreateDirectory name RemoveDirectory name Very different method for reading directory entries FindFirstFile pattern FindNextFile
View Full Document
Unlocking...