1&6(&6(3ULQFLSOHVRI2SHUDWLQJ3ULQFLSOHVRI2SHUDWLQJ6\VWHPV6\VWHPV)DOO)DOOLecture 12: File SystemsLecture 12: File SystemsGeoffrey M. VoelkerGeoffrey M. VoelkerNovember 12, 2001 CSE 120 – Lecture 12 – File Systems 2)LOH6\VWHPV)LOH6\VWHPV● Last time we talked about the physical characteristics of disks and their performance● Today we’ll talk about file systems◆ Files◆ Directories◆ Sharing◆ Protection◆ File System Layouts◆ File Buffer Cache◆ Read Ahead2November 12, 2001 CSE 120 – Lecture 12 – File Systems 3)LOH6\VWHPV)LOH6\VWHPV● 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)November 12, 2001 CSE 120 – Lecture 12 – File Systems 4)LOHV)LOHV● 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)3November 12, 2001 CSE 120 – Lecture 12 – File Systems 5%DVLF)LOH2SHUDWLRQV%DVLF)LOH2SHUDWLRQVUnix● creat(name)● open(name, how)● read(fd, buf, len)● write(fd, buf, len)● sync(fd)● seek(fd, pos)● close(fd)● unlink(name)NT● CreateFile(name, CREATE)● CreateFile(name, OPEN)● ReadFile(handle, …)● WriteFile(handle, …)● FlushFileBuffers(handle, …)● SetFilePointer(handle, …)● CloseHandle(handle, …)● DeleteFile(name)● CopyFile(name)● MoveFile(name)November 12, 2001 CSE 120 – Lecture 12 – File Systems 6)LOH$FFHVV0HWKRGV)LOH$FFHVV0HWKRGV● Some file systems provide different access methodsthat 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 methods4November 12, 2001 CSE 120 – Lecture 12 – File Systems 7'LUHFWRULHV'LUHFWRULHV● Directories serve two purposes◆ 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● Most file systems support multi-level directories◆ 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 treeNovember 12, 2001 CSE 120 – Lecture 12 – File Systems 8'LUHFWRU\,QWHUQDOV'LUHFWRU\,QWHUQDOV● A directory is a list of entries – names and associated metadata◆ Metadata is not the data itself, but information that describes properties of the data (size, protection, location, etc.)● List is usually unordered (effectively random)◆ Entries usually sorted by program that reads directory● Directories typically stored in files◆ Only need to manage one kind of secondary storage unit5November 12, 2001 CSE 120 – Lecture 12 – File Systems 9%DVLF'LUHFWRU\2SHUDWLRQV%DVLF'LUHFWRU\2SHUDWLRQVUnix● Directories implemented in files◆ Use file ops to create dirs● C runtime library provides a higher-level abstraction for reading directories◆ opendir(name)◆ readdir(DIR)◆ seekdir(DIR)◆ closedir(DIR)NT● Explicit dir operations◆ CreateDirectory(name)◆ RemoveDirectory(name)● Very different method for reading directory entries◆ FindFirstFile(pattern)◆ FindNextFile()November 12, 2001 CSE 120 – Lecture 12 – File Systems 103DWK1DPH7UDQVODWLRQ3DWK1DPH7UDQVODWLRQ● Let’s say you want to open “/one/two/three”● What does the file system do?◆ Open directory “/” (well known, can always find)◆ Search for the entry “one”, get location of “one” (in dir entry)◆ Open directory “one”, search for “two”, get location of “two”◆ Open directory “two”, search for “three”, get location of “three”◆ Open file “three”● Systems spend a lot of time walking directory paths◆ This is why open is separate from read/write◆ OS will cache prefix lookups for performance» /a/b, /a/bb, /a/bbb, etc., all share “/a” prefix6November 12, 2001 CSE 120 – Lecture 12 – File Systems 11)LOH6KDULQJ)LOH6KDULQJ● File sharing has been around since timesharing◆ Easy to do on a single machine◆ PCs, workstations, and networks get us there (mostly)● File sharing is incredibly important for getting work done◆ Basis for communication and synchronization● Two key issues when sharing files◆ Semantics of concurrent access» What happens when one process reads while another writes?» What happens when two processes open a file for writing?◆ ProtectionNovember 12, 2001 CSE 120 – Lecture 12 – File Systems 123URWHFWLRQ3URWHFWLRQ● File systems implement some kind of protection system◆ Who can access a file◆ How they can access it● More generally…◆ Objects are “what”, subjects are “who”, actions are “how”● A protection system dictates whether a given actionperformed by a given subject on a given object should be allowed◆ You can read and/or write your files, but others cannot◆ You can read “/etc/motd”, but you cannot write it7November 12, 2001 CSE 120 – Lecture 12 – File Systems 135HSUHVHQWLQJ3URWHFWLRQ5HSUHVHQWLQJ3URWHFWLRQAccess Control Lists (ACL)● For each object, maintain a list of subjects and their permitted actionsCapabilities● For each subject, maintain a list of objects and their permitted
View Full Document