File Systems: Naming

Similar documents
COS 318: Operating Systems. Journaling, NFS and WAFL

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

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

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

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

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

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

Virtual File System. Don Porter CSE 306

File System Internals. Jo, Heeseung

File Systems. CS170 Fall 2018

The UNIX File System

Directory. File. Chunk. Disk

The UNIX File System

Arvind Krishnamurthy Spring Implementing file system abstraction on top of raw disks

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

File Systems. Information Server 1. Content. Motivation. Motivation. File Systems. File Systems. Files

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

File Systems. What do we need to know?

Virtual File System. Don Porter CSE 506

Computer Systems Laboratory Sungkyunkwan University

Page 1. Recap: File System Goals" Recap: Linked Allocation"

Input & Output 1: File systems

we are here I/O & Storage Layers Recall: C Low level I/O Recall: C Low Level Operations CS162 Operating Systems and Systems Programming Lecture 18

INTRODUCTION TO THE UNIX FILE SYSTEM 1)

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

Tricky issues in file systems

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

CS 4284 Systems Capstone

Lecture 19: File System Implementation. Mythili Vutukuru IIT Bombay

Files and File Systems

File Systems. CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse]

Unix Filesystem. January 26 th, 2004 Class Meeting 2

CS 550 Operating Systems Spring File System

Logical disks. Bach 2.2.1

Page 1. Review: Storage Performance" SSD Firmware Challenges" SSD Issues" CS162 Operating Systems and Systems Programming Lecture 14

5/8/2012. Creating and Changing Directories Chapter 7

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

File Systems Management and Examples

Files and File Systems

Network File System (NFS)

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

Network File System (NFS)

Motivation: I/O is Important. CS 537 Lecture 12 File System Interface. File systems

CS510 Operating System Foundations. Jonathan Walpole

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 18: Naming, Directories, and File Caching

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

File System Structure. Kevin Webb Swarthmore College March 29, 2018

UNIX File Systems. How UNIX Organizes and Accesses Files on Disk

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 18: Naming, Directories, and File Caching

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Typical File Extensions File Structure

File Systems. File Examples. Carsten Griwodz University of Oslo. (includes slides from Pål Halvorsen, Kai Li, A. Tanenbaum and M.

Files and the Filesystems. Linux Files

OPERATING SYSTEMS: Lesson 12: Directories

Advanced Operating Systems

CS197U: A Hands on Introduction to Unix

FS Facilities. Naming, APIs, and Caching OS Lecture 17. UdS/TUKL WS 2015 MPI-SWS 1

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

File Systems. CSE 2431: Introduction to Operating Systems Reading: Chap. 11, , 18.7, [OSC]

CS162 Operating Systems and Systems Programming Lecture 14 File Systems (Part 2)"

File Layout and Directories

Operating Systems. File Systems. Thomas Ropars.

Filesystem Hierarchy and Permissions

FILE SYSTEMS. Tanzir Ahmed CSCE 313 Fall 2018

CSE380 - Operating Systems

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

OPERATING SYSTEMS CS136

File Systems. Chapter 11, 13 OSPP

Filesystem Hierarchy and Permissions

Today: Distributed File Systems. File System Basics

Pintos Project 4 File Systems. November 14, 2016

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

Commands are in black

Today: Distributed File Systems

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

tmpfs: A Virtual Memory File System

Unix System Architecture, File System, and Shell Commands

Operating System Labs. Yuanbin Wu

The medium is the message. File system fun. Disk review Disk reads/writes in terms of sectors, not bytes. Disk vs. Memory. Files: named bytes on disk

Preview. COSC350 System Software, Fall

CS 111. Operating Systems Peter Reiher

Review: FFS [McKusic] basics. Review: FFS background. Basic FFS data structures. FFS disk layout. FFS superblock. Cylinder groups

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

File Systems: Recovery

Case study: ext2 FS 1

Operating Systems CMPSC 473 File System Implementation April 10, Lecture 21 Instructor: Trent Jaeger

COMP 530: Operating Systems File Systems: Fundamentals

Lab 4 File System. CS140 February 27, Slides adapted from previous quarters

CS 140 Project 4 File Systems Review Session

Filesystem. Disclaimer: some slides are adopted from book authors slides with permission

File system fun. File systems: traditionally hardest part of OS. - More papers on FSes than any other single topic

File System. yihshih

Operating Systems 2015 Assignment 4: File Systems

Review: FFS background

Distributed Systems. Distributed File Systems. Paul Krzyzanowski

Motivation. Operating Systems. File Systems. Outline. Files: The User s Point of View. File System Concepts. Solution? Files!

Manage Directories and Files in Linux. Objectives. Understand the Filesystem Hierarchy Standard (FHS)

File system fun. File systems: traditionally hardest part of OS

Transcription:

File Systems: Naming Learning Objective Explain how to implement a hierarchical name space. Identify the key SFS data structures. Map system call level operations to manipulations of SFS data structures. Topics: Naming exercise In-depth study of directory implementation SFS data structures SFS operations 3/24/16 CS161 Spring 2016 1

Exercise 3: Naming Let s think about how to implement a hierarchical name space (i.e., directories & files). How will you represent a directory? How will you find the root directory ( / )? How will you support traversing up a directory tree (cd..)? Be as specific as you can. 3/24/16 CS161 Spring 2016 2

Hierarchical Naming Generalized tree structure Directories are regular files with a special format. A bit in the file meta-data indicates that a file is of type directory. A directory entry is simply a mapping between names and a file index (a collection of name/value pairs). User programs can read directories just like they read files. Only the operating system can write directories (wouldn t want a user to corrupt the directory structure) Pros: Cons: / bin mach_kernel usr ls cat bin etc lib 3/24/16 CS161 Spring 2016 3

Hierarchical Naming Generalized tree structure Directories are regular files with a special format. A bit in the file meta-data indicates that a file is of type directory. A directory entry is simply a mapping between names and a file index (a collection of name/value pairs). User programs can read directories just like they read files. Only the operating system can write directories (wouldn t want a user to corrupt the directory structure) / Pros: Reuses file implementation Mimics how people used to organize files in file cabinets. Cons: Doesn t natively provide the kind of searching that is commonplace today in data organization. bin mach_kernel usr ls cat bin etc lib 3/24/16 CS161 Spring 2016 4

Traditional Directory Implementation Directories are represented like files. Contents of directories are structured (dirents). Name Inodenumber Type Directories grow in chunks of direntsthat fit on a single disk block. Root directory has a designated inode. 3/24/16 CS161 Spring 2016 5

The Root Directory This is the contents of the / directory on my machine. Name inumber Name inumber Name inumber Applications 113 Desktop Folder 844727 Developer 844731 Documents 937803 Library 213 Marketocracy 937813 Network 84416 System 37 Updaters 937816 Users 38892 Volumes 26447 bin 24377 cdrom 937840 cores 84418 dev 296 etc 25116 home 5 mach_kernel 552433 net 3 opt 937844 private 214 sbin 4512 sw 1024168 tmp 25155 usr 40 var 25156. 2.. 2 3/24/16 CS161 Spring 2016 6

Walking a Directory Path For historical reasons (because original versions of UNIX did this) we call: File index structures: inodes References to file index structures: inumbers Given a path /C1/C2/C3 Start at the root directory (a designated directory with a designated inumber). 1. Let inum = root directory inumber; current component = C1 2. Read the directory data for inum 3. Find the entry with the name equal to the current component 4. Fine the associated inumber 5. Read the inode for that inumber If it s not a directory, this is a bad pathname If it is a directory, set inumto the inumber; set current component to next part of path and iterate back to step 2. 3/24/16 CS161 Spring 2016 7

Assume: Inode 2 is in disk block 100 Inodes fit 8 to the block Block 100 contains inodes 0-7, 101 contains 8-15, etc. There are 100 blocks of inodes Directory Example Inodes Data Blocks Disk block number 100 200 101 202 203 102 204 205 Contents 200., 2.., 2 bin,8 usr, 16 boot, 35 kadb, 27 201., 11.., 2 Some text The number in these inodesis what is found in daddr[0] 203., 9.., 16 libc.a, 55 Exercise: List all the blocks, in font, 77 order that you need to 204., 16.., 2 lib, 9 read to open share, 52 ucb, 15 old, 66 /usr/lib/libc.a 3/24/16 CS161 Spring 2016 8 is in this file 202., 8.., 2 ls, 91 csh, 105

Assume: Inode 2 is in disk block 100 Inodes fit 8 to the block Block 100 contains inodes 0-7, 101 contains 8-15, etc. There are 100 blocks of inodes Directory Example Inodes Data Blocks Disk block number 100 200 101 202 203 102 204 205 Contents 200., 2.., 2 bin,8 usr, 16 boot, 35 kadb, 27 201., 11.., 2 Some text The number in these inodesis what is found in daddr[0] 203., 9.., 16 libc.a, 55 Exercise: List all the blocks, in font, 77 order that you need to 204., 16.., 2 lib, 9 read to open share, 52 ucb, 15 old, 66 /usr/lib/libc.a 3/24/16 CS161 Spring 2016 9 is in this file 202., 8.., 2 ls, 91 csh, 105

More Directory Fun In POSIX, every directory has two special entries. and... The. directory refers to the directory itself. The.. directory refers to the parent directory. This is how the file system implements paths such as../asst2. It is possible for more than one directory entry to refer to a single file. Hard link: the same inumber appears in two different directories. The reference count for the inumber is incremented. Could you create a hard link between two directories in different file systems? When you remove (unlink) a file, you decrement its reference count and remove a name from a directory. When the reference count goes to zero, the file s blocks are actually freed. Soft link (symbolic link): file that contains the name of another file. Files of this sort are identified by a bit in their file descriptor. When the OS encounters a symbolic link, it continues pathname resolution using the pathname that appears in the file. Can you create a soft link between two directories? What is the minimum link count for a directory? 3/24/16 CS161 Spring 2016 10

Working Directory It is cumbersome (and inefficient for the OS) to use full pathnames every time you reference a file. POSIX maintains a single current working directory (cwd) for each process. The inumber of the cwd is stored in the user structure. When the OS wants to translate a name to an inumber, it looks at the first character in the path. If that character is /, the OS begins looking at the root. If it is not a path, the OS begins looking in the current directory. Some systems allow you to have more than one current working directory. The list of directories that are in the current working directory set are called a search path. 3/24/16 CS161 Spring 2016 11

The VFS/VnodeLayer Context: The year is 1985 (do not remind me that you weren t even born or your parents weren t even married yet). Personal computers are fairly new toys. Single-user workstations (powerful personal computers) are a new thing. Workstation users need to store files reliably. Workstations have local disks, but they aren t terribly reliable, and if a workstation crashes, its disks (and data) are unavailable. It s difficult to access one workstation s files from another workstation. So, what do you do? 3/24/16 CS161 Spring 2016 12

The VFS/VnodeLayer Context: The year is 1985 (do not remind me that you weren t even born or your parents weren t even married yet). Personal computers are fairly new toys. Single-user workstations (powerful personal computers) are a new thing. Workstation users need to store files reliably. Workstations have local disks, but they aren t terribly reliable, and if a workstation crashes, its disks (and data) are unavailable. It s difficult to access one workstation s files from another workstation. So, what do you do? You build a network file system! (NFS) 3/24/16 CS161 Spring 2016 13

The Engineering Challenge Traditionally a system had only a single file system. Now you want to add a second one. How do you do it? Hand code everything? Think about a generic interface to the file system code and rewrite the existing system to use it. 3/24/16 CS161 Spring 2016 14

The Engineering Challenge Traditionally a system had only a single file system. Now you want to add a second one. How do you do it? Hand code everything? Think about a generic interface to the file system code and rewrite the existing system to use it. Enter VFS: Virtual File System: one VFS/file system Operations performed on entire file systems, e.g., : unmount root returns the root of the file system statfs returns file system statistics sync write all dirty data to disk 3/24/16 CS161 Spring 2016 15

Vnodes One vnode per file Abstract representation of a file To get real work done, you have to pass the operation to the underlying implementation. Vnode operations: open setattr mkdir inactive close lookup rmdir bmap rdwr create readdir strategy ioctl remove symlink bread select link readlink brelse getattr rename fsync 3/24/16 CS161 Spring 2016 16

And Speaking of SFS How does SFS represent a file? kern/include/kern/sfs.h struct sfs_inode { uint32_t sfi_size; /* File size in bytes */ uint16_t sfi_type; /* File or directory */ uint16_t sfi_linkcount; /* #hard links */ uint32_t sfi_direct[15]; /* Direct blocks */ uint32_t sfi_indirect; /* Indirect block */ uint32_t sfi_dindirect; /* Double indirect */ uint32_t sfi_tindirect; /* Triple indirect */ uint32_t sfi_waste[108]; /* Pad to 512 bytes */ } 3/24/16 CS161 Spring 2016 17

SFS Free Space Management See kern/include/sfs.h A struct sfs_fs is the in-memory representation of an SFS file system. That structure has the following fields: struct bitmap *sfs_freemap; bool sfs_freemapdirty; struct lock *sfs_freemaplock; The file kern/include/kern/sfs.h defines the following constants: #define SFS_FREEMAP_START 2 3/24/16 CS161 Spring 2016 18

SFS Directories See kern/include/kern/sfs.h struct sfs_direntry { uint32_t sfd_ino; /* Inode number */ char sfd_name[60]; /* Filename */ }; So, how large is each entry? And how many entries do you fit in a block? Can you think of two different ways we might keep track of how many valid entries are in a directory? 3/24/16 CS161 Spring 2016 19

3/24/16 CS161 Spring 2016 20

SFS Idiosyncracy Where do inodes live? Anywhere they want! Since an inode consumes an entire block, we allocate an inode by asking the allocator for a free block. The block number is the inode number. The root directory has a designated inode (#1). 3/24/16 CS161 Spring 2016 21

Implementing File System Operations Given the data structures used to implement SFS, you should now be able to construct most file system operations. Let s walk through creating a file. Assume that you have a vnodefor a parent directory and you are asked to create file newfile What do you have to do? 3/24/16 CS161 Spring 2016 22

Other Operations 1. How would you modify the previous operation to create a directory instead of a file? 2. What do you have to do to delete a file? 3/24/16 CS161 Spring 2016 23