File-System Structure

37
Silberschatz, Galvin and Gagne 2002 12.1 Operating System Concepts File-System Structure File structure user view Logical storage unit Collection of related information File system physical view Resides on secondary storage (disks) Partitions and mounting Blocks

description

File-System Structure. File structure user view Logical storage unit Collection of related information File system physical view Resides on secondary storage (disks) Partitions and mounting Blocks. Moving-Head Disk Mechanism. Low Level Format. - PowerPoint PPT Presentation

Transcript of File-System Structure

Page 1: File-System Structure

Silberschatz, Galvin and Gagne 200212.1Operating System Concepts

File-System Structure

File structure user view Logical storage unit Collection of related information

File system physical view Resides on secondary storage (disks) Partitions and mounting Blocks

Page 2: File-System Structure

Silberschatz, Galvin and Gagne 200212.2Operating System Concepts

Moving-Head Disk Mechanism

Page 3: File-System Structure

Silberschatz, Galvin and Gagne 200212.3Operating System Concepts

Low Level Format

Low-level formatting, or physical formatting — Dividing a disk into sectors that the disk controller can read and write. Zones of cylinders allow more (up to 40%) sectors on outer

tracks

The sectors and tracks are mapped to a large 1-dimensional array of logical blocks, Block 0 is the first sector of the first track on the outermost

or innermost cylinder. Mapping proceeds in order through that track, then the rest

of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost.

The block is the smallest unit of transfer.

Page 4: File-System Structure

Silberschatz, Galvin and Gagne 200212.4Operating System Concepts

Blocks and Fragments

Block sizes Smaller => less internal fragmentation Larger => larger transfers

Can improve efficiency by varying file-system parameters, e.g., block size = frame size on swap device

4.2BSD uses two block sized for files which have no indirect blocks: All the blocks of a file are of a large block size (such as 8K),

except the last. The last block is an appropriate multiple of a smaller

fragment size (e.g., 1024) to fill out the file. Thus, a file of size 18,000 bytes would have two 8K blocks

and one 2K fragment (which would not be filled completely).

Page 5: File-System Structure

Silberschatz, Galvin and Gagne 200212.5Operating System Concepts

High Level Format

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.

Logical formatting or “making a file system”.

Page 6: File-System Structure

Silberschatz, Galvin and Gagne 200212.6Operating System Concepts

Partitions and Disks

A physical device may support several partitions, each hosting a physical file system.

Page 7: File-System Structure

Silberschatz, Galvin and Gagne 200212.7Operating System Concepts

Partitions and Disks

Different file systems can support different uses. Potentially different OSs in different partitions

Prevents one program from using all available space for a large file. Speeds up searches on backup tapes and restoring partitions from

tape.

Known as IBM minidisks Mac volumes UNIX file systems Windows drives

Page 8: File-System Structure

Silberschatz, Galvin and Gagne 200212.8Operating System Concepts

Partitions

Boot block - for booting the OS Partition control block

Information about the partition Free space list Free directory space list Superblock in UNIX, Master File Table in NTFS

Directory structure Directory nodes, exactly one per file

Inodes in UNIX MFT entries in NTFS

Organization links nodes into a data structure Provides naming

Data blocks

Page 9: File-System Structure

Silberschatz, Galvin and Gagne 200212.9Operating System Concepts

Directory Implementation

Linear list of file names with pointer to the data blocks. Simple to program Inefficient - searching, empty entries UNIX directory files

Sorted tree, e.g., B-tree NTFS 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 Fixed size, or overflow facilities

Page 10: File-System Structure

Silberschatz, Galvin and Gagne 200212.10Operating System Concepts

Disk Structures

A logical file system that a user ordinarily sees may consist of several physical file systems, each hosted in a partition of a physical device. Permits very large logical file systems Makes monolithic backups possible

The root file system is always available on a partition. Other file systems may be mounted — i.e., integrated into

the directory hierarchy of the root file system. A file system must be mounted before it can be accessed. A unmounted file system mounted at a mount point.

Page 11: File-System Structure

Silberschatz, Galvin and Gagne 200212.11Operating System Concepts

Mapping File System to Physical Devices

Page 12: File-System Structure

Silberschatz, Galvin and Gagne 200212.12Operating System Concepts

Layered File System

Applications call the LFS via system calls LFS deals with file names, file and

directory operations, file tables, security FOM maps logical to physical, buffers,

tracks free blocks, tracks bad blocks BFS sends commands to DDs to access

specified blocks on the device I/O control consists of device drivers and

interrupts handlers for each device.

Page 13: File-System Structure

Silberschatz, Galvin and Gagne 200212.13Operating System Concepts

File Tables

Draw my example To open a file

System wide file table is search to see if already open If no, the directory structure is searched (cached if possible)

Node copied to system wide file table A new entry in the per-process file table

Refers to the existing SW file table entry Contains mode of access, and offset

Counter incremented in the SW file table To close a file

Per-process file table entry is removed Count decremented in SW file table, and if 0 the node is

written to disk To create a file

LFS allocates a new directory node Reads in, updates, and writes out the directory

Page 14: File-System Structure

Silberschatz, Galvin and Gagne 200212.14Operating System Concepts

Contiguous Allocation

Each file occupies a set of contiguous blocks on the disk E.g., IBM, VMS

Page 15: File-System Structure

Silberschatz, Galvin and Gagne 200212.15Operating System Concepts

Contiguous Allocation

Random access Block = LA / BlockSize Offset = LA % BlockSize Simple – only starting location (block #) and length

(number of blocks) are required in a directory node Wasteful of space

Dynamic storage-allocation problem External fragmentation

Files cannot grow easily Initial allocation?

Page 16: File-System Structure

Silberschatz, Galvin and Gagne 200212.16Operating System Concepts

Linked Allocation

Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk.

Block is a pointer (disk address) and data

pointerblock =

Page 17: File-System Structure

Silberschatz, Galvin and Gagne 200212.17Operating System Concepts

Linked Allocation (Cont.)

Random access

Block in chain = LA / (BlockSize - LinkSize)

Offset = LA % (BlockSize - LinkSize) Simple – need only starting address Free-space management system – no waste of space

New file has NULL pointer in directory Easy to get another or release a block

Slow random access

Page 18: File-System Structure

Silberschatz, Galvin and Gagne 200212.18Operating System Concepts

Linked Allocation (Cont.)

FAT variation Table with index corresponding to blocks Linked table entries - cached for fast traversal Used by DOS and OS/2

Page 19: File-System Structure

Silberschatz, Galvin and Gagne 200212.19Operating System Concepts

Extent-Based Systems

Many newer file systems (e.g., Veritas File System) use a modified contiguous allocation scheme.

Extent-based file systems allocate disk blocks in extents. An extent is a contiguous block of disks. Extents are

allocated for file allocation. A file consists of one or more extents.

Extents are linked together Extents reduce LinkSize overhead

E.g., NTFS

Page 20: File-System Structure

Silberschatz, Galvin and Gagne 200212.20Operating System Concepts

Indexed Allocation

Brings all pointers together into the index block.

index table

Page 21: File-System Structure

Silberschatz, Galvin and Gagne 200212.21Operating System Concepts

Indexed Allocation (Cont.)

Random access

Index table entry = LA / BlockSize

Offset = LA % BlockSize Fast random access

Cached for speed Need index block

Small files have mostly empty index block Fixed maximal file size

Page 22: File-System Structure

Silberschatz, Galvin and Gagne 200212.22Operating System Concepts

Linked - Indexed Allocation

Linked scheme – Link blocks of index table Random access

Index block in chain =

LA / (((BlockSize-LinkSize)/LinkSize) * BlockSize)

LAInBlock = LA % (((BlockSize-LinkSize)/LinkSize) * BlockSize)

Index table entry = LAInBlock / BlockSize

Offset = LAInBlock % BlockSize

Page 23: File-System Structure

Silberschatz, Galvin and Gagne 200212.23Operating System Concepts

Two Level Indexed Allocation

outer-index

index table file

Page 24: File-System Structure

Silberschatz, Galvin and Gagne 200212.24Operating System Concepts

Two Level Indexed Allocation

Random access

Outer index table entry = LA / (BlockSize2/LinkSize)

LAInBlock = LA % (BlockSize2/LinkSize)

Inner index table entry = LAInBlock / BlockSize

Offset = LAInBlock % BlockSize Fixed, but large maximal size Fast random access if cached

Page 25: File-System Structure

Silberschatz, Galvin and Gagne 200212.25Operating System Concepts

Combined Scheme: UNIX (4K bytes per block)

Fast for small files Gradual degradation as file size increases

Page 26: File-System Structure

Silberschatz, Galvin and Gagne 200212.26Operating System Concepts

Free-Space Management

Linked list (free list) Cannot get contiguous

space easily No waste of space Can use same routines as

for file management

Page 27: File-System Structure

Silberschatz, Galvin and Gagne 200212.27Operating System Concepts

Free-Space Management

Bit vector (n blocks) (e.g., Mac)

0 1 2 n-1

bit[i] = 1 block[i] free

0 block[i] occupied

Can use Motorola “find bit” instruction Easy to get contiguous blocks Needs to be kept in memory

block size = 212 bytes (4KB)

disk size = 236 bytes (64GB)

n = 236/212 = 224 bits = 221 bytes (2MB (!))

Page 28: File-System Structure

Silberschatz, Galvin and Gagne 200212.28Operating System Concepts

Efficiency and Performance

Efficiency dependent on: Disk allocation and directory algorithms Types of data kept in file’s directory entry

Performance Disk cache – separate section of main memory for

frequently used blocks Free-behind and read-ahead – techniques to optimize

cache performance for sequential access A page cache caches pages rather than disk blocks using

virtual memory techniques. Improve PC performance by dedicating section of memory

as virtual disk, or RAM disk.

Page 29: File-System Structure

Silberschatz, Galvin and Gagne 200212.29Operating System Concepts

Log Structured File Systems

Log structured (or journaling) file systems record each 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. However, the file system may not yet be updated.

The transactions in the log are asynchronously written to the file system. When the file system is modified, the transaction is removed from the log.

If the file system crashes, all remaining transactions in the log must still be performed.

Page 30: File-System Structure

Silberschatz, Galvin and Gagne 200212.30Operating System Concepts

UNIX File Systems

Size of a block is given in sys/param.h as BSIZE, and is typically 512 or 1024 bytes.

The area of disc set aside for a file system is split into 4 regions: Block 0 is set aside for a bootstrap program if required Block 1 contains the superblock which describes the file

system as a whole, including free blocks and inodes lists. Block 2 starts the inode area (fixed size) Remaining blocks are allocated to files

The UNIX file system supports two main objects: files and directories. Directories are just files with a special format, so the

representation of a file is the basic UNIX concept.

Page 31: File-System Structure

Silberschatz, Galvin and Gagne 200212.31Operating System Concepts

Inodes

A file (could be a directory) is represented by an inode — a record that stores information about a specific file on the disk. Type of file

Plain Directory FIFO Special, …

Access permissions. Number of links to this inode User and group IDs of the file owner. Size of file in bytes for files, device number for devices. Times of creation, last access, and last modification Addresses of the files data blocks.

Inodes are numbered from 1 Inode 1 is reserved for the bad blocks list Inode 2 for the root directory of the file system.

Page 32: File-System Structure

Silberschatz, Galvin and Gagne 200212.32Operating System Concepts

Directories

The inode type field distinguishes between plain files and directories.

Directory entries are of variable length, with fields: The length of the entry The file name The inode number.

Page 33: File-System Structure

Silberschatz, Galvin and Gagne 200212.33Operating System Concepts

Finding Inodes

The OS has to map the supplied user path name to an inode If the first character is “/”, the starting directory is the root

directory. For any other starting character, the starting directory is the

current directory. The search process continues until the end of the path

name is reached and the desired inode is returned. 4.3BSD improved file system performance by adding a

directory name cache to hold recent directory-to-inode translations.

Page 34: File-System Structure

Silberschatz, Galvin and Gagne 200212.34Operating System Concepts

File System Data Structures

UNIX maintains System inode table - inodes of files that are open + name +

counter System file table - offset, mode + counter Per process file table - not much

Tables are of fixed length

Page 35: File-System Structure

Silberschatz, Galvin and Gagne 200212.35Operating System Concepts

Files

To create a file Allocate new inode Write new entry in directory file

To open a file Search inode table If open, create system & process file table entries, increment counters If not open, read in inode and create table entries

To use a file, use the process file table entry To close a file

Delete process file table entry, decrement system file table counter If system file table counter is 0, delete and decrement inode table

counter If inode table counter is 0, write out inode and delete

To delete a file Delete directory entry Decrement link counter If link counter is 0, and inode not in inode table, delete inode

Page 36: File-System Structure

Silberschatz, Galvin and Gagne 200212.36Operating System Concepts

Schematic View of NFS Architecture

Page 37: File-System Structure

Silberschatz, Galvin and Gagne 200212.37Operating System Concepts

NFS Protocol

Provides a set of remote procedure calls for remote file operations. The procedures support the following operations:

searching for a file within a directory reading a set of directory entries manipulating links and directories accessing file attributes reading and writing files

NFS servers are stateless; each request has to provide a full set of arguments.

Modified data must be committed to the server’s disk before results are returned to the client (lose advantages of caching).

The NFS protocol does not provide concurrency-control mechanisms.