ch11 file system

61
Course 11: File - System

Upload: mmmaya

Post on 25-Dec-2015

15 views

Category:

Documents


3 download

DESCRIPTION

File System

TRANSCRIPT

Page 1: Ch11 File System

Course 11: File-System

Page 2: Ch11 File System

11.2 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Course 10: Review

Virtual memory – separation of user

logical memory from physical memory.

Only part of the program needs to be

in memory for execution

Logical address space can therefore

be much larger than physical address

space

Allows address spaces to be shared

by several processes

Allows for more efficient process

creation

Page 3: Ch11 File System

11.3 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Course 10: Review – Demand Paging

Page 4: Ch11 File System

11.4 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Course 10: Review – Copy on Write

Page 5: Ch11 File System

11.5 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Course 10: Review – Page Replacement

Page 6: Ch11 File System

11.6 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Course 11: File-System

File Concept

Access Methods

Directory Structure

Protection

File-System Structure

File-System Implementation

Allocation Methods

Page 7: Ch11 File System

11.7 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Objectives

To explain the function of file systems

To describe the interfaces to file systems

To discuss file-system design tradeoffs, including access methods,

file sharing, file locking, and directory structures

To explore file-system protection

To describe the details of implementing local file systems and

directory structures

Page 8: Ch11 File System

11.8 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File Concept

Page 9: Ch11 File System

11.9 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File Concept

Resource for storing information

Contiguous logical address space

User point of view

Interface to information (usually hierarchical)

OS point of view

Data structures and allocation management algorithms

Files contains

Data

Meta-data - FCB

Page 10: Ch11 File System

11.10 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File Structure

None - sequence of words, bytes

Simple record structure

Lines

Fixed length

Variable length

Complex structures

Formatted document

Relocatable load file

Can simulate last two with first method by inserting appropriate control characters – e.g. XML

Who decides:

Operating system

Program

Page 11: Ch11 File System

11.11 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File Types – Name, Extension

Page 12: Ch11 File System

11.12 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File Attributes

Name – only information kept in human-readable form

Identifier – unique tag (number) identifies file within file system

Type – needed for systems that support different types

Location – pointer to file location on device

Size – current file size

Protection – controls who can do reading, writing, executing

Time, date, and user identification – data for protection, security,

and usage monitoring

Information about files are kept in the directory structure, which is

maintained on the disk

Page 13: Ch11 File System

11.13 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File Operations

File is an abstract data type

Operations:

Create

Write

Read

Reposition within file

Delete

Truncate

Page 14: Ch11 File System

11.14 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Open Files

Several pieces of data are needed to manage open files:

File pointer: pointer to last read/write location, per process that

has the file open

File-open count: counter of number of times a file is open – to

allow removal of data from open-file table when last processes

closes it

Disk location of the file: cache of data access information

Access rights: per-process access mode information

Page 15: Ch11 File System

11.15 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Access Methods

Page 16: Ch11 File System

11.16 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Sequential-access File

Page 17: Ch11 File System

11.17 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Access Methods

Sequential Access

read next

write next

reset

no read after last write

(rewrite)

Direct Access

read n

write n

position to n

read next

write next

rewrite n

n = relative block number

Page 18: Ch11 File System

11.18 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Simulation of Sequential Access on a Direct-access File

Page 19: Ch11 File System

11.19 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Example of Index and Relative Files

Page 20: Ch11 File System

11.20 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Directory Structure

Page 21: Ch11 File System

11.21 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Directory Structure

A collection of nodes containing information about all files

F 1 F 2F 3

F 4

F n

Directory

Files

Both the directory structure and the files reside on disk

Backups of these two structures are kept on tapes

Page 22: Ch11 File System

11.22 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

A Typical File-system Organization

Page 23: Ch11 File System

11.23 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Operations Performed on Directory

Search for a file

Create a file

Delete a file

List a directory

Rename a file

Traverse the file system

Page 24: Ch11 File System

11.24 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Organize the Directory (Logically) to Obtain

Efficiency – locating a file quickly

Naming – convenient to users

Two users can have same name for different files

The same file can have several different names

Grouping – logical grouping of files by properties, (e.g., all

Java programs, all games, …)

Page 25: Ch11 File System

11.25 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Single-Level Directory

A single directory for all users

Naming problem

Grouping problem

Page 26: Ch11 File System

11.26 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Two-Level Directory

Separate directory for each user

Path name

Can have the same file name for different user

Efficient searching

No grouping capability

Page 27: Ch11 File System

11.27 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Tree-Structured Directories

Efficient searching

Grouping capability

Page 28: Ch11 File System

11.28 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Tree-Structured Directories (Cont)

Absolute or relative path name

Creating a new file is done in current directory

Delete a file

rm <file-name>

Creating a new subdirectory is done in current directory

mkdir <dir-name>

Example: if in current directory /mail

mkdir count

mail

prog copy prt exp count

Deleting “mail” deleting the entire subtree rooted by “mail”

Page 29: Ch11 File System

11.29 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Acyclic-Graph Directories

Have shared subdirectories and files

Page 30: Ch11 File System

11.30 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Acyclic-Graph Directories (Cont.)

Two different names (aliasing)

If dict deletes list dangling pointer

Solutions:

Backpointers, so we can delete all pointers

Variable size records a problem

Backpointers using a daisy chain organization

Entry-hold-count solution

New directory entry type

Link – another name (pointer) to an existing file

Resolve the link – follow pointer to locate the file

Page 31: Ch11 File System

11.31 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Protection

Page 32: Ch11 File System

11.32 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Protection

File owner/creator should be able to control:

what can be done

by whom

Types of access

Read

Write

Execute

Append

Delete

List

Page 33: Ch11 File System

11.33 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Access Lists and Groups

Mode of access: read, write, execute

Three classes of users

RWX

a) owner access 7 1 1 1RWX

b) group access 6 1 1 0

RWX

c) public access 1 0 0 1

Ask manager to create a group (unique name), say G, and add some users to the group.

For a particular file (say game) or subdirectory, define an appropriate access.

owner group public

chmod 761 game

Attach a group to a file

chgrp G game

Page 34: Ch11 File System

11.34 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Windows XP Access-control List Management

Page 35: Ch11 File System

11.35 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

A Sample UNIX Directory Listing

Page 36: Ch11 File System

11.36 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File System Structure

Page 37: Ch11 File System

11.37 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File-System Structure

File structure

Logical storage unit

Collection of related information

File system resides on secondary storage (disks)

File system organized into layers

File control block – storage structure consisting of information

about a file

Page 38: Ch11 File System

11.38 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Layered File System

Page 39: Ch11 File System

11.39 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File System Implementation

Page 40: Ch11 File System

11.40 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

OS File Control Structures

A boot control block (per volume) - contain information needed by

the system to boot an operating system from that volume

A volume control block (per volume) contains volume (or

partition) details, such as the number of blocks in the partition, size

of the blocks, freeblock count and free-block pointers

A directory structure per file system is used to organize the files.

In UFS, this includes file names and associated inode numbers. In

NTFS it is stored in the master file table.

A per-file FCB contains many details about the file, including file

permissions,ownership, size, and location of the data blocks. In

UFS, this is called the inode.

Page 41: Ch11 File System

11.41 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

A Typical File Control Block

Page 42: Ch11 File System

11.42 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

In-Memory File System Structures

The following figure illustrates the necessary file system structures

provided by the operating systems.

Figure 12-3(a) refers to opening a file.

Figure 12-3(b) refers to reading a file.

Page 43: Ch11 File System

11.43 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

In-Memory File System Structures

Page 44: Ch11 File System

11.44 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Virtual File Systems

Virtual File Systems (VFS) provide an object-oriented way of

implementing file systems.

VFS allows the same system call interface (the API) to be used for

different types of file systems.

The API is to the VFS interface, rather than any specific type of file

system.

Page 45: Ch11 File System

11.45 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Schematic View of Virtual File System

Page 46: Ch11 File System

11.46 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Directory Implementation

Linear list of file names with pointer to the data blocks.

simple to program

time-consuming to execute

Hash Table – linear list with hash data structure.

decreases directory search time

collisions – situations where two file names hash to the same

location

fixed size

Page 47: Ch11 File System

11.47 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Alocation Methods

Page 48: Ch11 File System

11.48 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Allocation Methods

An allocation method refers to how disk blocks are allocated for

files:

Contiguous allocation

Linked allocation

Indexed allocation

Page 49: Ch11 File System

11.49 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Contiguous Allocation

Each file occupies a set of contiguous blocks on the disk

Simple – only starting location (block #) and length (number

of blocks) are required

Random access

Wasteful of space (dynamic storage-allocation problem)

Files cannot grow

Page 50: Ch11 File System

11.50 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Contiguous Allocation of Disk Space

IBM 360 Pros: Fast Sequential

Access, Easy Random access

Cons: External Fragmentation/Hard to grow files Free holes get

smaller and smaller

Could compact space, but that would be reallyexpensive

Page 51: Ch11 File System

11.51 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Extent-Based Systems

Many newer file systems (I.e. Veritas File System) use a modified

contiguous allocation scheme

Extent-based file systems allocate disk blocks in extents

An extent is a contiguous block of disks

Extents are allocated for file allocation

A file consists of one or more extents.

Page 52: Ch11 File System

11.52 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Linked Allocation

Each file is a linked list of disk blocks: blocks may be scattered

anywhere on the disk.

pointerblock =

Page 53: Ch11 File System

11.53 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Linked Allocation (Cont.)

Simple – need only starting address

Free-space management system – no waste of space

No random access

File-allocation table (FAT) – disk-space allocation used by

MS-DOS and OS/2.

Page 54: Ch11 File System

11.54 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Linked Allocation

Pros: Can grow files

dynamically, Free list

same as file

Cons: Bad Sequential

Access (seek between

each block),

Unreliable

(lose block, lose rest

of file)

Serious Con: Bad

random access!!!!

Technique originally

from Alto (First PC,

built at Xerox)

No attempt to

allocate contiguous

blocks

Page 55: Ch11 File System

11.55 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

File-Allocation Table

MSDOS links pages together to create a file Links not in pages, but

in the File Allocation Table (FAT) FAT contains an

entry for each block on the disk

FAT Entries corresponding to blocks of file linked together

Access properties: Sequential access

expensive unless FAT cached in memory

Random access expensive always, but reallyexpensive if FAT not cached in memory

Page 56: Ch11 File System

11.56 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Indexed Allocation

Brings all pointers together into the index block.

Logical view.

index table

Page 57: Ch11 File System

11.57 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Example of Indexed Allocation

System Allocates file

header block to hold

array of pointers big

enough to point to all

blocks

User pre-declares

max file size;

Pros: Can easily

grow up to space

allocated for index

Random

access is fast

Cons: Clumsy to grow

file bigger than table

size

Still lots of

seeks: blocks may be

spread over disk

Page 58: Ch11 File System

11.58 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Indexed Allocation (Cont.)

Need index table

Random access

Dynamic access without external fragmentation, but have overhead of index block.

Page 59: Ch11 File System

11.59 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Indexed Allocation – Mapping (Cont.)

outer-index

index table file

Page 60: Ch11 File System

11.60 Silberschatz, Galvin and Gagne ©2008Operating System Concepts

Combined Scheme: UNIX (4K bytes per block)

UNIX 4.1 Pros and cons

Pros:

Simple (more or less)

Files can easily expand (up to a point)

Small files particularly cheap and easy

Cons:

Lots of seeks

Very large files must read many indirect blocks (four I/Os per block

Page 61: Ch11 File System

End of Course 11