Download File-System

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Copland (operating system) wikipedia , lookup

Security-focused operating system wikipedia , lookup

Library (computing) wikipedia , lookup

MTS system architecture wikipedia , lookup

Windows NT startup process wikipedia , lookup

RSTS/E wikipedia , lookup

DNIX wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

OS 2200 wikipedia , lookup

Commodore DOS wikipedia , lookup

Spring (operating system) wikipedia , lookup

Burroughs MCP wikipedia , lookup

Batch file wikipedia , lookup

CP/M wikipedia , lookup

Computer file wikipedia , lookup

File locking wikipedia , lookup

VS/9 wikipedia , lookup

Unix security wikipedia , lookup

Transcript
Chapter 10: File-System
 10.1 File Concept
 10.2 Access Methods
 10.3 Directory Structure
 10.4 File-System Mounting
 10.5 File Sharing
 10.6 Protection
Operating System Principles
10.1
Silberschatz, Galvin and Gagne ©2005
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 discuss the semantics of sharing files among
multiple processes, users, and computers
 To explore file-system protection
Operating System Principles
10.2
Silberschatz, Galvin and Gagne ©2005
10.1 File Concept
 The operating system abstracts from the physical
properties of its storage to define a logical storage unit,
the file.
 Files are mapped by the OS onto physical, usually
nonvolatile, devices.
 Use Ultra-Editor to examine contents of a file
 File types:

Data, free form or formatted
numeric
 character
 binary


Program
source
 object

Operating System Principles
10.3
Silberschatz, Galvin and Gagne ©2005
File Structure
 None - sequence of words, bytes
 Simple record structure



Lines and Pages
Fixed length
Variable length
 Complex Structures



Formatted document
Relocatable load file
Executable
 Who decides:


Operating system
Program
Operating System Principles
10.4
Silberschatz, Galvin and Gagne ©2005
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 file types
 Location – pointer to the 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 secondary storage, like a disk
Operating System Principles
10.5
Silberschatz, Galvin and Gagne ©2005
File Operations
 File is an abstract data type with the following basic
operations

create

write


The system must keep a writer pointer. File info in the directory also
updated
read

The system must keep a read pointer.

reposition within file (known as file seek)

delete

truncate
 Other operations

append, rename, copy, get/set file attributes
Operating System Principles
10.6
Silberschatz, Galvin and Gagne ©2005
Open and Close Files
 Most file operations involve searching the directory for a
file

open(Fi) – search the directory structure on disk for entry Fi, and
move the content of entry to memory

close (Fi) – move the content of entry Fi in memory to directory
structure on disk
 The OS normally maintains two-level open-file tables,
per-process and system-wide
Operating System Principles
10.7
Silberschatz, Galvin and Gagne ©2005
Open and Close 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 Principles
10.8
Silberschatz, Galvin and Gagne ©2005
Open File Locking
 Provided by some operating systems and file systems
 Mediates access to a file, like process synchronization

shared lock and exclusive lock
 Mandatory or advisory:

Mandatory – access is denied depending on locks held and
requested (Windows)

Advisory – processes can find status of locks and decide
what to do (Unix)
Operating System Principles
10.9
Silberschatz, Galvin and Gagne ©2005
File Locking Example – Java API
import java.io.*;
import java.nio.channels.*;
public class LockingExample {
public static final boolean EXCLUSIVE = false;
public static final boolean SHARED = true;
public static void main(String arsg[]) throws IOException {
FileLock sharedLock = null;
FileLock exclusiveLock = null;
try {
RandomAccessFile raf = new RandomAccessFile("file.txt", "rw");
// get the channel for the file
FileChannel ch = raf.getChannel();
// this locks the first half of the file - exclusive
exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE);
/** Now modify the data . . . */
// release the lock
exclusiveLock.release();
Operating System Principles
10.10
Silberschatz, Galvin and Gagne ©2005
File Locking Example – Java API (cont)
// this locks the second half of the file - shared
sharedLock = ch.lock(raf.length()/2+1, raf.length(), SHARED);
/** Now read the data . . . */
// release the lock
sharedLock.release();
} catch (java.io.IOException ioe) {
System.err.println(ioe);
}finally {
if (exclusiveLock != null)
exclusiveLock.release();
if (sharedLock != null)
sharedLock.release();
}
}
}
Operating System Principles
10.11
Silberschatz, Galvin and Gagne ©2005
Common File
Types
Unix: use magic
number to
indicate roughly
file types
Skip: p.428 第 2
段及第 3 段
Skip: 10.1.4
Operating System Principles
10.12
Silberschatz, Galvin and Gagne ©2005
Internal File Structure
 All disks is performed in units of one block
(physical record)
 Logical records may vary in length
 Packing a number of logical records into physical
blocks is the common solution

Example: UNIX defines all files to be streams of bytes.
Its logical record size is 1 byte.
 Packing can be done either by user’s application
or by the operating system

Internal fragmentation problem
Operating System Principles
10.13
Silberschatz, Galvin and Gagne ©2005
10.2 Access Methods
 Sequential Access (based on tape model)
read next
write next
reset to the beginning
no read after last write
 Direct Access (or relative access)
read n
write n
position to n
read next
write next
rewrite n
(n = relative block number)
Operating System Principles
10.14
Silberschatz, Galvin and Gagne ©2005
Some systems support only one of sequential access
and direct access for files.
Simulation of sequential access on a direct-access file
Simulation of direct access on a sequential-access file
is inefficient and clumsy
Operating System Principles
10.15
Silberschatz, Galvin and Gagne ©2005
Other Access Methods
Example of Index and Relative Files
Operating System Principles
10.16
Silberschatz, Galvin and Gagne ©2005
10.3 Directory Structure
 A disk may have several partitions. A partition may be
with a file system. Several partitions, maybe from many
disks, could form a volume that holds a file system.
 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 Principles
10.17
Silberschatz, Galvin and Gagne ©2005
A Typical File-system Organization
Operating System Principles
10.18
Silberschatz, Galvin and Gagne ©2005
Operations Performed on Directory
 Search for a file
 Create a file
 Delete a file
 List a directory
 Rename a file
 Traverse the file system

for backup (to tape)
Operating System Principles
10.19
Silberschatz, Galvin and Gagne ©2005
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 Principles
10.20
Silberschatz, Galvin and Gagne ©2005
Single-Level Directory
 A single directory for all users
Naming problem
Grouping problem
Operating System Principles
10.21
Silberschatz, Galvin and Gagne ©2005
Two-Level Directory
 Separate directory for each user
 Can have the same file name for different user
 Isolation or Allow access to other’s files?
 If allowed, then use path name
 Efficient searching
 Use environment variable: search path
 No grouping capability
Operating System Principles
10.22
Silberschatz, Galvin and Gagne ©2005
Tree-Structured Directories
Operating System Principles
10.23
Silberschatz, Galvin and Gagne ©2005
Tree-Structured Directories
 Efficient searching
 Grouping Capability
 Current directory (working directory)

cd /spell/mail/prog
 type list
 Absolute or relative path name
 Creating a new file is done in current directory
 Delete a file
rm <file-name>
 Delete a directory

MS-DOS will not delete a directory unless it is empty
 Unix provides an option to delete all files and sub-directories
under a directory
Operating System Principles
10.24
Silberschatz, Galvin and Gagne ©2005
Tree-Structured Directories
 Creating a new subdirectory is done in current
directory
mkdir <dir-name>
Example: if current directory is /mail
mkdir count
mail
prog
copy prt exp count
In Unix “rm –f mail”  deleting the entire subtree rooted by “mail”
Operating System Principles
10.25
Silberschatz, Galvin and Gagne ©2005
Acyclic-Graph Directories
 Use link to have shared subdirectories and files
 Another approach: duplicate all information about
subdirectories and files in both sharing directories. But it is
hard to maintain consistency when a shared file is modified.
Operating System Principles
10.26
Silberschatz, Galvin and Gagne ©2005
Acyclic-Graph Directories
 New directory entry type

Link – another name (pointer) to an existing file

Resolve the link – follow pointer to locate the file
 Two different names (aliasing)

A file could have multiple absolute path names.

Traverse problem.
 If dict deletes all  dangling pointer. Solutions:

Just wait for users to find out. It is used with symbolic links:

Preserve the file until all references to it are deleted. Unix uses
this approach for hard links by keeping a reference count in the
file information block.
 Acyclic-graph could be maintained by prohibiting
multiple references to directories
SKIP: 10.3.7
Operating System Principles
10.27
Silberschatz, Galvin and Gagne ©2005
10.4 File System Mounting
 A file system must be mounted before it can be accessed
 A unmounted file system (i.e. Fig. 10-11(b)) is mounted at
a mount point
existing
Operating System Principles
unmounted volume
10.28
mount point
Silberschatz, Galvin and Gagne ©2005
Mount Point
1. The OS is first given the name of the device and the mount point
2. The OS verifies that the device contains a valid file system

Read the device directory and verify the directory format
3. The OS notes in the directory structure that a file system is
mounted at the specified mount point
4. If the volume is unmounted, the file system is restored to the
situation before mounting

OS may impose semantics to clarify functionality

May disallow a mount over a directory containing files; or may
obscure the directory’s existing files until the file system is unmounted

May allow the same file system to be mounted repeatedly, at different
mount points; or it may allow only one mount per file system
Operating System Principles
10.29
Silberschatz, Galvin and Gagne ©2005
Mount Examples
 Macintosh searches for a file system on a disk first
encountered. If found, the file system is auto-mounted at
the root level
 Windows OS maintains an extended two-level directory
structure, with devices and volumes assigned drive letters.

Recent Windows allow a file system to be mounted
anywhere in the directory tree

Windows auto-discover all devices and mount all located file
systems at boot time
 Unix has explicit mount commands
Operating System Principles
10.30
Silberschatz, Galvin and Gagne ©2005
10.5 File Sharing
 Sharing of files on multi-user systems is desirable
 Sharing may be done through a protection
scheme
 On distributed systems, files may be shared
across a network
 Network File System (NFS) is a common
distributed file-sharing method
Operating System Principles
10.31
Silberschatz, Galvin and Gagne ©2005
File Sharing – Multiple Users
 File sharing, file naming, and file protection are important in
multiple-user systems

The system may allow a user to access other user’s
files by default or it may require specific access grant
 Most systems use the concept of file owner and group, as file
attributes, to implement file sharing and protection

User IDs identify users, allowing permissions and
protections to be per-user

Group IDs allow users to be in groups, permitting
group access rights
Operating System Principles
10.32
Silberschatz, Galvin and Gagne ©2005
File Sharing – Remote File Systems
 Uses networking to allow file system access between
systems

Manually via programs like FTP
 Both
anonymous and authenticated access

Automatically, seamlessly using distributed file
systems, in which remote directories are visible from a
local machine

Semi automatically via the world wide web, where a
browser is needed to access remote files, and separate
operations (a wrapper for ftp) are used to transfer files
Operating System Principles
10.33
Silberschatz, Galvin and Gagne ©2005
The Client-Server Model
 Client-server model allows clients to mount remote
file systems from servers

Server can serve multiple clients

Client, specified by a network name or IP address, and
user-on-client identification is insecure or complicated (by
encryption)

NFS is standard UNIX client-server file sharing protocol
 User’s
ID on the client and server must match
 Once
the remote file system is mounted, file operation
requests are sent on behalf of the user across the network to
the server via the DFS protocol
 Standard
operating system file calls are translated into
remote calls
Operating System Principles
10.34
Silberschatz, Galvin and Gagne ©2005
Distributed Information Systems
 Also known as distributed naming services
 LDAP, DNS, NIS (network information service, yellow
pages), Active Directory implement unified access to
information needed for remote computing
 In Windows CIFS (common internet file system),
network information is used with user authentication to
create a network login. A newer version is called active
directory.
 One distributed LDAP (lightweight directory-access
protocol) could be used by an organization to store all
user and resource information for all organization’s
computers. The result is secure single sign-on for
users.
Skip 10.5.2.3, 10.5.3
Operating System Principles
10.35
Silberschatz, Galvin and Gagne ©2005
10.6 Protection
 Reliability is to keep the computer system from physical
damage. (Chapter 12)
 Protection is to keep it from improper access.
 File owner/creator should be able to control:

what can be done

by whom
 Basic types of controlled access

Read

Write

Execute

Append

Delete

List
Operating System Principles
Other high-level functions, like copying and
editing files may be implemented by making
lower-level system calls
10.36
Silberschatz, Galvin and Gagne ©2005
Access Control Lists
 Mode of access: read, write, execute
 Three classes of users
a) owner access
7

b) group access
6

c) public access
1

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 Principles
G
game
10.37
Silberschatz, Galvin and Gagne ©2005
Windows XP Access-control List Management
Operating System Principles
10.38
Silberschatz, Galvin and Gagne ©2005
A Sample UNIX Directory Listing
Operating System Principles
10.39
Silberschatz, Galvin and Gagne ©2005
Other Protection Approaches
 Associate a password with each file

Disadvantages
 The
number of passwords that a user needs to remember
 If only one password is used for all the files, then
protection is on an all-or-none basis
–
Some system allow the user to associate a password with a
directory
 Adding protection mechanisms to single-user OS is
difficult
 Directory protection

Control the creation and deletion of files in a directory

Control whether a user could check the existence of a
file in a directory. (Listing the contents of a directory)
Operating System Principles
10.40
Silberschatz, Galvin and Gagne ©2005