1 chapter 10: file- system interface. 2 file concept access methods directory structure file-system...
Post on 21-Dec-2015
218 views
TRANSCRIPT
11
Chapter 10: File-Chapter 10: File-System InterfaceSystem Interface
22
Chapter 10: File-System Chapter 10: File-System InterfaceInterface
File ConceptFile Concept
Access MethodsAccess Methods
Directory StructureDirectory Structure
File-System MountingFile-System Mounting
File SharingFile Sharing
ProtectionProtection
33
ObjectivesObjectives
To explain the function of file systemsTo explain the function of file systems
To describe the interfaces to file systemsTo describe the interfaces to file systems
To discuss file-system design tradeoffs, To discuss file-system design tradeoffs, including access methods, file sharing, file including access methods, file sharing, file locking, and directory structureslocking, and directory structures
To explore file-system protectionTo explore file-system protection
44
File ConceptFile Concept
Contiguous logical address spaceContiguous logical address space
Types: Types: DataData
numericnumeric
charactercharacter
binarybinary ProgramProgram
55
File StructureFile StructureNone - sequence of words, bytesNone - sequence of words, bytesSimple record structureSimple record structure Lines Lines Fixed lengthFixed length Variable lengthVariable length
Complex StructuresComplex Structures Formatted documentFormatted document Relocatable load fileRelocatable load file
Can simulate last two with first method by inserting Can simulate last two with first method by inserting appropriate control charactersappropriate control charactersWho decides:Who decides: Operating systemOperating system ProgramProgram
66
File AttributesFile Attributes
NameName – only information kept in human- – only information kept in human-readable formreadable form
IdentifierIdentifier – unique tag (number) identifies – unique tag (number) identifies file within file systemfile within file system
TypeType – needed for systems that support – needed for systems that support different typesdifferent types
LocationLocation – pointer to file location on – pointer to file location on devicedevice
SizeSize – current file size – current file size
77
File AttributesFile Attributes
ProtectionProtection – controls who can do reading, – controls who can do reading, writing, executingwriting, executing
Time, date, and user identificationTime, date, and user identification – – data for protection, security, and usage data for protection, security, and usage monitoringmonitoring
Information about files are kept in the Information about files are kept in the directory structure, which is maintained on directory structure, which is maintained on the diskthe disk
88
File OperationsFile Operations
File is an File is an abstract data typeabstract data type
CreateCreate
WriteWrite
ReadRead
Reposition within fileReposition within file
DeleteDelete
TruncateTruncate
99
File OperationsFile Operations
Open(FOpen(Fii)) – search the directory structure – search the directory structure
on disk for entry on disk for entry FFii, and move the content , and move the content
of entry to memoryof entry to memory
Close (FClose (Fii)) – move the content of entry – move the content of entry FFii in in
memory to directory structure on diskmemory to directory structure on disk
1010
Open FilesOpen FilesSeveral pieces of data are needed to manage Several pieces of data are needed to manage open files:open files: File pointer: pointer to last read/write location, File pointer: pointer to last read/write location,
per process that has the file openper process that has the file open File-open count: counter of number of times a File-open count: counter of number of times a
file is open – to allow removal of data from open-file is open – to allow removal of data from open-file table when last processes closes itfile table when last processes closes it
Disk location of the file: cache of data access Disk location of the file: cache of data access informationinformation
Access rights: per-process access mode Access rights: per-process access mode informationinformation
1111
Open File LockingOpen File Locking
Provided by some operating systems and Provided by some operating systems and file systemsfile systems
Mediates access to a fileMediates access to a file
Mandatory or advisory:Mandatory or advisory: MandatoryMandatory – access is denied – access is denied
depending on locks held and requesteddepending on locks held and requested AdvisoryAdvisory – processes can find status of – processes can find status of
locks and decide what to dolocks and decide what to do
1212
File Locking Example – Java APIFile Locking Example – Java API
import java.io.*;import java.io.*;import java.nio.channels.*;import java.nio.channels.*;public class LockingExample public class LockingExample { {
public static final boolean EXCLUSIVE = false;public static final boolean EXCLUSIVE = false;public static final boolean SHARED = true;public static final boolean SHARED = true;public static void main(String arsg[]) throws public static void main(String arsg[]) throws IOException IOException { {
FileLock sharedLock = null;FileLock sharedLock = null;FileLock exclusiveLock = null;FileLock exclusiveLock = null;try try { {
continue ==>
1313
File Locking Example – (cont)File Locking Example – (cont)RandomAccessFile raf = new RandomAccessFile("file.txt", RandomAccessFile raf = new RandomAccessFile("file.txt",
"rw");"rw");
// get the channel for the file// get the channel for the file
FileChannel ch = raf.getChannel();FileChannel ch = raf.getChannel();
// this locks the first half of the file - exclusive// this locks the first half of the file - exclusive
exclusiveLock = ch.lock(0, raf.length()/2, exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE);EXCLUSIVE);
/** Now modify the data . . . *//** Now modify the data . . . */
// release the lock// release the lock
exclusiveLock.release();exclusiveLock.release();
continue ==>
1414
File Locking Example – (cont)File Locking Example – (cont)// this locks the second half of the file - shared// this locks the second half of the file - shared
sharedLock = ch.lock(raf.length()/2+1, sharedLock = ch.lock(raf.length()/2+1, raf.length(), raf.length(), SHARED);SHARED);
/** Now read the data . . . *//** Now read the data . . . */// release the lock// release the locksharedLock.release();sharedLock.release();
}} catch (java.io.IOException ioe) {catch (java.io.IOException ioe) { System.err.println(ioe);System.err.println(ioe);
}finally {}finally { if (exclusiveLock != null)if (exclusiveLock != null)exclusiveLock.release();exclusiveLock.release();if (sharedLock != null)if (sharedLock != null)sharedLock.release();sharedLock.release();
} } }} } }
1515
File Types – Name, ExtensionFile Types – Name, Extension
1616
Chapter 10: File-System Chapter 10: File-System InterfaceInterface
File ConceptFile Concept
Access MethodsAccess Methods
Directory StructureDirectory Structure
File-System MountingFile-System Mounting
File SharingFile Sharing
ProtectionProtection
1717
Access MethodsAccess MethodsSequential AccessSequential Access
read nextread nextwrite next write next resetresetno read after last write (rewrite)no read after last write (rewrite)
Direct AccessDirect Accessread read nnwrite write nnposition to position to nn
read nextread nextwrite next write next
rewrite rewrite nnnn = relative block number = relative block number
1818
Sequential-access FileSequential-access File
1919
Simulation of Sequential Access on Simulation of Sequential Access on Direct-access FileDirect-access File
2020
Example of Index and Relative Example of Index and Relative FilesFiles
2121
Chapter 10: File-System Chapter 10: File-System InterfaceInterface
File ConceptFile Concept
Access MethodsAccess Methods
Directory StructureDirectory Structure
File-System MountingFile-System Mounting
File SharingFile Sharing
ProtectionProtection
2222
Directory StructureDirectory StructureA collection of nodes containing A collection of nodes containing information about all filesinformation about all files
F 1 F 2F 3
F 4
F n
Directory
Files
Both the directory structure and the files reside on diskBackups of these two structures are kept on tapes
2323
Disk StructureDisk Structure
Disk can be subdivided into Disk can be subdivided into partitionspartitions
Disks or partitions can be Disks or partitions can be RAIDRAID protected protected against failureagainst failure
Disk or partition can be used Disk or partition can be used rawraw – without a – without a file system, or file system, or formattedformatted with a file systemwith a file system
Partitions also known as minidisks, slicesPartitions also known as minidisks, slices
2424
Disk StructureDisk Structure
Entity containing file system known as a Entity containing file system known as a volumevolume
Each volume containing file system also Each volume containing file system also tracks that file system’s info in a tracks that file system’s info in a device device directorydirectory or or volume table of contentsvolume table of contents
As well as As well as general-purpose file systemsgeneral-purpose file systems there are many there are many special-purpose filespecial-purpose file systemssystems, frequently all within the same , frequently all within the same operating system or computeroperating system or computer
2525
A Typical File-system A Typical File-system OrganizationOrganization
2626
Operations Performed on Operations Performed on DirectoryDirectory
Search for a fileSearch for a file
Create a fileCreate a file
Delete a fileDelete a file
List a directoryList a directory
Rename a fileRename a file
Traverse the file systemTraverse the file system
2727
Organize the Directory (Logically) Organize the Directory (Logically) to Obtainto Obtain
Efficiency – locating a file quicklyEfficiency – locating a file quickly
Naming – convenient to usersNaming – convenient to users Two users can have same name for different Two users can have same name for different
filesfiles The same file can have several different The same file can have several different
namesnames
Grouping – logical grouping of files by Grouping – logical grouping of files by properties, (e.g., all Java programs, all games, properties, (e.g., all Java programs, all games, …)…)
2828
Single-Level DirectorySingle-Level DirectoryA single directory for all usersA single directory for all users
Naming problem
Grouping problem
2929
Two-Level DirectoryTwo-Level DirectorySeparate directory for each userSeparate directory for each user
Path name Can have the same file name for different user
Efficient searching No grouping capability
3030
Tree-Structured DirectoriesTree-Structured Directories
3131
Tree-Structured Directories (Cont)Tree-Structured Directories (Cont)
Efficient searchingEfficient searching
Grouping CapabilityGrouping Capability
Current directory (working directory)Current directory (working directory) cd /spell/mail/progcd /spell/mail/prog type listtype list
3232
Tree-Structured Directories Tree-Structured Directories (Cont)(Cont)
AbsoluteAbsolute or or relativerelative path name path name
Creating a new file is done in the current Creating a new file is done in the current directorydirectory
Delete a fileDelete a file
rm <file-name>rm <file-name>
Creating a new subdirectory is done in the Creating a new subdirectory is done in the current directorycurrent directory
mkdir <dir-name>mkdir <dir-name>
3333
Tree-Structured Directories (Cont)Tree-Structured Directories (Cont)
Example: if in current directory Example: if in current directory /mail/mailmkdir countmkdir count
Deleting “mail” deleting the entire subtree rooted by “mail”
prog copy prtexpcount
3434
Acyclic-Graph DirectoriesAcyclic-Graph DirectoriesHave shared subdirectories and filesHave shared subdirectories and files
3535
Acyclic-Graph Directories (Cont.)Acyclic-Graph Directories (Cont.)Two different names (aliasing)Two different names (aliasing)
If If dictdict deletes deletes listlist dangling pointer dangling pointer
Solutions:Solutions: Backpointers, so we can delete all pointersBackpointers, so we can delete all pointers
Variable size records a problemVariable size records a problem Backpointers using a daisy chain organizationBackpointers using a daisy chain organization Entry-hold-count solutionEntry-hold-count solution
New directory entry typeNew directory entry type LinkLink – another name (pointer) to an existing file – another name (pointer) to an existing file Resolve the linkResolve the link – follow pointer to locate the file – follow pointer to locate the file
3636
General Graph DirectoryGeneral Graph Directory
3737
General Graph Directory (Cont.)General Graph Directory (Cont.)
How do we guarantee no cycles?How do we guarantee no cycles? Allow only links to file not subdirectoriesAllow only links to file not subdirectories Garbage collectionGarbage collection Every time a new link is added use a Every time a new link is added use a
cycle detection algorithm to determine cycle detection algorithm to determine whether it is OKwhether it is OK
3838
Chapter 10: File-System Chapter 10: File-System InterfaceInterface
File ConceptFile Concept
Access MethodsAccess Methods
Directory StructureDirectory Structure
File-System MountingFile-System Mounting
File SharingFile Sharing
ProtectionProtection
3939
File System MountingFile System Mounting
A file system must be A file system must be mountedmounted before it before it can be accessedcan be accessed
A unmounted file system (i.e. Fig. 11-11(b)) A unmounted file system (i.e. Fig. 11-11(b)) is mounted at a is mounted at a mount pointmount point
4040
(a) Existing. (b) Unmounted (a) Existing. (b) Unmounted PartitionPartition
4141
Mount PointMount Point
4242
Chapter 10: File-System Chapter 10: File-System InterfaceInterface
File ConceptFile Concept
Access MethodsAccess Methods
Directory StructureDirectory Structure
File-System MountingFile-System Mounting
File SharingFile Sharing
ProtectionProtection
4343
File SharingFile Sharing
Sharing of files on multi-user systems is Sharing of files on multi-user systems is desirabledesirable
Sharing may be done through a Sharing may be done through a protectionprotection scheme scheme
On distributed systems, files may be On distributed systems, files may be shared across a networkshared across a network
Network File System (NFS) is a common Network File System (NFS) is a common distributed file-sharing methoddistributed file-sharing method
4444
File Sharing – Multiple UsersFile Sharing – Multiple Users
User IDsUser IDs identify users, allowing permissions identify users, allowing permissions and protections to be per-userand protections to be per-user
Group IDsGroup IDs allow users to be in groups, allow users to be in groups, permitting group access rights - useful for permitting group access rights - useful for project work with teamsproject work with teams
4545
File Sharing – Remote File SystemsFile Sharing – Remote File Systems
Uses networking to allow file system access Uses networking to allow file system access between systemsbetween systems Manually via programs like FTPManually via programs like FTP Automatically, seamlessly using Automatically, seamlessly using distributed file distributed file
systemssystems Semi automatically via theSemi automatically via the world wide webworld wide web
4646
File Sharing – Remote File File Sharing – Remote File SystemsSystems
Client-serverClient-server model allows clients to mount model allows clients to mount remote file systems from serversremote file systems from servers Server can serve multiple clientsServer can serve multiple clients Client and user-on-client identification is insecure Client and user-on-client identification is insecure
or complicatedor complicated NFSNFS is standard UNIX client-server file sharing is standard UNIX client-server file sharing
protocolprotocol CIFSCIFS is standard Windows protocol is standard Windows protocol Standard operating system file calls are Standard operating system file calls are
translated into remote callstranslated into remote calls
4747
File Sharing – Remote File File Sharing – Remote File SystemsSystems
Distributed Information Systems Distributed Information Systems (distributed naming services)(distributed naming services) such as such as LDAP, DNS, NIS, Active Directory LDAP, DNS, NIS, Active Directory implement unified access to information implement unified access to information needed for remote computingneeded for remote computing
4848
File Sharing – Failure ModesFile Sharing – Failure Modes
Remote file systems add new failure modes, Remote file systems add new failure modes, due to network failure, server failuredue to network failure, server failure
Recovery from failure can involve state Recovery from failure can involve state information about status of each remote information about status of each remote requestrequest
Stateless protocols such as NFS include all Stateless protocols such as NFS include all information in each request, allowing easy information in each request, allowing easy recovery but less securityrecovery but less security
4949
File Sharing – Consistency File Sharing – Consistency SemanticsSemantics
Consistency semanticsConsistency semantics specify how specify how multiple users are to access a shared file multiple users are to access a shared file simultaneouslysimultaneously Similar to Ch 6 process synchronization Similar to Ch 6 process synchronization
algorithmsalgorithmsTend to be less complex due to disk Tend to be less complex due to disk I/O and network latency (for remote file I/O and network latency (for remote file systemssystems
Andrew File System (AFS) implemented Andrew File System (AFS) implemented complex remote file sharing semanticscomplex remote file sharing semantics
5050
File Sharing – Consistency File Sharing – Consistency SemanticsSemantics
Unix file system (UFS) implements:Unix file system (UFS) implements:
Writes to an open file visible Writes to an open file visible immediately to other users of the same immediately to other users of the same open fileopen file
Sharing file pointer to allow multiple Sharing file pointer to allow multiple users to read and write concurrentlyusers to read and write concurrently
AFS has session semanticsAFS has session semantics
Writes only visible to sessions starting Writes only visible to sessions starting after the file is closedafter the file is closed
5151
Chapter 10: File-System Chapter 10: File-System InterfaceInterface
File ConceptFile Concept
Access MethodsAccess Methods
Directory StructureDirectory Structure
File-System MountingFile-System Mounting
File SharingFile Sharing
ProtectionProtection
5252
ProtectionProtectionFile owner/creator should be able to control:File owner/creator should be able to control: what can be donewhat can be done by whomby whom
Types of accessTypes of access ReadRead WriteWrite ExecuteExecute AppendAppend DeleteDelete ListList
5353
Access Lists and GroupsAccess Lists and GroupsMode of access: read, write, executeMode of access: read, write, executeThree classes of usersThree classes of users
RWXRWXa) a) owner accessowner access 77 1 1 11 1 1
RWXRWXb) b) group accessgroup access 66 1 1 01 1 0
RWXRWXc) c) public accesspublic access 11 0 0 10 0 1
owner group public
chmod 761 game
Attach a group to a file chgrp G game
5454
Access Lists and GroupsAccess Lists and Groups
Mode of access: read, write, executeMode of access: read, write, execute
Three classes of usersThree classes of usersRWXRWX
a) a) owner accessowner access 77 1 1 11 1 1RWXRWX
b) b) group accessgroup access 66 1 1 01 1 0RWXRWX
c) c) public accesspublic access 11 0 0 10 0 1
5555
Access Lists and GroupsAccess Lists and Groups
Ask manager to create a group (unique name), Ask manager to create a group (unique name), say G, and add some users to the group.say G, and add some users to the group.For a particular file (say For a particular file (say gamegame) or subdirectory, ) or subdirectory, define an appropriate access.define an appropriate access.
owner group public
chmod 761 game
Attach a group to a file chgrp G game
5656
Windows XP Access-control List Windows XP Access-control List ManagementManagement
5757
A Sample UNIX Directory A Sample UNIX Directory ListingListing
5858
End of Chapter 10End of Chapter 10