Lecture 17 File Systems

advertisement
Lecture 17
File Systems
Outline
•
•
•
•
•
•
•
Devices
Disks and Partitions
File Systems
i-nodes
Virtual File System
Journaling
Mounting
1
July 24, 2016
Device Special File
• Corresponds to device on system
• Located in /dev
• Some are real, e.g.,
• Mouse
• Keyboard
• Disk
• Others are virtual
• No actual hardware
• Kernel provides abstract device
2
July 24, 2016
Device Driver
• Kernel code that implements operations specific to hardware
• API is fixed, e.g.,
•
•
•
•
•
open()
close()
read()
write()
etc.
• Allows universality of I/O
3
July 24, 2016
Types of Devices
• Character devices- handles data character by character, e.g.,
• Terminal
• Keyboard
• Block devices- handles data a block at a time, e.g., disk
• Size depends on device, typically 512 bytes (or multiple thereof)
4
July 24, 2016
udev Program
• Relies on sysfs file system
• Exports information about devices into user space
• Uses a pseudo file system mounted under /sys
• E.g., when plug in usb flash driver...
5
July 24, 2016
Device ID
• Major ID
• Identifies general class of device
• Used by kernel to locate driver
• Minor ID
• Identifies a particular device within general class
• Can be displayed with ls –l command
• Device IDs recorded in i-node of device file
6
July 24, 2016
Outline
•
•
•
•
•
•
•
Devices
Disks and Partitions
File Systems
i-nodes
Virtual File System
Journaling
Mounting
7
July 24, 2016
Disks and Partitions
• Regular files and directories usually reside on hard disk devices
• Can also exist on CD-ROMS, flash drivers, virtual disks
8
July 24, 2016
Disk Drives
•
•
•
•
Hard disk is a mechanical device
Information stored on set of concentric circles called tracks
Tracks divided into sectors
Sectors contain series of physical blocks
• Typically 512 bytes in size (or multiples thereof)
9
July 24, 2016
Disk Drives
•
•
•
•
Disk access is SLOW (on order of milliseconds)
Seek time- move to appropriate track
Rotation latency- wait until sector moves under disk head
Transfer time- transfer bytes
10
July 24, 2016
Partitions
• Disk divided into one (or more) non-overlapping partitions
• Each partition treated as separate device /dev
• Usually contain:
• file system- hold regular files and directories
• data area- accessed as a raw-mode device
• swap area- used by kernel for memory management
11
July 24, 2016
Outline
•
•
•
•
•
•
•
Devices
Disks and Partitions
File Systems
i-nodes
Virtual File System
Journaling
Mounting
12
July 24, 2016
File Systems
• Organized collection of regular files and directories
• mkfs command makes a file system
• Linux supports variety of file systems:
•
•
•
•
•
•
•
ext2
minix, system V, BSD (native UNIX)
FAT, FAT32, NTFS (Microsoft)
HFS (Apple)
NFS (network file systems)
ext3, ext4, JFS, XFS (journaling file systems)
...
13
July 24, 2016
ext2 File System
• Second Extended File System
• Use has declined in favor of journaling file systems
• 5000+ lines of C
• Used to explain file system concepts
14
July 24, 2016
Logical Block
• Basic unit for allocating file system space
• Multiple contiguous physical block on disk device
• ext2 logical block size is 1024, 2048, or 4096 bytes
15
July 24, 2016
File System Structure
• File system contains following parts:
•
•
•
•
Boot block
Superblock
i-node table
Data blocks
16
July 24, 2016
File System Boot Block
• ALWAYS first block in file system
• Not used by file system
• Contains info used to boot operating system
17
July 24, 2016
File System Superblock
• Single block, immediately following boot block
• Contains parameter info about file system
• Size of i-node table
• Size of logical blocks
• Size of file system
18
July 24, 2016
File System i-node Table
• Each file / dir in file system has unique entry in i-node table
• Entry records various information about file
• Also known as i-list
19
July 24, 2016
File System Data Blocks
• Majority of space in file system
• Form files and directories of files system
• (Where actual bytes reside on disk)
20
July 24, 2016
Outline
•
•
•
•
•
•
•
Devices
Disks and Partitions
File Systems
i-nodes
Virtual File System
Journaling
Mounting
21
July 24, 2016
i-nodes
• i-node stands for index node
• Each row of i-node table contains one i-node
• One i-node for each file in file system
• Identified sequentially (numerically) by location in i-node table
• “i-node number”
• UNIX> ls –li
22
July 24, 2016
Information Maintained by i-node
•
•
•
•
•
•
•
•
File type
Owner
Group
Access permissions
Timestamps: modified, access, status change
Number of hard links to file
Number of blocks allocated to file
Pointers to data blocks of file
23
July 24, 2016
Files and Data Blocks
• ext2 file system does NOT store data blocks in sequential order
• Does try to store data blocks “close together”
• Kernel maintains set of pointers in i-node to locate data blocks
• Reduces risk of disk fragmentation
24
July 24, 2016
i-node Data Block Pointers
• Each i-node contains 15
pointers
• Pointers 0-11: first 12 data
blocks of file
• Pointer 12: pointer to block
of pointers (single indirect)
• Pointer 13: double indirect
pointer
• Pointer 14: triple indirect
pointer
25
July 24, 2016
i-node Data Block Pointers
26
July 24, 2016
i-node Data Block Pointers
• Why such a complex system of pointers to pointers to
pointers...?
• Allows i-node structure to be fixed size (always 15 pointers)
• Allows file system to store files non-contiguously
• Allows any size file
27
July 24, 2016
Outline
•
•
•
•
•
•
•
Devices
Disks and Partitions
File Systems
i-nodes
Virtual File System
Journaling
Mounting
28
July 24, 2016
Virtual File System (VFS)
• File systems (e.g., ext2, FAT) have different implementations
• Kernel provides abstraction (VFS)
• Provides generic interface for file system operations
• Programs only need to understand VFS (e.g., open(), close(), etc.)
• Each file system implements VFS interface
29
July 24, 2016
Outline
•
•
•
•
•
•
•
Devices
Disks and Partitions
File Systems
i-nodes
Virtual File System
Journaling
Mounting
30
July 24, 2016
Journaling File Systems
• ext2 file system is “traditional”
• Suffers classic limitation: after system crash, file system consistency check
(fsck) must be performed to insure integrity
• At time of crash, file update may have been only partially completed
• Consistency check must examine entire file system!! (slow)
31
July 24, 2016
Journaling File Systems
• Journaling eliminates need for consistency check after crash
• Journaling logs metadata to special on-disk journal before file
operations are carried out
• If system crashes, log used to rapidly redo incomplete updates
• E.g., ext3
32
July 24, 2016
Outline
•
•
•
•
•
•
•
Devices
Disks and Partitions
File Systems
i-nodes
Virtual File System
Journaling
Mounting
33
July 24, 2016
Single Directory Hierarchy and Mount Points
• ALL files from file systems reside under single directory tree
• Base of tree is root directory ( ‘/‘ )
• Other file systems mounted under root directory and appear
as subtrees within overall hierarchy
34
July 24, 2016
Single Directory Hierarchy and Mount Points
35
July 24, 2016
Mount
• To mount a device:
UNIX> sudo mount device directory
• Attach device into directory hierarchy at specified directory
• directory known as device’s mount point
• Use umount command to detach device
36
July 24, 2016
Mount
UNIX> mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
...
• List file systems currently attached (e.g., on my Mac)
37
July 24, 2016
/proc/mounts
• Look up info about mounted devices
• Interface of kernel data structures
• Example line from /proc/mounts
/dev/sda9
/boot ext3
rw
0
0
mount point
file system type
name of
mounted device
38
July 24, 2016
always 0
(unused in
/proc/mounts)
mount flags
(e.g., read, write)
Download