Chapter 06

You might also like

You are on page 1of 59

Chapter 6

File Systems

6.1 Files
6.2 Directories
6.3 File system implementation
6.4 Example file systems

1
Long-term Information Storage

1. Must store large amounts of data

2. Information stored must survive the


termination of the process using it

3. Multiple processes must be able to access


the information concurrently

2
File Naming

Typical file extensions.


3
File Structure

• Three kinds of files


– byte sequence
– record sequence
– tree
4
File Types

(a) An executable file (b) An archive 5


File Access
• Sequential access
– read all bytes/records from the beginning
– cannot jump around, could rewind or back up
– convenient when medium was mag tape
• Random access
– bytes/records read in any order
– essential for data base systems
– read can be …
• move file marker (seek), then read or …
• read and then move file marker

6
File Attributes

Possible file attributes 7


File Operations

1. Create 7. Append
2. Delete 8. Seek
3. Open 9. Get attributes
4. Close 10.Set Attributes
5. Read 11.Rename
6. Write

8
An Example Program Using File System Calls (1/2)

9
An Example Program Using File System Calls (2/2)

10
Memory-Mapped Files

(a) Segmented process before mapping files


into its address space
(b) Process after mapping
existing file abc into one segment
creating new segment for xyz
11
Directories
Single-Level Directory Systems

• A single level directory system


– contains 4 files
– owned by 3 different people, A, B, and C

12
Two-level Directory Systems

Letters indicate owners of the directories and files

13
Hierarchical Directory Systems

A hierarchical directory system


14
Path Names

A UNIX directory tree


15
Directory Operations

1. Create 5. Readdir
2. Delete 6. Rename
3. Opendir 7. Link
4. Closedir 8. Unlink

16
File System Implementation

A possible file system layout

17
Implementing Files (1)

(a) Contiguous allocation of disk space for 7 files


(b) State of the disk after files D and E have been removed
18
Implementing Files (2)

Storing a file as a linked list of disk blocks

19
Implementing Files (3)

Linked list allocation using a file allocation table in RAM


20
Implementing Files (4)

An example i-node
21
Implementing Directories (1)

(a) A simple directory


fixed size entries
disk addresses and attributes in directory entry
(b) Directory in which each entry just refers to an i-node
22
Implementing Directories (2)

• Two ways of handling long file names in directory


– (a) In-line
– (b) In a heap 23
Shared Files (1)

File system containing a shared file


24
Shared Files (2)

(a) Situation prior to linking


(b) After the link is created
(c)After the original owner removes the file
25
Disk Space Management (1)

Block size

• Dark line (left hand scale) gives data rate of a disk


• Dotted line (right hand scale) gives disk space efficiency
• All files 2KB
26
Disk Space Management (2)

(a) Storing the free list on a linked list


(b) A bit map
27
Disk Space Management (3)

(a) Almost-full block of pointers to free disk blocks in RAM


- three blocks of pointers on disk
(b) Result of freeing a 3-block file
(c) Alternative strategy for handling 3 free blocks
- shaded entries are pointers to free disk blocks
28
Disk Space Management (4)

Quotas for keeping track of each user’s disk use


29
File System Reliability (1)

File that has


not changed

• A file system to be dumped


– squares are directories, circles are files
– shaded items, modified since last dump
– each directory & file labeled by i-node number 30
File System Reliability (2)

Bit maps used by the logical dumping algorithm


31
File System Reliability (3)

• File system states


(a) consistent
(b) missing block
(c) duplicate block in free list
(d) duplicate data block
32
File System Performance (1)

The block cache data structures

33
File System Performance (2)

• I-nodes placed at the start of the disk


• Disk divided into cylinder groups
– each with its own blocks and i-nodes
34
Disk Scheduling
• The operating system is responsible for using hardware
efficiently — for the disk drives, this means having a fast
access time and disk bandwidth.
• Access time has two major components
– Seek time is the time for the disk are to move the
heads to the cylinder containing the desired sector.
– Rotational latency is the additional time waiting for
the disk to rotate the desired sector to the disk head.
• Minimize seek time
• Seek time  seek distance
• Disk bandwidth is the total number of bytes transferred,
divided by the total time between the first request for
service and the completion of the last transfer.
35
Disk Scheduling (Cont.)
• Several algorithms exist to schedule the
servicing of disk I/O requests.
• We illustrate them with a request queue (0-
199).

98, 183, 37, 122, 14, 124, 65, 67

Head pointer 53

36
FCFS
llustration shows total head movement of 640 cylinders.

37
SSTF
• Selects the request with the minimum seek
time from the current head position.
• SSTF scheduling is a form of SJF
scheduling; may cause starvation of some
requests.
• Illustration shows total head movement of
236 cylinders.

38
SSTF (Cont.)

39
SCAN/Elevator
• The disk arm starts at one end of the disk,
and moves toward the other end, servicing
requests until it gets to the other end of the
disk, where the head movement is reversed
and servicing continues.
• Sometimes called the elevator algorithm.
• Illustration shows total head movement of
208 cylinders.

40
SCAN/Elevator (Cont.)

41
LOOK/Elevator

• Version of SCAN
• Arm only goes as far as the last request in
each direction, then reverses direction
immediately, without first going all the way
to the end of the disk.

42
C-SCAN

• Provides a more uniform wait time than SCAN.


• The head moves from one end of the disk to the
other. servicing requests as it goes. When it
reaches the other end, however, it immediately
returns to the beginning of the disk, without
servicing any requests on the return trip.
• Treats the cylinders as a circular list that wraps
around from the last cylinder to the first one.

43
C-SCAN (Cont.)

44
C-LOOK

• Version of C-SCAN
• Arm only goes as far as the last request in
each direction, then reverses direction
immediately, without first going all the way
to the end of the disk.

45
C-LOOK (Cont.)

46
Selecting a Disk-Scheduling Algorithm
• SSTF is common and has a natural appeal
• SCAN and C-SCAN perform better for systems that place
a heavy load on the disk.
• Performance depends on the number and types of
requests.
• Requests for disk service can be influenced by the file-
allocation method.
• The disk-scheduling algorithm should be written as a
separate module of the operating system, allowing it to be
replaced with a different algorithm if necessary.
• Either SSTF or LOOK/Elevator is a reasonable choice for
the default algorithm.
47
Log-Structured File Systems
• With CPUs faster, memory larger
– disk caches can also be larger
– increasing number of read requests can come from cache
– thus, most disk accesses will be writes

• LFS Strategy structures entire disk as a log


– have all writes initially buffered in memory
– periodically write these to the end of the disk log
– when file opened, locate i-node, then find blocks

48
Example File Systems
CD-ROM File Systems

The ISO 9660 directory entry

49
The CP/M File System (1)

BIOS had 17 I/O calls, OS in 3584 bytes, Shell in 2K, Zero page for h/w
interrupt handling

Memory layout of CP/M


50
The CP/M File System (2)

The CP/M directory entry format

51
The MS-DOS File System (1)

The MS-DOS directory entry

52
The MS-DOS File System (2)

• Maximum partition for different block sizes


• The empty boxes represent forbidden combinations
53
The Windows 98 File System (1)

Bytes

The extended MOS-DOS directory entry used in Windows


98
54
The Windows 98 File System (2)

Bytes

Checksum

An entry for (part of) a long file name in Windows 98

55
The Windows 98 File System (3)

An example of how a long name is stored in Windows 98

56
The UNIX V7 File System (1)

A UNIX V7 directory entry

57
The UNIX V7 File System (2)

A UNIX i-node
58
The UNIX V7 File System (3)

The steps in looking up /usr/ast/mbox


59

You might also like