Вы находитесь на странице: 1из 61

Course 11: File-System

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

Operating System Concepts

11.2

Silberschatz, Galvin and Gagne 2008

Course 10: Review Demand Paging

Operating System Concepts

11.3

Silberschatz, Galvin and Gagne 2008

Course 10: Review Copy on Write

Operating System Concepts

11.4

Silberschatz, Galvin and Gagne 2008

Course 10: Review Page Replacement

Operating System Concepts

11.5

Silberschatz, Galvin and Gagne 2008

Course 11: File-System


File Concept
Access Methods
Directory Structure
Protection
File-System Structure
File-System Implementation
Allocation Methods

Operating System Concepts

11.6

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.7

Silberschatz, Galvin and Gagne 2008

File Concept

Operating System Concepts

11.8

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.9

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.10

Silberschatz, Galvin and Gagne 2008

File Types Name, Extension

Operating System Concepts

11.11

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.12

Silberschatz, Galvin and Gagne 2008

File Operations
File is an abstract data type
Operations:

Create

Write

Read

Reposition within file

Delete

Truncate

Operating System Concepts

11.13

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.14

Silberschatz, Galvin and Gagne 2008

Access Methods

Operating System Concepts

11.15

Silberschatz, Galvin and Gagne 2008

Sequential-access File

Operating System Concepts

11.16

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.17

Silberschatz, Galvin and Gagne 2008

Simulation of Sequential Access on a Direct-access File

Operating System Concepts

11.18

Silberschatz, Galvin and Gagne 2008

Example of Index and Relative Files

Operating System Concepts

11.19

Silberschatz, Galvin and Gagne 2008

Directory Structure

Operating System Concepts

11.20

Silberschatz, Galvin and Gagne 2008

Directory Structure
A collection of nodes containing information about all files

Directory

Files

F1

F2

F3

F4
Fn

Both the directory structure and the files reside on disk


Backups of these two structures are kept on tapes
Operating System Concepts

11.21

Silberschatz, Galvin and Gagne 2008

A Typical File-system Organization

Operating System Concepts

11.22

Silberschatz, Galvin and Gagne 2008

Operations Performed on Directory


Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system

Operating System Concepts

11.23

Silberschatz, Galvin and Gagne 2008

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, )

Operating System Concepts

11.24

Silberschatz, Galvin and Gagne 2008

Single-Level Directory
A single directory for all users

Naming problem
Grouping problem

Operating System Concepts

11.25

Silberschatz, Galvin and Gagne 2008

Two-Level Directory
Separate directory for each user

Path name
Can have the same file name for different user
Efficient searching
No grouping capability

Operating System Concepts

11.26

Silberschatz, Galvin and Gagne 2008

Tree-Structured Directories
Efficient searching

Grouping capability

Operating System Concepts

11.27

Silberschatz, Galvin and Gagne 2008

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


Operating System Concepts

11.28

Silberschatz, Galvin and Gagne 2008

Acyclic-Graph Directories
Have shared subdirectories and files

Operating System Concepts

11.29

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.30

Silberschatz, Galvin and Gagne 2008

Protection

Operating System Concepts

11.31

Silberschatz, Galvin and Gagne 2008

Protection
File owner/creator should be able to control:

what can be done

by whom

Types of access

Read

Write

Execute

Append

Delete

List

Operating System Concepts

11.32

Silberschatz, Galvin and Gagne 2008

Access Lists and Groups

Mode of access: read, write, execute

Three classes of users


a) owner access

b) group access

c) public access

RWX
111
RWX
110
RWX
001

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

chmod

group

public

761

game

Attach a group to a file

chgrp
Operating System Concepts

game

11.33

Silberschatz, Galvin and Gagne 2008

Windows XP Access-control List Management

Operating System Concepts

11.34

Silberschatz, Galvin and Gagne 2008

A Sample UNIX Directory Listing

Operating System Concepts

11.35

Silberschatz, Galvin and Gagne 2008

File System Structure

Operating System Concepts

11.36

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.37

Silberschatz, Galvin and Gagne 2008

Layered File System

Operating System Concepts

11.38

Silberschatz, Galvin and Gagne 2008

File System Implementation

Operating System Concepts

11.39

Silberschatz, Galvin and Gagne 2008

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.

Operating System Concepts

11.40

Silberschatz, Galvin and Gagne 2008

A Typical File Control Block

Operating System Concepts

11.41

Silberschatz, Galvin and Gagne 2008

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.

Operating System Concepts

11.42

Silberschatz, Galvin and Gagne 2008

In-Memory File System Structures

Operating System Concepts

11.43

Silberschatz, Galvin and Gagne 2008

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.

Operating System Concepts

11.44

Silberschatz, Galvin and Gagne 2008

Schematic View of Virtual File System

Operating System Concepts

11.45

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.46

Silberschatz, Galvin and Gagne 2008

Alocation Methods

Operating System Concepts

11.47

Silberschatz, Galvin and Gagne 2008

Allocation Methods
An allocation method refers to how disk blocks are allocated for

files:
Contiguous allocation
Linked allocation

Indexed allocation

Operating System Concepts

11.48

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.49

Silberschatz, Galvin and Gagne 2008

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 really
expensive

Operating System Concepts

11.50

Silberschatz, Galvin and Gagne 2008

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.

Operating System Concepts

11.51

Silberschatz, Galvin and Gagne 2008

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

anywhere on the disk.

block

Operating System Concepts

pointer

11.52

Silberschatz, Galvin and Gagne 2008

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.

Operating System Concepts

11.53

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.54

Silberschatz, Galvin and Gagne 2008

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 really
expensive if FAT
not cached in
memory
Operating System Concepts

11.55

Silberschatz, Galvin and Gagne 2008

Indexed Allocation
Brings all pointers together into the index block.

Logical view.

index table

Operating System Concepts

11.56

Silberschatz, Galvin and Gagne 2008

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
Operating System Concepts

11.57

Silberschatz, Galvin and Gagne 2008

Indexed Allocation (Cont.)


Need index table

Random access
Dynamic access without external fragmentation, but have

overhead of index block.

Operating System Concepts

11.58

Silberschatz, Galvin and Gagne 2008

Indexed Allocation Mapping (Cont.)

outer-index

index table

Operating System Concepts

11.59

file

Silberschatz, Galvin and Gagne 2008

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

Operating System Concepts

11.60

Silberschatz, Galvin and Gagne 2008

End of Course 11

Вам также может понравиться