RCU. ò Dozens of supported file systems. ò Independent layer from backing storage. ò And, of course, networked file system support

Similar documents
Virtual File System. Don Porter CSE 506

Virtual File System. Don Porter CSE 306

CSE506: Operating Systems CSE 506: Operating Systems

Fall 2017 :: CSE 306. File Systems Basics. Nima Honarmand

RCU. ò Walk through two system calls in some detail. ò Open and read. ò Too much code to cover all FS system calls. ò 3 Cases for a dentry:

VFS, Continued. Don Porter CSE 506

Ext3/4 file systems. Don Porter CSE 506

Basic OS Progamming Abstrac7ons

Basic OS Progamming Abstrac2ons

CSE506: Operating Systems CSE 506: Operating Systems

Lecture 19: File System Implementation. Mythili Vutukuru IIT Bombay

File Systems. What do we need to know?

Block Device Scheduling. Don Porter CSE 506

Block Device Scheduling

3/26/2014. Contents. Concepts (1) Disk: Device that stores information (files) Many files x many users: OS management

TDDB68 Concurrent Programming and Operating Systems. Lecture: File systems

Logical disks. Bach 2.2.1

1 / 23. CS 137: File Systems. General Filesystem Design

File Systems. CS170 Fall 2018

CSE 506: Opera.ng Systems. The Page Cache. Don Porter

The Page Cache 3/16/16. Logical Diagram. Background. Recap of previous lectures. The address space abstracvon. Today s Problem.

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

CS370 Operating Systems

COS 318: Operating Systems. Journaling, NFS and WAFL

Page Frame Reclaiming

ECE 598 Advanced Operating Systems Lecture 19

Operating System Labs. Yuanbin Wu

read(2) There can be several cases where read returns less than the number of bytes requested:

Introduction to File Systems

Network File System (NFS)

File Systems. Chapter 11, 13 OSPP

COS 318: Operating Systems. NSF, Snapshot, Dedup and Review

Secure Software Programming and Vulnerability Analysis

Operating Systems Design Exam 2 Review: Fall 2010

ò Server can crash or be disconnected ò Client can crash or be disconnected ò How to coordinate multiple clients accessing same file?

CS370 Operating Systems

NFS. Don Porter CSE 506

Operating System Labs. Yuanbin Wu

CptS 360 (System Programming) Unit 6: Files and Directories

ò Very reliable, best-of-breed traditional file system design ò Much like the JOS file system you are building now

Files and the Filesystems. Linux Files

1 / 22. CS 135: File Systems. General Filesystem Design

File System Interface. ICS332 Operating Systems

File Systems: Naming

Basic OS Programming Abstractions (and Lab 1 Overview)

INTRODUCTION TO THE UNIX FILE SYSTEM 1)

Long-term Information Storage Must store large amounts of data Information stored must survive the termination of the process using it Multiple proces

W4118 Operating Systems. Instructor: Junfeng Yang

Implementation should be efficient. Provide an abstraction to the user. Abstraction should be useful. Ownership and permissions.

File Systems Ch 4. 1 CS 422 T W Bennet Mississippi College

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

File Systems. Kartik Gopalan. Chapter 4 From Tanenbaum s Modern Operating System

Native POSIX Thread Library (NPTL) CSE 506 Don Porter

UNIT I Linux Utilities

Distributed File Systems

Files and File System

OPERATING SYSTEMS CS136

Typical File Extensions File Structure

Chapter 6. File Systems

Operating Systems. File Systems. Thomas Ropars.

File Management 1/34

The UNIX File System

To understand this, let's build a layered model from the bottom up. Layers include: device driver filesystem file

V. File System. SGG9: chapter 11. Files, directories, sharing FS layers, partitions, allocations, free space. TDIU11: Operating Systems

File System Internals. Jo, Heeseung

FILE SYSTEMS. Tanzir Ahmed CSCE 313 Fall 2018

File System Internals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS2028 -UNIX INTERNALS

The UNIX Time- Sharing System

Chapter 8: Filesystem Implementation

UNIX File System. UNIX File System. The UNIX file system has a hierarchical tree structure with the top in root.

CS720 - Operating Systems

File Systems: Interface and Implementation

A2 Design Considerations. CS161, Spring

File System Code Walkthrough

COS 318: Operating Systems. File Systems. Topics. Evolved Data Center Storage Hierarchy. Traditional Data Center Storage Hierarchy

8. Files and File Systems

Chapter 11: File-System Interface

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

OPERATING SYSTEM. Chapter 12: File System Implementation

Chapter 11: File System Implementation. Objectives

File Systems: Interface and Implementation

File Systems: Interface and Implementation

Announcements/Reminders

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

What is a file system

File Systems. Todays Plan. Vera Goebel Thomas Plagemann. Department of Informatics University of Oslo

File I/O and File Systems

Files and File Systems

VIRTUAL FILE SYSTEM AND FILE SYSTEM CONCEPTS Operating Systems Design Euiseong Seo

EXPLODE: a Lightweight, General System for Finding Serious Storage System Errors. Junfeng Yang, Can Sar, Dawson Engler Stanford University

Operating Systems. No. 9 ศร ณย อ นทโกส ม Sarun Intakosum

Chapter 11: Implementing File Systems

Computer Systems Laboratory Sungkyunkwan University

Directory. File. Chunk. Disk

CS 326: Operating Systems. Process Execution. Lecture 5

Outline. File Systems. File System Structure. CSCI 4061 Introduction to Operating Systems

Da-Wei Chang CSIE.NCKU. Professor Hao-Ren Ke, National Chiao Tung University Professor Hsung-Pin Chang, National Chung Hsing University

[537] Fast File System. Tyler Harter

CS 140 Project 4 File Systems Review Session

Transcription:

Logical Diagram Virtual File System Don Porter CSE 506 Binary Formats RCU Memory Management File System Memory Allocators System Calls Device Drivers Networking Threads User Today s Lecture Kernel Sync CPU Scheduler Interrupts Disk Net Consistency Hardware History Modern VFS Early OSes provided a single file system In general, system was pretty tailored to target hardware In the early 80s, people became interested in supporting more than one file system type on a single system Any guesses why? Networked file systems sharing parts of a file system transparently across a network of workstations Dozens of supported file systems Allows experimentation with new features and designs transparent to applications Interoperability with removable media and other OSes Independent layer from backing storage Pseudo FSes used for configuration (/proc, /devtmps ) only backed by kernel data structures And, of course, networked file system support More detailed diagram User s perspective User Kernel VFS ext4 btrfs fat32 nfs Page Cache Block Device Network IO Scheduler Driver Disk Single programming interface (POSIX file system calls open, read, write, etc.) Single file system tree A remote file system with home directories can be transparently mounted at /home Alternative: Custom library for each file system Much more trouble for the programmer 1

What the VFS does FS Developer s Perspective The VFS is a substantial piece of code, not just an API wrapper Caches file system metadata (e.g., file names, attributes) Coordinates data caching with the page cache Enforces a common access control model Implements complex, common routines, such as path lookup, file opening, and file handle management FS developer responsible for implementing a set of standard objects/functions, which are called by the VFS Primarily populating in-memory objects from stable storage, and writing them back Can use block device interfaces to schedule disk I/O And page cache functions And some VFS helpers Analogous to implementing Java abstract classes High-level FS dev. tasks Opportunities Translate between volatile VFS objects and backing storage (whether device, remote system, or other/none) Potentially includes requesting I/O Read and write file pages VFS doesn t prescribe all aspects of FS design More of a lowest common denominator Opportunities: (to name a few) More optimal media usage/scheduling Varying on-disk consistency guarantees Features (e.g., encryption, virus scanning, snapshotting) Core VFS abstractions Super blocks super block FS-global data Early/many file systems put this as first block of partition inode (index node) metadata for one file dentry (directory entry) file name to inode mapping file a file handle refers to a dentry and a cursor in the file (offset) SB + inodes are extended by FS developer Stores all FS-global data Opaque pointer (s_fs_info) for fs-specific data Includes many hooks for tasks such as creating or destroying inodes Dirty flag for when it needs to be synced with disk Kernel keeps a circular list of all of these 2

Inode Inode history The second object extended by the FS Huge more fields than we can talk about Tracks: File attributes: permissions, size, modification time, etc. File contents: Address space for contents cached in memory Low-level file system stores block locations on disk Flags, including dirty inode and dirty data Name goes back to file systems that stored file metadata at fixed intervals on the disk If you knew the file s index number, you could find its metadata on disk Hence, the name index node Original VFS design called them vnode for virtual node (perhaps more appropriately) Linux uses the name inode Embedded inodes Linking Many file systems embed the VFS inode in a larger, FS-specific inode, e.g.,: struct donfs_inode { } int ondisk_blocks[]; /* other stuff*/ struct inode vfs_inode; Why? Finding the low-level data associated with an inode just requires simple (compiler-generated) math An inode uniquely identifies a file for its lifespan Does not change when renamed Model: Inode tracks links or references on disk Created by file names in a directory that point to the inode Ex: renaming the file temporarily increases link count and then lowers it again When link count is zero, inode (and contents) deleted There is no delete system call, only unlink Linking, cont. Inode stats Hard link (link system call/ln utility): creates a second name for the same file; modifications to either name changes contents. This is not a copy Open files create an in-memory reference to a file If an open file is unlinked, the directory entry is deleted immediately, but the inode and data are retained until all in-memory references are deleted Common trick for temporary files: create (1 link) open (1 link, 1 ref) unlink (0 link) File gets cleaned up when program dies (kernel removes last reference on exit) The stat word encodes both permissions and type High bits encode the type: regular file, directory, pipe, char device, socket, block device, etc. Unix: Everything s a file! VFS involved even with sockets! Lower bits encode permissions: 3 bits for each of User, Group, Other + 3 special bits Bits: 2 = read, 1 = write, 0 = execute Ex: 750 User RWX, Group RX, Other nothing 3

Special bits More special bits For directories, Execute means search X-only permissions means I can find readable subdirectories or files, but can t enumerate the contents Useful for sharing files in your home directory, without sharing your home directory contents Setuid bit Lots of information in meta-data! Mostly relevant for executables: Allows anyone who runs this program to execute with owner s uid Crude form of permission delegation Group inheritance bit In general, when I create a file, it is owned by my default group If I create in a g+s directory, the directory group owns the file Useful for things like shared git repositories Sticky bit Restricts deletion of files File objects File handle games Represent an open file; point to a dentry and cursor Each process has a table of pointers to them The int fd returned by open is an offset into this table These are VFS-only abstractions; the FS doesn t need to track which process has a reference to a file Files have a reference count. Why? Fork also copies the file handles If your child reads from the handle, it advances your (shared) cursor dup, dup2 Copy a file handle Just creates 2 table entries for same file struct, increments the reference count seek adjust the cursor position Obviously a throw-back to when files were on tapes fcntl Like ioctl (misc operations), but for files CLOSE_ON_EXEC a bit that prevents file inheritance if a new binary is exec ed (set by open or fcntl) Dentries Why dentries? These store: A file name A link to an inode A parent pointer (null for root of file system) Ex: /home/porter/vfs.pptx would have 4 dentries: /, home, porter, & vfs.pptx Parent pointer distinguishes /home/porter from /tmp/porter These are also VFS-only abstractions A simple directory model might just treat it as a file listing <name, inode> tuples Why not just use the page cache for this? FS directory tree traversal very common; optimize with special data structures The dentry cache is a complex data structure we will discuss in much more detail later Although inode hooks on directories can populate them 4

Summary of abstractions Super blocks FS- global data Inodes stores a given file File (handle) Essentially a <dentry, offset> tuple Dentry Essentially a <name, parent dentry, inode> tuple More on the user s perspective Let s wrap today by discussing some common FS system calls in more detail Let s play it as a trivia game What call would you use to Create a file? Create a directory? creat More commonly, open with the O_CREAT flag Avoid race conditions between creation and open What does O_EXCL do? Fails if the file already exists mkdir But I thought everything in Unix was a file!?! This means that sometimes you can read/write an existing handle, even if you don t know what is behind it. Even this doesn t work for directories Remove a directory Remove a file rmdir unlink 5

Read a file? Read a directory? read() How do you change cursor position? readdir or getdents lseek (or pread) Shorten a file What is a symbolic link? truncate/ftruncate Can also be used to create a file full of zeros of abritrary length Often blocks on disk are demand-allocated (laziness rules!) A special file type that stores the name of another file How different from a hard link? Doesn t raise the link count of the file Can be broken, or point to a missing file How created? symlink system call or ln s command Let s step it up a bit How does an editor save a file? Hint: we don t want the program to crash with a halfwritten file Create a backup (using open) Write the full backup (using read old/ write new) Close both Do a rename(old, new) to atomically replace 6

How does ls work? dh = open(dir) for each file (while readdir(dh)) Print file name close(dh) What about that cool colored text? dh = open(dir) for each file (while readdir(dh)) stat(file, &stat_buf) if (stat & execute bit) color == green else if Print file name Reset color close(dh) Summary Today s goal: VFS overview from many perspectives User (application programmer) FS implementer Key VFS objects Used many page cache and disk I/O tools we ve seen Important to be able to pick POSIX fs system calls from a line up Homework: think about pseudocode from any simple command-line file system utilities you type this weekend 7