28
Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview 5.7 Implementation of the Minix 3 File System Andrew S. Tanenbaum and Albert S. Woodhull Operating Systems (The Minix Book), 3rd edition Lecture 11, 4 December 2012

Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Embed Size (px)

Citation preview

Page 1: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner

File Systems

Chapter 5

5.1 Files 5.2 Directories 5.3 File System Implementation5.4 Security5.5 Protection Mechanism5.6 Overview5.7 Implementation of the Minix 3 File System

Andrew S. Tanenbaum and Albert S. WoodhullOperating Systems (The Minix Book), 3rd editionPrentice Hall © 2006

Lecture 11, 4 December 2012

Page 2: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 2

5. Essential Requirements for 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

Page 3: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 3

5.1.1 File Naming

Fig. 5.1 Typical file extensions.

Page 4: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 4

5.1.2 File Structure

Fig. 5.2 Three kinds of filesa) byte sequenceb) record sequencec) tree

Page 5: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 5

5.1.3 File Types

Fig. 5.3 (a) An executable file (b) An archive

Magic number: identifies the file as an executable

Page 6: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 6

5.1.4 File Access• Sequential access

– read all bytes/records from the beginning– cannot jump around, could rewind or back up– convenient when medium was magnetic tape

• Random access– bytes/records read in any order– essential for data base systems– read can be implemented by :

• move file marker (seek), then read sequentially (Unix, Windows)

• Give the position in the file to start reading at

Page 7: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 7

5.5.5 File Attributes

Fig. 5.4 Some possible file attributessee OS X packages and meta data !

Page 8: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 8

5.1.6 File Operations

• Create

• Delete

• Open

• Close

• Read

• Write

• Append

• Seek

• Get attributes

• Set attributes

• Rename

• Lock

The most common system calls relating to files:

Page 9: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 9

5.2.1 Simple Directories

Fig. 5.5a) A simple directory (e.g. Windows)

o containing fixed size entrieso with disk addresses and attributes in directory entry

b)Directory in which each entry just refers to an i-node (e.g. Unix)

Page 10: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 10

5.2.2 Hierarchical Directory Systems

Fig 5.6.a A single level directory system– contains 4 files– owned by 3 different people, A, B, and C

Page 11: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 11

5.2.2 Hierarchical Directory Systems

Fig. 5.6.b A hierarchical directory system

Page 12: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 12

Fig. 5.7 A UNIX directory tree

5.2.3 Path Names

Page 13: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner

5.6.6 Directories and Paths: Minix3

Fig. 5.38 (a) Root file system. (b) An unmounted file system. (c) The result of mounting the file system of (b) on /usr/

Special file: contains no data, but provides a mechanism to map physical devices to file names

13

Page 14: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 14

5.2.4 Directory Operations

• Create

• Delete

• Opendir

• Closedir

• Readdir

• Rename

• Link

• Unlink

The most common system calls relating to directories:

hard / symbolic link, see later (variants: alias in OS X, shortcut in Windows)

Page 15: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 15

5.3.1 File System Layout

Fig. 5.8 A possible file system layoutMBR = Master Boot Record

Super block: contains all the key parameters about the file sytem

Page 16: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner

5.6.2 File System Layout: MINIX 3

Fig. 5.34 Disk layout for a floppy disk or small hard disk partition, with 64 i-nodes and a 1-KB block size (i.e., two consecutive 512-byte sectors are treated as a single block).

zone: 1, 2, 4, …, 2n blocks 16

Page 17: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 17

5.3.2 Contiguous File Allocation

Idea: allocate n consecutive blocks on the disk

Advantage•Very simple to implement•Excellent read performance

Major drawback•in time, the disk becomes fragmented•often, the final file size is not known at creation time

Usage•magnetic disk file systems•optical write-once media: CD-ROMs, DVDs, …

Page 18: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 18

5.3.2 Linked List File Allocation

Fig. 5.9 Storing a file as a linkedlist of disk blocks

Fig 5.10 Linked list allocation using a file allocation table in RAM

Page 19: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 19

5.3.2 i-nodes

Fig. 5.11 An i-node with three levels of indirect blocks

Page 20: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 20

5.3.3 Shared Files

Fig. 5.12 File system containing a shared file

Hard link vs symbolic (or soft) link

Unix command: link

Page 21: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 21

5.3.3 Shared Files : hard link

Fig. 4.17 a) Situation prior to linkingb) After the hard link is createdc) After the original owner removes the file

Andrew S. Tanenbaum: "Modern Operating Systems", 3rd edition, Prentice Hall © 2009

Page 22: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 22

Example: rsync to mimic Apple’s TimeMachine

Source: http://blog.interlinked.org/tutorials/rsync_time_machine.html

Question: hard link or soft link ?

Page 23: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner

Operations required to remove a file in UNIX• Remove the file from its directory.

• Release the i-node to the pool of free i-nodes.

• Return all the disk blocks to the pool of free disk blocks.

4.3.6 Journaling File Systems

Problem if the system crashes during these actions

SolutionWrite a log entry listing the three actions to be completed and write it to disk + atomic transaction (i.e. 'begin transaction', 'end transaction')

Andrew S. Tanenbaum: "Modern Operating Systems", 3rd edition, Prentice Hall © 2009 23

Page 24: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner

Fig. 4.18 Position of the virtual file system.

4.3.7 Virtual File Systems

Andrew S. Tanenbaum: "Modern Operating Systems", 3rd edition, Prentice Hall © 2009

24

Page 25: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner

5.3.3 Directories in Windows 98

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

Fig 5.13 A Windows 98 base directory entry.

25

Page 26: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 26

5.3.3 Directories in Unix

Fig. 5.15 A Version 7 UNIX directory entry

Page 27: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner 27

5.3.3 Directories in Unix

Fig. 5.16 The steps in looking up /usr/ast/mbox

Page 28: Annotated by B. Hirsbrunner File Systems Chapter 5 5.1 Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview

Annotated by B. Hirsbrunner

5.3.6 Reducing Disk Arm Motion

Fig. 5.21

a)i-nodes placed at the start of the disk.

b)Disk divided into cylinder groups, each with its own blocks and i-nodes.

28