11/8/17
Where Are We?
• Covered: COS 318: Operating Systems Management of CPU & concurrency Management of main memory & virtual memory Management of I/O devices File Structure • Currently --- File Systems This lecture: File Structure Jaswinder Pal Singh Computer Science Department • Then: Princeton University • Naming and directories (http://www.cs.princeton.edu/courses/cos318/) • Efficiency and performance • Reliability and protection
The File System Abstraction File System
• Open, close, read, write … named files, arranged in folders or directories ◆ Naming File name and directory File naming Physical Reality File System Abstraction ◆ File access File access Read, write, other operations block oriented byte oriented (char stream) Buffer cache ◆ Buffer cache Reduce client/server disk I/Os Management physical sector #’s named files Disk allocation ◆ Disk allocation Disk Drivers no protection users protected from ◆ Layout, mapping files to blocks each other ◆ Security, protection, reliability, durability
data might be corrupted robust to machine failures ◆ Management tools if machine crashes 4
1 11/8/17
Topics Typical File Attributes
◆ File system structure • Name ◆ Disk allocation and i-nodes • Type – needed for systems that support different types ◆ Directory and link implementations • Location – pointer to file location on device. ◆ Physical layout for performance • Size – current file size. • Protection – controls who can read, write, execute • Time, date, and user identification – data for protection, security, and usage monitoring
• Information about files are kept in the directory structure, which is maintained on the disk
2
Typical Layout of a Disk Partition File Types – Name, Extension
◆ Boot block Boot block Code to load and boot OS File Type Usual extension Function Executable exe, com, bin or ready-to-run machine- ◆ Super-block defines a file system Superblock none language program File system info: type, no of blocks, ... Object obj, o complied, machine language, not linked File metadata File metadata area Source code c, p, pas, 177, source code in various (i-nodes in Unix) Information about / ptr to free blocks asm, a languages Batch bat, sh commands to the Location of descriptor of root directory Directory data command interpreter ◆ File metadata Text txt, doc textual data doc uments Each descriptor describes a file Word processor wp, tex, rrf, etc. various word-processor formats ◆ Directories File data Library lib, a libraries of routines Directory data (directory and file names) Print or view ps, dvi, gif ASCII or binary file ◆ File data Archive arc, zip, tar related files grouped Data blocks into one file, sometimes compressed. 3
2 11/8/17
Typical File Operations Open A File: Open(fd, name, access)
◆ Various checking (directory and file name lookup, authenticate) • Create ◆ Copy the file descriptors into the in-memory data structure • Write ◆ Create an entry in the open file table (system wide) • Read ◆ Create an entry in PCB File system • Reposition within file – file seek ◆ Return user a pointer to “file descriptor” info Process File • Delete control Open-file table descriptors File block (system-wide) (Metadata) • Truncate metadata
• Open(Fi) – search the directory structure on disk for Directories entry Fi, and move the content of entry to memory.
• Close (Fi) – move the content of entry Fi in memory to Open directory structure on disk. file File data pointer . array .
5
Translating from user to system view File system design constraints
• User wants to read 10 bytes from file starting at byte 2? • For small files: Seek byte 2, fetch the block, read 10 bytes Small blocks for storage efficiency Files used together should be stored together • User wants to write 10 bytes to file starting at byte 2? Seek byte 2, fetch the block, write 10 bytes, write out block • For large files: Contiguous allocation for sequential access • Everything inside file system is in whole size blocks Efficient lookup for random access Even getc and putc buffers 4096 bytes • May not know at file creation whether file will become • From now on, file is collection of blocks. small or large
3 11/8/17
File usage patterns File system design
• How do users access files? • Data structures Sequential: bytes read in order Directories: file name -> file metadata Random: read/write element out of middle of arrays • Store directories as files Content-based access: find me next byte starting with “COS318” File metadata: used to find file data blocks • How are files used? Free map: list of free disk blocks Most files are small