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

Similar documents
Chapter 7: File-System

CS3600 SYSTEMS AND NETWORKS

Chapter 12: File System Implementation

Chapter 11: Implementing File

Chapter 11: Implementing File Systems. Operating System Concepts 9 9h Edition

File Systems: Interface and Implementation

File Systems: Interface and Implementation

CHAPTER 11: IMPLEMENTING FILE SYSTEMS (COMPACT) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Chapter 11: Implementing File Systems

OPERATING SYSTEM. Chapter 12: File System Implementation

File-System Interface. File Structure. File Concept. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

Chapter 10: File System Implementation

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Chapter 12: File System Implementation. Operating System Concepts 9 th Edition

Chapter 12: File System Implementation

Week 12: File System Implementation

Chapter 12: File System Implementation

File System Implementation

CS720 - Operating Systems

File Systems: Interface and Implementation

OPERATING SYSTEMS II DPL. ING. CIPRIAN PUNGILĂ, PHD.

Chapter 11: File-System Interface

CS307: Operating Systems

File System: Interface and Implmentation

TDDB68 Concurrent Programming and Operating Systems. Lecture: File systems

UNIT V SECONDARY STORAGE MANAGEMENT

Chapter 10: File System. Operating System Concepts 9 th Edition

File System & Device Drive Mass Storage. File Attributes (Meta Data) File Operations. Directory Structure. Operations Performed on Directory

CS370 Operating Systems

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

CSE 4/521 Introduction to Operating Systems. Lecture 23 File System Implementation II (Allocation Methods, Free-Space Management) Summer 2018

Chapter 10: File-System Interface. Operating System Concepts with Java 8 th Edition

Chapter 11: File-System Interface. Operating System Concepts 9 th Edition

Chapter 10: File-System Interface

Chapter 14: File-System Implementation

Chapter 11: File System Implementation. Objectives

Chapter 10: File-System Interface

CS370 Operating Systems

Advanced Operating Systems. File Systems Lecture 9

Chapter 11: File-System Interface

File-System Interface

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

CHAPTER 10 AND 11 - FILE SYSTEM & IMPLEMENTING FILE- SYSTEMS

Chapter 11: Implementing File-Systems

Chapter 11: File-System Interface

F 4. Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes

ICS Principles of Operating Systems

Lecture 10 File Systems - Interface (chapter 10)

Chapter 10: File-System Interface. Operating System Concepts 8 th Edition

File Management By : Kaushik Vaghani

File Systems. CS170 Fall 2018

Chapter 11: File-System Interface

Chapter 11: File-System Interface

Chapter 11: Implementing File Systems

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Chapter 11: File System Implementation

File-System. File Concept. File Types Name, Extension. File Attributes. File Operations. Access Methods. CS307 Operating Systems

CS3600 SYSTEMS AND NETWORKS

Chapter 11: Implementing File Systems

Chapter 10: File-System Interface

Part Four - Storage Management. Chapter 10: File-System Interface

Chapter 10: File-System Interface. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

A file system is a clearly-defined method that the computer's operating system uses to store, catalog, and retrieve files.

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

Chapter 6 Storage Management File-System Interface 11.1

File-System Structure. Allocation Methods. Free-Space Management. Directory Implementation. Efficiency and Performance. Recovery

Chapter 12 File-System Implementation

CS370 Operating Systems

Principles of Operating Systems

Chapter 10: File System

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Chapter 9: File System Interface

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 10: FILE SYSTEM

Chapter 11: File System Implementation

Chapter 11: File-System Interface. File Concept. File Structure

File System Management

Chapter 11: Implementing File Systems. Operating System Concepts 8 th Edition,

Files and File Systems

Chapter 11: File-System Interface. File Concept. File Structure

Chapter 11: File-System Interface

Chapter 11: File System Implementation

CSE325 Principles of Operating Systems. File Systems. David P. Duggan. March 21, 2013

Outlook. File-System Interface Allocation-Methods Free Space Management

Chapter 11: File-System Interface. Long-term Information Storage. File Structure. File Structure. File Concept. File Attributes

Chapter 11: Implementing File Systems

Modulo V Sistema de Arquivos

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

File System (FS) Highlights

V. Mass Storage Systems

File System CS170 Discussion Week 9. *Some slides taken from TextBook Author s Presentation

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Computer Systems Laboratory Sungkyunkwan University

Operating System Concepts Ch. 11: File System Implementation

Chapter 12: File System Implementation

File System Internals. Jo, Heeseung

Virtual Memory cont d.; File System Interface. 03/30/2007 CSCI 315 Operating Systems Design 1

CMSC421: Principles of Operating Systems

File-System Structure

There is a general need for long-term and shared data storage: Files meet these requirements The file manager or file system within the OS

Chapter 11: File System Interface Capítulo 10 no livro adotado!

Transcription:

V. File System SGG9: chapter 11 Files, directories, sharing FS layers, partitions, allocations, free space TDIU11: Operating Systems Ahmed Rezine, Linköping University Copyright Notice: The lecture notes are modifications of the slides accompanying the course book Operating System Concepts, 9 th edition, 2013 by Silberschatz, Galvin and Gagne.

File Concept Primary memory is volatile need secondary storage for long-term storage Assume: A disk is a linear sequence of numbered blocks With 2 operations: write block b, read block b Low level of abstraction, Portability across different storage devices Solution: OS provides the file abstraction Smallest piece of secondary storage known to the user Attributes (Name, id, size, ) Typically, contiguous logical address space Organized in a directory of files API (operations on files and directories)

File Attributes Name only information kept in human-readable form Identifier unique tag (number) identifies file within file system Type needed for systems that support different types Location pointer to file location on device Size current file size Protection controls who can do reading, writing, executing 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 Many variations, including extended file attributes such as file checksum

Basic File Operations File is an abstract data type. System calls for: Create: space must be found and an entry created in directory Write at write pointer location (system call with name and data, system searches for file in the directory) Read at read pointer location (system call with name and destination). Pointer kept as a per-process current position. Reposition within file file seek. Delete: release all file space and delete directory entry. Truncate: maintain all attributes except for length Instead of searching each time, keep information in a table Open(F i ) search the directory structure on disk for entry F i, and move the content of entry to memory Close (F i ) move the content of entry F i in memory to directory structure on disk

Open Files Several pieces of data are needed to manage open files: Open-file table: tracks open files (System wide and per process) File pointer: pointer to last read/write location, per process that has the file open File-open count: counter of number of times a file is open to allow removal of data from open-file table when last processes closes it Disk location of the file: cache of data access information Access rights: per-process access mode information

File descriptors and open file tables Process 1 Logical Address Space Process-local open file table KERNEL MEMORY SPACE stdin, stdout, stderr are opened upon process start 0 1 stdin (pos, ) stdout (pos, ) System-wide open file table FILE data structure {, fd, } 2 stderr (pos, ) Console input Console output Disk d newfile(pos, ) fp returned by fopen() library call newfile (loc., ) FCB contents FCB Process 2 Logical Address Space 0 1 2 Process-local open file table stdin (pos, ) stdout (pos, ) stderr (pos, ) File data open() syscall returns a file descriptor = index in local open file table

Open File Locking Provided by some operating systems and file systems Similar to reader-writer locks Shared lock similar to reader lock several processes can acquire concurrently Exclusive lock similar to writer lock Mediates access to a file Mandatory or advisory: Mandatory access is denied depending on locks held and requested (usually adopted by windows) Advisory processes can find status of locks and decide what to do (usually adopted by unix)

Access Methods Sequential Access (tape model) read next write next reset Sometimes forward/backward n records. Direct/relative Access (disk model). File made up of fixed length logical records. read n write n position to n read next write next rewrite n n = relative block number

Disk Structure Disk can be subdivided into partitions. Disk or partition can be used raw without a file system, or formatted with a file system Entity containing file system known as a volume Each volume containing file system also tracks that file system s info in device directory or volume table of contents: names, location, size and type for all files As well as general-purpose file systems there are many special-purpose file systems, frequently all within the same operating system or computer

Operations Performed on Directory Directory could be viewed as a table from file names to their entries. Search for a file, or for all files matching a pattern Create and add a file Delete a file List all files, and their entries, in a directory Rename a file Traverse the file system

Tree-Structured Directories Efficient searching Grouping Capability Current directory (working directory) cd /spell/mail/prog

Acyclic-Graph Directories Two different names (aliasing) If dict deletes count: dangling pointer Solutions: Backpointers, so we can delete all pointers Variable size records a problem Backpointers using a daisy chain organization Entry-hold-count solution New directory entry type Link another name (pointer) to an existing file Resolve the link follow pointer to locate the file

General Graph Directory Efficiency and correctness problems Garbage collection How do we guarantee no cycles? Allow only links to file not subdirectories Every time a new link is added use a cycle detection algorithm to determine whether it is OK

File System Mounting A file system must be mounted before it can be accessed An unmounted file system in a volume is mounted at a mount point before it can be traversed. / users bill fred sue jane help prog doc (a) (b)

File Sharing Sharing of files on multi-user systems is desirable Sharing may be done through a protection scheme On distributed systems, files may be shared across a network Network File System (NFS) is a common distributed file-sharing method If multi-user system User IDs identify users, allowing permissions and protections to be per-user Group IDs allow users to be in groups, permitting group access rights Owner of a file / directory Group of a file / directory

Protection File owner/creator should be able to control: what can be done by whom Types of access Read Write Execute Append Delete List

Access Lists and Groups Mode of access: read, write, execute Three classes of users on Unix / Linux R W X a) owner access 7 Þ 1 1 1 b) group access 6 Þ 1 1 0 c) public access 1 Þ 0 0 1 Ask manager to create a group (unique name), say G, and add some users to the group. For a particular file (say game) or subdirectory, define an appropriate access. Attach a group to a file: chgrp G game

File-System Structure File system (FS) resides on secondary storage (disks): interface and implementation File system organized into layers Logical file system Directory management. Translates file name into file number, file handle, location, protection, etc. Maintains File control blocks (FCBs) or inodes in UNIX. Storage structure consisting of information about a file.

File System Layers File organization module understands files, logical addresses, and physical blocks. Translates logical block # to physical block #. Manages free space, disk allocation Basic file system issues generic commands to the appropriate device driver. Manages memory buffers and caches (allocation, freeing, replacement) Device drivers manage I/O devices at the I/O control layer. Given retrieve block 123, outputs low-level commands to hardware controller Disk provides in-place rewrite and random access. I/O transfers performed in blocks of sectors (usually 512 bytes) Layering useful for reducing complexity and redundancy (e.g. several FSs), but adds overhead and can decrease performance.

File-System Implementation We have system calls at the API level, but how do we implement their functions? On-disk and in-memory structures, example: Boot control block: info needed by system to boot OS from a volume Needed if volume contains OS, usually first block of volume Volume control block (superblock, master file table) contains volume details Total # of blocks, # of free blocks, block size, free block pointers or array Directory structure organizes the files for each file system Names and their inode numbers Per file file control block (FCB) with a unique identifier and many details about the file.

In-Memory File System Structures In memory for FS management and performance. Data loaded at mount time: Mount table storing file system mounts, mount points, file system types Copy of the directory structure of recently accessed directories System-wide open-file table: copy of FCB of open files Buffers hold FS blocks when read/written to disk

Partitions and Mounting Partition can be a volume containing a file system ( cooked ) or raw just a sequence of blocks with no file system Boot block can point to boot volume or boot loader set of blocks that contain enough code to know how to load the kernel from the file system. System does not know FS code yet. Root partition contains the OS, other partitions can hold other Oses, other file systems, or be raw Mounted at boot time Other partitions can mount automatically or manually At mount time, file system reads device directory and consistency is checked

Directory Implementation Linear list of file names with pointer to the data blocks Simple to program Time-consuming to execute Linear search time Could keep ordered alphabetically via linked list or use B+ tree Hash Table linear list with hash data structure Decreases directory search time Collisions situations where two file names hash to the same location Only good if entries are fixed size, or use chainedoverflow method

Allocation Methods- Contiguous An allocation method refers to how disk blocks are allocated for files: Contiguous, linked and indexed. Contiguous allocation each file occupies set of contiguous blocks Best performance in most cases Simple only starting location (block #) and length (number of blocks) are required Supports both sequential and direct access Problems include finding space for file, knowing file size beforehand, external fragmentation, need for compaction off-line (downtime) or on-line Many file systems (i.e., Veritas File System) use extents. An extent is a contiguous block of disks.

Allocation Methods - Linked Linked allocation each file a linked list of blocks. No external fragmentation. No need for compaction. Each block contains pointer to next block Reliability can be a problem Locating a block can take many I/Os and disk seeks Improve efficiency by clustering blocks into groups but increases internal fragmentation

Allocation Methods - Linked FAT (File Allocation Table) variation Beginning of volume has table, indexed by block number Much like a linked list, but faster on disk and cacheable New block allocation simple

Allocation Methods - Indexed Indexed allocation Each file has its own index block(s) of pointers to its data blocks. Similar to the paging scheme. Supports direct access without external fragmentation. More overhead than linked allocation pointers. Index blocks can be cached, but blocks can be spread all over a volume index table

Indexed Allocation (Cont.) A block of 512 bytes can store 128 four-bytes pointers for a maximum file size of 128 x 512 bytes= 64 KB. Files can be larger. Mapping from logical to physical in a file of unbounded length Linked scheme Link blocks of index table (no limit on size). Keep last word to point to next index block. Two-level index (4K blocks could store 1,024 four-byte pointers in outer index -> 1,048,567 data blocks and file size of up to 4GB) Combined scheme (Unix based file systems): say 12 (direct),1 (single indirect),1 (double indirect),1 (triple indirect)

Performance Best method depends on file access type Contiguous great for sequential and random Linked good for sequential, not random Some systems require to declare access type at creation -> select either contiguous for direct (but require max length) or linked for sequential Indexed more complex Single block access could require 2 index block reads then data block read Clustering can help improve throughput, reduce CPU overhead

Free-Space Management File system maintains free-space list to track available blocks/clusters Bit vector or bit map (n blocks): CPUs have instructions to return offset within word of first 1 bit Bit map requires extra space: block size = 4KB = 2 12 bytes 0 1 2 n-1 disk size = 2 40 bytes (1 terabyte) n = 2 40 /2 12 = 2 28 bits (or 32MB)!"# bit[i] = 1 Þ block[i] free 0 Þ block[i] occupied if clusters of 4 blocks -> 8MB of memory Easy to get contiguous files

Linked Free Space List on Disk Linked list (free list): Cannot get contiguous space easily No waste of space No need to traverse the entire list (if # free blocks recorded like in FAT) Grouping: Modify linked list to store address of next n-1 free blocks in first free block, plus a pointer to next block that contains free-block-pointers (like this one) Counting: Keep address of first free block and count of following free blocks. Free space list then has entries containing addresses and counts

Efficiency and Performance Efficiency dependent on: Disk allocation and directory algorithms Types of data kept in file s directory entry: e.g., last access Pre-allocation (Unix inodes) or as-needed metadata allocation Varying-size data structures: e.g., clusters of varying sizes Performance: Keeping data and metadata close together to reduce seek time Buffer cache in main memory for frequently used blocks Synchronous writes sometimes requested by apps or needed by OS No buffering / caching writes must hit disk before acknowledgement Asynchronous writes more common, buffer-able, faster Free-behind and read-ahead techniques to optimize sequential access Reads frequently slower than writes

Recovery Consistency checking compares data in directory structure with data blocks on disk, and tries to fix inconsistencies Can be slow and sometimes fails Use system programs to back up data from disk to another storage device (magnetic tape, other magnetic disk, optical) Recover lost file or disk by restoring data from backup

Log Structured File Systems Log structured (or journaling) file systems record each metadata update to the file system as a transaction All transactions are written to a log A transaction is considered committed once it is written to the log (sequentially) Sometimes to a separate device or section of disk However, the file system may not yet be updated The transactions in the log are asynchronously written to the file system structures When the file system structures are modified, the transaction is removed from the log If the file system crashes, all remaining transactions in the log must still be performed Faster recovery from crash, removes chance of inconsistency of metadata

Single-Level Directory A single directory for all users Naming problem: we cannot use the same name for two different files. Consider several users with their test1.c files. Grouping problem: flat organization, e.g., cannot group all first assignment files together.

Two-Level Directory Separate directory for each user Path name Can have the same file name for different user Efficient searching Can use configurable search paths No grouping capability

Virtual File Systems Virtual File Systems (VFS) on Unix provide an object-oriented way of implementing file systems VFS allows the same system call interface (the API) to be used for different types of file systems Separates file-system generic operations from implementation details Implementation can be one of many file systems types, or network file system Implements vnodes which hold inodes or network file details Then dispatches operation to appropriate file system implementation routines

Free-Space Management (Cont.) Space Maps Used in ZFS (Solaris, BSD, Linux) Consider meta-data I/O on very large file systems Full data structures like bit maps couldn t fit in memory -> thousands of I/Os Divides device space into metaslab units and manages metaslabs Given volume can contain hundreds of metaslabs Each metaslab has associated space map Uses counting algorithm But records to log file rather than file system Space Map is a log of all block activity, in time order, in counting format Metaslab activity -> load space map into memory in balanced-tree structure, indexed by offset Replay log into that structure Combine contiguous free blocks into single entry

Disk Management Low-level formatting, or physical formatting Dividing a disk into sectors that the disk controller can read and write Each sector can hold header information, plus data, plus error correction code (ECC) Usually 512 bytes of data but can be selectable To use a disk to hold files, the operating system still needs to record its own data structures on the disk Partition the disk into one or more groups of cylinders, each treated as a logical disk Logical formatting or making a file system To increase efficiency most file systems group blocks into clusters Disk I/O done in blocks File I/O done in clusters

Disk Management (Cont.) Raw disk access for apps that want to do their own block management, keep OS out of the way (databases for example) Boot block initializes system The bootstrap is stored in ROM Bootstrap loader program stored in boot blocks of boot partition Methods such as sector sparing used to handle bad blocks

Swap-Space Management Swap-space Virtual memory uses disk space as an extension of main memory Less common now due to memory capacity increases Swap-space can be carved out of the normal file system, or, more commonly, it can be in a separate disk partition (raw) Swap-space management BSD allocates swap space when process starts; holds text segment (the program) and data segment Kernel uses swap maps to track swap-space use Solaris 2 allocates swap space only when a swap dirty area page is forced out of physical memory page slot What if a system runs out of swap space? swap partition Some systems allow multiple or swap file swap spaces swap map 1 0 3 0 1