File-System Interface

advertisement
TDDI04
Concurrent Programming,
Operating Systems,
and Real-time Operating Systems
File-System Interface
§ File Concept
How the file system
looks to the user
and to application
programs
§ Access Methods
§ Directory Structure
File-System Interface
§ File-System Mounting
§ File Sharing
§ Protection
[SGG7] Chapter 10
Copyright Notice: The lecture notes are mainly based on Silberschatz’s, Galvin’s and Gagne’s book (“Operating System
Concepts”, 7th ed., Wiley, 2005). No part of the lecture notes may be reproduced in any form, due to the copyrights
reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University.
Acknowledgment: The lecture notes are originally compiled by C. Kessler, IDA.
Klas Arvidsson, IDA,
Linköpings universitet.
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
File Concept
File Structure
§ Contiguous logical address space
§ None - sequence of words, bytes
•
A file is the unit of secondary storage known to the user
§ Type
•
Data
> character
§ Simple record structure
•
•
•
Lines
Fixed length
Variable length
§ Complex Structures
•
•
> binary
•
© Silberschatz, Galvin and Gagne 2005
10.2
Program
Formatted document
Relocatable load file
§ Attributes (Name, id, size, type, location, protection, etc)
§ Can simulate last two with first method by inserting appropriate control
characters
§ API (Operations on files)
§ Who decides:
•
•
§ Organized in a directory of files
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.3
© Silberschatz, Galvin and Gagne 2005
Operating system
Program
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
© Silberschatz, Galvin and Gagne 2005
10.4
File Attributes
File Operations (API)
§ Name – the only information kept in human-readable form
§ File is an abstract data type, with operations
§ 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 read, write, execute
§ Time, date, and user identification – data for protection,
security, and usage monitoring
§ Such information about files (i.e., meta-data)
is kept in a directory structure,
which is maintained on the disk
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.5
© Silberschatz, Galvin and Gagne 2005
•
•
•
•
•
•
•
•
Create
Unix / C example:
Write
open ( ”filename”, ”mode” )
Read
returns a file descriptor / handle
= index into a per-process
table of open files (part of PCB)
(or an error code)
Reposition within file
Delete
Truncate
Open(Fi) – search the directory structure on disk for entry
Fi, and move the content of that entry to memory
Close(Fi) – move the content of entry Fi in memory to
directory structure on disk
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.6
© Silberschatz, Galvin and Gagne 2005
1
Open Files
File Types – Name, Extension
§ Collected in a system-wide table of open files
•
Each process has (in its PCB) a table of pointers into this
system-wide table
•
Semantics of fork()?
§ Data needed to manage open files:
•
File pointer: pointer to last read/write location,
one per process that has the file open
•
File-open count: count number of times a file is opened –
to allow removal of data from open-file table when last
process closes it
•
•
Disk location of the file
Access rights: per-process access mode information
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.7
© Silberschatz, Galvin and Gagne 2005
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
© Silberschatz, Galvin and Gagne 2005
10.8
Simulation of Sequential Access
on a Direct-access File
Access Methods
§ Sequential Access
read next
write next
reset (rewind, position to 0)
§ Direct Access
position to n
read next
write next
read n
write n
(n = relative block number)
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.9
© Silberschatz, Galvin and Gagne 2005
Example of Index and Relative Files
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
© Silberschatz, Galvin and Gagne 2005
10.10
Directory Structure
§ A collection of nodes containing information about all files
Directory
Files
F1
F2
F3
F4
Fn
Use an index to search data with minimum disk access
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.11
© Silberschatz, Galvin and Gagne 2005
Both the directory structure and the files reside on disk.
Backups of these two structures are kept on tapes.
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.12
© Silberschatz, Galvin and Gagne 2005
2
A Typical File-system Organization
Operations performed on a Directory
§ Search for a file
§ Create a file
§ Delete a file
§ List a directory
§ Rename a file
§ Traverse the file system
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.13
© Silberschatz, Galvin and Gagne 2005
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.14
Organize the Directory (Logically) to Obtain …
Single-Level Directory
§ Efficiency – locating a file quickly
§ A single directory for all users
© Silberschatz, Galvin and Gagne 2005
§ Naming – convenient to users
•
•
Two users can use the 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, …
=> Naming problem
=> Grouping problem
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.15
© Silberschatz, Galvin and Gagne 2005
Two-Level Directory
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.16
© Silberschatz, Galvin and Gagne 2005
Tree-Structured Directories
§ Separate directory for each user
§ Efficient searching
n Path name: username / filename
§ Grouping Capability
n Can have the same file name for different user
§ Current directory (working directory)
•
•
n Efficient searching
n No grouping capability
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.17
© Silberschatz, Galvin and Gagne 2005
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
cd /spell/mail/prog
type list
10.18
© Silberschatz, Galvin and Gagne 2005
3
Tree-Structured Directories (Cont)
§ Absolute or relative path name
§ Creating a new file is done in current directory
Acyclic-Graph Directories
§ Have shared subdirectories and files
§ 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” (?)
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.19
© Silberschatz, Galvin and Gagne 2005
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.20
© Silberschatz, Galvin and Gagne 2005
Acyclic-Graph Directories (Cont.)
Hard and soft links
§ Two different names (aliasing)
§ Hard links
• direct pointer (block address) to a directory or file
§ If /dict/w/list is deleted ⇒ dangling pointer /dict/all
Solutions:
•
Backpointers, so we can delete all pointers
=> But variable size records a problem
•
•
Backpointers using a daisy chain organization
Count references to file
§ New directory entry type
•
•
Link – another name (pointer) to an existing file
Resolve the link – follow pointer to locate the file
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.21
© Silberschatz, Galvin and Gagne 2005
General Graph Directory
•
•
•
cannot span partition boundaries
need be updated when file moves to different place on disk
Unix: ln <filename> <linkname>
§ Soft links (symbolic links, ”shortcut”, ”alias”)
• files containing the actual (full) file name
• still valid if file moves on disk
• no longer valid if file name (or path) changes
•
•
Unix: ln –s <filename> <linkname>
Windows: junction <link> <target>
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.22
© Silberschatz, Galvin and Gagne 2005
File System Mounting
§ A file system must be mounted before it can be accessed
§ Mounting combines multiple file systems in one namespace
§ An unmounted file system is mounted at a mount point
§ How do we guarantee no cycles?
•
•
Allow only links to files, not to subdirectories
•
Garbage collection – mark all reachable files, delete the rest
Every time a new hard link is added, use a cycle detection
algorithm to determine whether it is OK (not for soft links)
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.23
© Silberschatz, Galvin and Gagne 2005
Existing
file system
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
Unmounted volume
residing on /device/dsk
10.24
Mount point:
Mounted /device/dsk
over /users
© Silberschatz, Galvin and Gagne 2005
4
File Sharing
File Sharing – Remote File Systems
§ Sharing of files on multi-user systems is desirable
§ Uses networking to allow file system access between systems
•
•
•
§ 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
§ Group IDs allow users to be in groups,
permitting group access rights
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
Automatically, seamlessly using distributed file systems
Semi automatically via the world wide web
§ Client-server model allows clients to mount remote file systems from
servers
•
•
•
•
•
§ User IDs identify users,
allowing permissions and protections to be per-user
Manually via programs like FTP, SCP
Server can serve multiple clients
Client and user-on-client identification is insecure or complicated
NFS is standard UNIX client-server file sharing protocol
CIFS is standard Windows protocol
Standard OS file calls are translated into remote calls
§ Distributed Information Systems (distributed naming services) such as
LDAP, DNS, NIS, Active Directory implement unified access to information
needed for remote computing
© Silberschatz, Galvin and Gagne 2005
10.25
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.26
© Silberschatz, Galvin and Gagne 2005
Protection
File Sharing – Remote File Systems
§ File owner/creator should be able to control:
Failure Modes
•
•
§ Remote file systems add new failure modes,
due to network failure, server failure
§ Recovery from failure can involve state information
about status of each remote request
•
•
•
•
•
•
Consistency Semantics
§ Multiple simultaneous user access?
§ When is changes visible to others?
© Silberschatz, Galvin and Gagne 2005
10.27
by whom
§ Types of access
§ Stateless protocols such as NFS include all information
in each request, allowing easy recovery but less security
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
what can be done
Read
Write
Execute
Append
Delete
List
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.28
Access Lists and Groups
A Sample UNIX Directory Listing
§ 3 modes of access: read, write, execute
> ls -l
§ 3 classes of users:
a) owner access
7
⇒
b) group access
6
⇒
c) public access
1
⇒
owner
group
© Silberschatz, Galvin and Gagne 2005
name
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
Attach a group to a file:
chgrp
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
G
group
761
public
game
game
10.29
© Silberschatz, Galvin and Gagne 2005
TDDI04, K. Arvidsson, IDA, Linköpings universitet.
10.30
© Silberschatz, Galvin and Gagne 2005
5
Download