chapter 5 input/output - folk.uio.nofolk.uio.no/inf242/foils/filesystems.pdf · 1 1 input/output...

34
1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software layers 5.4 Disks 5.5 Clocks 5.6 Character-oriented terminals 5.7 Graphical user interfaces 5.8 Network terminals 5.9 Power management 2 Memory-Mapped I/O (1) Separate I/O and memory space Memory-mapped I/O • Hybrid

Upload: others

Post on 28-Dec-2019

32 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

1

1

Input/Output

Chapter 5

5.1 Principles of I/O hardware5.2 Principles of I/O software5.3 I/O software layers5.4 Disks5.5 Clocks5.6 Character-oriented terminals5.7 Graphical user interfaces5.8 Network terminals5.9 Power management

2

Memory-Mapped I/O (1)

• Separate I/O and memory space• Memory-mapped I/O• Hybrid

Page 2: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

2

3

Memory-Mapped I/O (2)

(a) A single-bus architecture(b) A dual-bus memory architecture

4

Direct Memory Access (DMA)

Operation of a DMA transfer

Page 3: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

3

5

Interrupts Revisited

How interrupts happens. Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires

6

DisksDisk Hardware (1)

Disk parameters for the original IBM PC floppy disk and a Western Digital WD 18300 hard disk

Page 4: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

4

7

Disk Hardware (2)

• Physical geometry of a disk with two zones• A possible virtual geometry for this disk

8

Disk Hardware (3)

• Raid levels 0 through 2 • Backup and parity drives are shaded

Page 5: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

5

9

Disk Hardware (4)

• Raid levels 3 through 5• Backup and parity drives are shaded

10

Disk Hardware (5)

Recording structure of a CD or CD-ROM

Page 6: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

6

11

Disk Hardware (6)

Logical data layout on a CD-ROM

12

Disk Hardware (7)

• Cross section of a CD-R disk and laser– not to scale

• Silver CD-ROM has similar structure– without dye layer– with pitted aluminum layer instead of gold

Page 7: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

7

13

Disk Hardware (8)

A double sided, dual layer DVD disk

14

Disk Formatting (1)

A disk sector

Page 8: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

8

15

Disk Formatting (2)

An illustration of cylinder skew

16

Disk Formatting (3)

• No interleaving• Single interleaving• Double interleaving

Page 9: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

9

17

Disk Arm Scheduling Algorithms (1)

• Time required to read or write a disk block determined by 3 factors

1. Seek time

2. Rotational delay

3. Actual transfer time

• Seek time dominates

• Error checking is done by controllers

18

Disk Arm Scheduling Algorithms (2)

Shortest Seek First (SSF) disk scheduling algorithm

Initialposition

Pendingrequests

Page 10: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

10

19

Disk Arm Scheduling Algorithms (3)

The elevator algorithm for scheduling disk requests

20

Error Handling

• A disk track with a bad sector• Substituting a spare for the bad sector• Shifting all the sectors to bypass the bad one

Page 11: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

11

21

Stable Storage

Analysis of the influence of crashes on stable writes

22

File Systems

Chapter 6

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

Page 12: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

12

23

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

24

File Naming

Typical file extensions.

Page 13: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

13

25

File Structure

• Three kinds of files– byte sequence– record sequence– tree

26

File Types

(a) An executable file (b) An archive

Page 14: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

14

27

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

28

File Attributes

Possible file attributes

Page 15: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

15

29

File Operations

1. Create

2. Delete

3. Open

4. Close

5. Read

6. Write

7. Append

8. Seek

9. Get attributes

10.Set Attributes

11.Rename

30

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

Page 16: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

16

31

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

32

Memory-Mapped Files

(a) Segmented process before mapping files into its address space

(b) Process after mapping existing file ��� into one segment

creating new segment for ���

Page 17: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

17

33

DirectoriesSingle-Level Directory Systems

• A single level directory system– contains 4 files– owned by 3 different people, A, B, and C

34

Two-level Directory Systems

Letters indicate ���� of the directories and files

Page 18: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

18

35

Hierarchical Directory Systems

A hierarchical directory system

36

A UNIX directory tree

Path Names

Page 19: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

19

37

Directory Operations

1. Create

2. Delete

3. Opendir

4. Closedir

5. Readdir

6. Rename

7. Link

8. Unlink

38

File System Implementation

A possible file system layout

Page 20: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

20

39

Implementing Files (1)

(a) Contiguous allocation of disk space for 7 files(b) State of the disk after files and � have been removed

40

Implementing Files (2)

Storing a file as a linked list of disk blocks

Page 21: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

21

41

Implementing Files (3)

Linked list allocation using a file allocation table in RAM

42

Implementing Files (4)

An example i-node

Page 22: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

22

43

Implementing Directories (1)

(a) A simple directoryfixed size entriesdisk addresses and attributes in directory entry

(b) Directory in which each entry just refers to an i-node

44

Implementing Directories (2)

• Two ways of handling long file names in directory– (a) In-line– (b) In a heap

Page 23: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

23

45

Shared Files (1)

File system containing a shared file

46

Shared Files (2)

(a) Situation prior to linking

(b) After the link is created

(c)After the original owner removes the file

Page 24: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

24

47

Disk Space Management (1)

• Dark line (left hand scale) gives data rate of a disk• Dotted line (right hand scale) gives disk space efficiency• All files 2KB

Block size

48

Disk Space Management (2)

(a) Storing the free list on a linked list(b) A bit map

Page 25: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

25

49

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

50

Disk Space Management (4)

Quotas for keeping track of each user’s disk use

Page 26: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

26

51

File System Reliability (1)

• 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

������������

������ ��

52

File System Reliability (2)

Bit maps used by the logical dumping algorithm

Page 27: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

27

53

File System Reliability (3)

• File system states(a) consistent(b) missing block(c) duplicate block in free list(d) duplicate data block

54

File System Performance (1)

The block cache data structures

Page 28: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

28

55

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

56

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

Page 29: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

29

57

Example File SystemsCD-ROM File Systems

The ISO 9660 directory entry

58

The CP/M File System (1)

Memory layout of CP/M

Page 30: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

30

59

The CP/M File System (2)

The CP/M directory entry format

60

The MS-DOS File System (1)

The MS-DOS directory entry

Page 31: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

31

61

The MS-DOS File System (2)

• Maximum partition for different block sizes• The empty boxes represent forbidden combinations

62

The Windows 98 File System (1)

The extended MOS-DOS directory entry used in Windows 98

�����

Page 32: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

32

63

The Windows 98 File System (2)

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

Bytes

Checksum

64

The Windows 98 File System (3)

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

Page 33: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

33

65

The UNIX V7 File System (1)

A UNIX V7 directory entry

66

The UNIX V7 File System (2)

A UNIX i-node

Page 34: Chapter 5 Input/Output - folk.uio.nofolk.uio.no/inf242/foils/FileSystems.pdf · 1 1 Input/Output Chapter 5 5.1 Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software

34

67

The UNIX V7 File System (3)

The steps in looking up �������������