Operating Systems File Systems ENCE 360.

Slides:



Advertisements
Similar presentations
More on File Management
Advertisements

Chapter 4 : File Systems What is a file system?
File Systems.
File Systems Examples.
COS 318: Operating Systems File Layout and Directories
Operating Systems File Systems CNS 3060.
Operating Systems File Systems.
Operating Systems File Systems (in a Day) Ch
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
File Systems Topics –File –Directory –File System Implementation Reference: Chapter 5: File Systems Operating Systems Design and Implementation (Second.
Ceng Operating Systems
Operating Systems File Systems (Select parts of Ch 6)
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
1 File Management in Representative Operating Systems.
1 Friday, July 07, 2006 “Vision without action is a daydream, Action without a vision is a nightmare.” - Japanese Proverb.
CS4513 Distributed Computer Systems
Operating Systems File Systems (Ch , Ch )
Operating Systems File Systems (Select parts of Ch 11-12)
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
File Systems. Main Points File layout Directory layout.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
Operating System Concepts and Techniques Lecture 17
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
CS333 Intro to Operating Systems Jonathan Walpole.
1 File Systems: Consistency Issues. 2 File Systems: Consistency Issues File systems maintains many data structures  Free list/bit vector  Directories.
File System Implementation
Some basic concepts and information on file systems Portions taken and modified from books by ANDREW S. TANENBAUM.
Chapter 16 File Management The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander John.
Why Do We Need Files? Must store large amounts of data. Information stored must survive the termination of the process using it - that is, be persistent.
UNIX File System (UFS) Chapter Five.
File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
Annotated by B. Hirsbrunner File Systems Chapter Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview.
File Systems Topics Design criteria History of file systems Berkeley Fast File System Effect of file systems on programs fs.ppt CS 105 “Tour of the Black.
Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.
11.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 11.5 Free-Space Management Bit vector (n blocks) … 012n-1 bit[i] =  1  block[i]
Lecture 20 FSCK & Journaling. FFS Review A few contributions: hybrid block size groups smart allocation.
Review CS File Systems - Partitions What is a hard disk partition?
操作系统原理 OPERATING SYSTEMS Chapter 4 File Systems 文件系统.
W4118 Operating Systems Instructor: Junfeng Yang.
COMP 3500 Introduction to Operating Systems Directory Structures Block Management Dr. Xiao Qin Auburn University
The need for File Systems Need to store data and programs in files Must be able to store lots of data Must be nonvolatile and survive crashes and power.
Day 28 File System.
File-System Management
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 11: File System Implementation
File System Structure How do I organize a disk into a file system?
Filesystems.
Journaling File Systems
File Management.
EECE.4810/EECE.5730 Operating Systems
File Sharing Sharing of files on multi-user systems is desirable
Chapter 11: File System Implementation
CS510 Operating System Foundations
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Directory Structure A collection of nodes containing information about all files Directory Files F 1 F 2 F 3 F 4 F n Both the directory structure and the.
Introduction to Operating Systems
File System Implementation
File-System Structure
Chapter 16 File Management
Chapter 14: File-System Implementation
File system : Disk Space Management
SE350: Operating Systems Lecture 12: File Systems.
CS 105 “Tour of the Black Holes of Computing”
Chapter 12: File-System Implementation CSS503 Systems Programming
Chapter 5 File Systems -Compiled for MCA, PU
Presentation transcript:

Operating Systems File Systems ENCE 360

Motivation – Top Down: Process Need Processes store, retrieve information When process terminates, memory lost How to make it persist? What if multiple processes want to share? Requirements: large persistent concurrent access Solution? Hard disks are large, persistent!

Motivation – Bottom Up: Hard Disks Disks come formatted with blocks (typically 512 bytes) bs – boot sector sb – super block Requirements Differentiation of data blocks Reading and writing of blocks Efficient access http://read.cs.ucla.edu/111/2007fall/notes/lec12 CRUX: HOW TO IMPLEMENT A FILE SYSTEM ON A HARD DISK How to find information? How to map blocks to files of all sizes? How to know which blocks are free? Solution? File Systems

MODERN OPERATING SYSTEMS (MOS) Outline Introduction (done) Implementation (next) Directories Journaling Chapter 4 MODERN OPERATING SYSTEMS (MOS) By Andrew Tanenbaum Chapter 39, 40 OPERATING SYSTEMS: THREE EASY PIECES  By Arpaci-Dusseau and Arpaci-Dusseau

Example: Unix open() path is name of file (NULL terminated string) int open(char *path, int flags [, int mode]) path is name of file (NULL terminated string) flags is bitmap to set switch O_RDONLY, O_WRONLY, O_TRUNC … O_CREATE then use mode for permissions success returns index On error, -1 and set errno

Unix open() – Under the Hood int fid = open(“blah”, flags); read(fid, …); User Space System Space Disk Process Control Block File sys info File Descriptor Table 1 2 3 stdin stdout stderr ... Copy fd to mem Open File Table File descriptors ... File Descriptor Directories File Structure (index) ... Data (File attributes) (Where blocks are) (Per process) (Per device)

File System Implementation Core data to track: which blocks with which file? Job of the file descriptor Different implementations: Contiguous allocation Linked list allocation Linked list allocation with index Inode File Descriptor

Contiguous Allocation (1 of 2) Store file as contiguous blocks on disk Good: Easy: file descriptor knows file location in 1 number (start block) Efficient: read entire file in 1 operation (start & length) Bad: Static: need to know file size at creation Or tough to grow! Fragmentation: chunks of disk “free” but can’t be used (Example next slide)

Contiguous Allocation (2 of 2) Delete Delete Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639 What if want new file, size 8 blocks?  Fragmentation (“free” but can’t be used)

Linked List Allocation Keep linked list with disk blocks null File Block 1 null File Block 1 2 Physical Block 4 7 2 6 3 Good: Easy: remember 1 number (location) Efficient: no space lost in fragmentation Bad: Slow: random access bad (e.g., process want’s middle block)

Linked List Allocation with Index Physical Block 1 null 2 3 7 4 5 6 Table in memory MS-DOS FAT, Win98 VFAT Good: faster random access Bad: can be large! e.g., 1 TB disk, 1 KB blocks Table needs 1 billion entries Each entry 3 bytes (say 4 typical)  4 GB memory! “File Allocation Table” Common format still (e.g., USB drives) since supported by many OSes & additional features not needed

inode Typically 15 pointers 12 to direct blocks 1 single indirect Fast for small files Can hold large files http://en.wikipedia.org/wiki/File:Ext2-inode.gif Typically 15 pointers 12 to direct blocks 1 single indirect 1 doubly indirect 1 triply indirect Number of pointers per block? Depends on block size and pointer size e.g., 1k byte block, 4 byte pointer  each indirect has 256 pointers Max size of file? Same – depends on block size and pointer size e.g., 4KB block, 4 byte pointer  max size 2 TB

Linux File System: ext3 inode // linux/include/linux/ext3_fs.h #define EXT3_NDIR_BLOCKS 12 // Direct blocks #define EXT3_IND_BLOCK EXT3_NDIR_BLOCKS + 1 // Indirect block index #define EXT3_DIND_BLOCK EXT3_IND_BLOCK + 1 // Double-ind. block index #define EXT3_TIND_BLOCK EXT3_DIND_BLOCK + 1 // Triple-ind. block index #define EXT3_N_BLOCKS EXT3_TIND_BLOCK + 1 // (Last index & total) struct ext3_inode { __u16 i_mode; // File mode __u16 i_uid; // Low 16 bits of owner Uid __u32 i_size; // Size in bytes __u32 i_atime; // Access time __u32 i_ctime; // Creation time __u32 i_mtime; // Modification time __u32 i_dtime; // Deletion time __u16 i_gid; // Low 16 bits of group Id __u16 i_links_count; // Links count __u32 i_blocks; // Blocks count ... __u32 i_block[EXT3_N_BLOCKS]; // Block pointers }

Outline Introduction (done) Implementation (done) Directories (next) Journaling

Directory Implementation Just like files (“wait, what?”) Have data blocks File descriptor to map which blocks to directory But have special bit set so user process cannot modify contents Data in directory is information / links to files Modify only through system call (right) Tree structure, directory most common Directory System Calls Create Delete Opendir Closedir Readdir Rename Link Unlink See: “ls.c”

Where are file attributes (e.g., owner, permissions) stored? Directories Before reading file, must be opened Directory entry provides information to get blocks Disk location (blocks, address) Map ASCII name to file descriptor name block count block numbers Where are file attributes (e.g., owner, permissions) stored?

Options for Storing Attributes Directory entry has attributes (Windows) Directory entry refers to file descriptor (e.g., inode), and descriptor has attributes (Linux) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Windows (FAT) Directory Hierarchical directories Entry: name - date type (extension) - block number (w/FAT) time name type attrib time date block size

Unix Directory Hierarchical directories Entry: name inode number (try “ls –i” or “ls –iad .”) Example, say want to read data from below file /usr/bob/mbox Want contents of file, which is in blocks Need file descriptor (inode) to get blocks How to find the file descriptor (inode)? inode name

User Access to Same File in More than One Directory B C A ? (Instead of tree, really have directed acyclic graph) “alias” Possibilities for “alias”: Refer to file descriptor in two locations – “hard link” Special directory entry points to real directory entry – “soft link” Examples: try “ln”, “ln -s” and “ls -i” Windows “shortcut” – but only viewable by graphic browser, absolute paths, with metadata, can track even if move

Keeping Track of Free Blocks Keep one large “file” of free blocks (use normal file descriptor) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639 Contents are linked-list of free blocks (can be small when full, but no locality) Contents are bitmap of free blocks (preserves locality, but 1-bit/block)

Outline Introduction (done) Implementation (done) Directories (done) Journaling (next)

Need for Robust File Systems Consider upkeep for removing file Remove file from directory entry Return all disk blocks to pool of free disk blocks Release file descriptor (e.g., inode) to pool of free descriptors What if system crashes in middle? a) inode becomes orphaned (lost+found, 1 per partition) b) Same blocks free and allocated If flip steps, blocks/descriptor free but directory entry exists! Crash consistency problem inode 5 91 12 3 1 91 2

Crash Consistency Problem Disk guarantees that single sector writes are atomic But no way to make multi-sector writes atomic How to ensure consistency after crash? Don’t bother to ensure consistency Accept that the file system may be inconsistent after crash Run program that fixes file system during bootup File system checker (e.g., fsck) Use transaction log to make multi-writes atomic Log stores history of all writes to disk After crash log “replayed” to finish updates Journaling file system http://www.ccs.neu.edu/home/cbw/5600/slides/10_File_Systems.pptx

File System Checker – the Good and the Bad Advantages of File System Checker Doesn’t require file system to do any work to ensure consistency Makes file system implementation simpler Disadvantages of File System Checker Complicated to implement fsck program Many possible inconsistencies that must be identified Many difficult corner cases to consider and handle Usually super sloooooooow… Scans entire file system multiple times Consider really large disks, like 400 TB RAID array! http://www.ccs.neu.edu/home/cbw/5600/slides/10_File_Systems.pptx

Journaling File Systems Write intent to do actions (a-c) to log (aka “journal”) before starting Option - read back to verify integrity before continue Perform operations Erase log If system crashes, when restart read log and apply operations Logged operations must be idempotent (can be repeated without harm) Superblock Journal Block Group 0 Block Group 1 … Block Group N

Journaling Example Before executing writes, first log them Assume appending new data block (D2) to file 3 writes: inode v2, data bitmap v2, data D2 Before executing writes, first log them TxB ID=1 I v2 B v2 D2 TxE ID=1 Journal TxB: Begin new transaction with unique ID=1 Write updated meta-data block (inode, data bitmap) Write file data block TxE: Write end-of-transaction with ID=1 http://www.ccs.neu.edu/home/cbw/5600/slides/10_File_Systems.pptx

Commits and Checkpoints Transaction committed after all writes to log complete After transaction is completed, OS checkpoints update Committed! Journal TxB I v2 B v2 D2 TxE v1 D1 Inode Bitmap Data Inodes Data Blocks Checkpointed! http://www.ccs.neu.edu/home/cbw/5600/slides/10_File_Systems.pptx v2 D2 Final step: free checkpointed transaction

Crash Recovery (1 of 2) What if system crashes during logging? If transaction not committed, data lost But, file system remains consistent! Journal TxB I v2 B v2 D2 v1 D1 Inode Bitmap Data Inodes Data Blocks http://www.ccs.neu.edu/home/cbw/5600/slides/10_File_Systems.pptx

Crash Recovery (2 of 2) What if system crashes during checkpoint? File system may be inconsistent During reboot, transactions committed but not completed are replayed in order Thus, no data is lost and consistency restored! Journal TxB I v2 B v2 D2 TxE http://www.ccs.neu.edu/home/cbw/5600/slides/10_File_Systems.pptx v1 D1 Inode Bitmap Data Inodes Data Blocks v2 D2

(Left for student exploration) Journaling Summary Advantages of journaling Robust, fast file system recovery No need to scan entire journal or file system Relatively straight forward to implement Disadvantages of journaling Write traffic to disk doubled Especially file data, which is probably large Can fix! Only journal meta-data! (Left for student exploration) Today, most OSes use journaling file systems ext3/ext4 on Linux NTFS on Windows Provides crash recovery with relatively low space and performance overhead Next-gen OSes likely move to file systems with copy-on-write semantics btrfs and zfs on Linux http://www.ccs.neu.edu/home/cbw/5600/slides/10_File_Systems.pptx

Outline Introduction (done) Implementation (done) Directories (done) Journaling (done)