Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must...

38
Chapter 6 File Systems

description

File names

Transcript of Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must...

Page 1: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Chapter 6 File Systems

Page 2: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Essential requirements

1. Store very large amount of information2. Must survive the termination of processes

persistent

3. Concurrent access by multiple processes

Page 3: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File names

Page 4: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File name issues

Length Distinguish between upper and lower case Characters allowed

Page 5: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File structure types

(keyed)

Page 6: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File types

1. Regular files2. Directories (folders)3. Special

1. Character special (used for serial I/O: ports, printers, networks, etc.)

2. Block special (used for disks)

Page 7: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Regular files

ASCII or binary ASCII is easy to use

Record oriented (delimiter)? Binary is space efficient

Fixed or variable length

Page 8: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File access

1. Sequential2. Random

seek() and fseek() Binary

unbuffered: read(), write() Buffered: fread(), fwrite()

ASCII, buffered: fscanf(), fprintf()

Page 9: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File attributes

Page 10: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File operations

Create Delete Open Close Read Write

Append Seek Get attributes Set attributes Rename

Page 11: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Memory-mapped files

Mapping files into process virtual address space

Page 12: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Directories (folders)

1. Single level2. Two level3. Hierarchical

Page 13: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Two level directory systems

Page 14: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Hierarchical directory systems

Page 15: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Path names

We already described file names. How do we specify the “path” to a file i.e., how do

we navigate the directory structure? Path names:

1. Absolute c:\usr\ginger\mailbox\junk.cpp /usr/ginger/mailbox/junk.cpp

2. Relative (to the current working (default) directory)1. . = current directory: ./hw1/junk.cpp or hw1/junk.cpp2. .. = directory above current: ../music/mm.mp3

Page 16: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Directory operations

Create Delete Opendir Closedir

Readdir Rename Link Unlink

Same or similar so be careful!

Page 17: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File system implementation

Physical disks Divided into one or more “partitions” (logical, separate

disks). Each partition can have its own file system. Sector 0 = MBR (master boot record)

List of partitions (start and ends) Indicates boot partition Every partition has a boot block (although it may be empty) Boot steps:

1. boot code in MBR executes2. reads in boot block code of boot partition and executes it3. boot block code boots OS code in partition

Page 18: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File system layout

Page 19: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files

1. Contiguous allocation2. Linked list allocation3. Linked list allocation w/ table in memory4. I-nodes (index-nodes)

Page 20: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: contiguous allocationGiven 1KB blocks, a 50KB file would be allocated 50

consecutive blocks+ simple: all we need to know if the disk address of the

first block and the number of blocks (or length of the file)

+ fast: only 1 seek + one read needed for the entire file+ sequential and random access are efficient- fragmentation (holes or compaction)- Must specify the size of the file ahead of time. Excellent for CDs and DVDs.

Page 21: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: contiguous allocation

Page 22: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: linked list allocation

Page 23: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: linked list allocation+ no fragmentation- Sequential access is easy but requires

multiple seeks and reads.- Random access is slow (basically becomes

sequential access).

Page 24: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: linked list w/ table in memory FAT = file allocation table+ random access requires only sequential

memory access (which is fast)- Need memory to store the table.

20GB and 1KB blocks requires a table with 20M entries. (20M x 4 bytes-per-entry = 80MB)

Size of table is proportional to disk size.

Page 25: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: linked list w/ table in memory

Page 26: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: i-nodes

i-node table for a file need only be in memory when the file is open.

Size of table is proportional to number of files we allow to be open at any time.

Page 27: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing files: i-nodesfile

(disk)

Page 28: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Implementing directories (folders) We need to locate (the first block of) the file! We need to store file attributes (e.g., owner,

creation time, etc.).

i-nodes

Page 29: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Shared files (i.e., files in more than one directory)

Page 30: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Disk space management

Block size Page size? Sector, track, or cylinder size? What is the average size of a file? For Unix, 1KB is commonly used.

Keeping track of free blocks Linked list of free block numbers Bitmap

Disk quotas Limits on disk space usage by users.

Page 31: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File system reliability

Backups1. Full2. Incremental

Backups1. Physical dump2. Logical dump

Consistency When the system is not shut down properly.

Page 32: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

File system performance

Caching (FIFO, second chance, LRU, etc.). Block read ahead. Reducing disk arm motion.

Page 33: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Example file systems

MS-DOS/Windows3.1/Windows95 Windows98 Unix V7

Page 34: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

MS-DOS/Windows3.1/Windows95Attributes

1. Read-only2. Hidden3. System file4. Should be archived

Each entry is 32 bytes.

Page 35: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Windows98

Problem: We outgrew 8.3 file names (in 1988).

Page 36: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Windows98 & old MS-DOS file namesMS-DOS file name: “THEQUI~1.”

Long file name: “The quick brown fox jumps over the lazy dog.”

First byte is sequence number & Invalid attr’s 0x0f for all long file entries.

Page 37: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

Unix V7 file system

simple

Page 38: Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.

disk addr of file block 0disk addr of file block 9

disk addrs of file blocks 10-15

disk addrs of file blocks 16-51

disk addrs of file blocks 52…