Chapter 11: File-System Interface
description
Transcript of Chapter 11: File-System Interface
-- 1--Operating System Concepts
Chapter 11: File-System InterfaceChapter 11: File-System Interface
File ConceptFile Concept
Access MethodsAccess Methods
Directory StructureDirectory Structure
File System MountingFile System Mounting
File Sharing File Sharing
ProtectionProtection
-- 2--Operating System Concepts
File ConceptFile Concept
A named collection of related informationA named collection of related information
Types: Types: Data
numeric character binary
Program
-- 3--Operating System Concepts
File StructureFile Structure
None - sequence of words, bytesNone - sequence of words, bytes Simple record structureSimple record structure
Lines Fixed length Variable length
Complex StructuresComplex Structures Formatted document Relocatable load file
Who decides:Who decides: Operating system Program
-- 4--Operating System Concepts
File AttributesFile Attributes
NameName – only information kept in human-readable – only information kept in human-readable form.form.
TypeType – needed for systems that support different – needed for systems that support different types.types.
LocationLocation – pointer to file location on device. – pointer to file location on device. SizeSize – current file size. – current file size. ProtectionProtection – controls who can do reading, writing, – controls who can do reading, writing,
executing.executing. TimeTime, , datedate, , and user identificationand user identification – data for – data for
protection, security, and usage monitoring.protection, security, and usage monitoring. Information about files are kept in the directory Information about files are kept in the directory
structure, which is maintained on the disk.structure, which is maintained on the disk.
-- 5--Operating System Concepts
File OperationsFile Operations
CreateCreate WriteWrite ReadRead Reposition within file – file seekReposition within file – file seek DeleteDelete Truncate(erase the contents)Truncate(erase the contents) Open(Open(FFii) – search the directory structure on disk for ) – search the directory structure on disk for
entry entry FFii, and move the content of entry to memory., and move the content of entry to memory. Close (Close (FFii) – move the content of entry ) – move the content of entry FFii in memory in memory
to directory structure on disk.to directory structure on disk.
-- 6--Operating System Concepts
Open-file table
CreateCreate OS maintains a open-file table to contain
information about open files In multitask environment, per-process
open-file table and system-wide open-file table
Information about a open file File pointer:current position for file accessing File open count:count of processes that open
that file Disk location of the file Access rights
-- 7--Operating System Concepts
File Types – Name, ExtensionFile Types – Name, Extension
-- 8--Operating System Concepts
Access MethodsAccess Methods
Sequential AccessSequential Accessread nextread nextwrite next write next resetreset
Direct AccessDirect Accessread nread nwrite nwrite nposition to nposition to n
read nextread nextwrite next write next
((nn = relative block = relative block number)number)
-- 9--Operating System Concepts
Sequential-access FileSequential-access File
-- 10--Operating System Concepts
Simulation of Sequential Access on a Direct-access FileSimulation of Sequential Access on a Direct-access File
-- 11--Operating System Concepts
Other access methods:use of IndexOther access methods:use of Index
-- 12--Operating System Concepts
Directory StructureDirectory Structure
A collection of entries containing information about all files.A collection of entries 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.
-- 13--Operating System Concepts
A Typical File-system OrganizationA Typical File-system Organization
-- 14--Operating System Concepts
Information in a Device DirectoryInformation in a Device Directory
Name Name TypeType Address Address Current lengthCurrent length Maximum lengthMaximum length Date last accessed (for archival)Date last accessed (for archival) Date last updated (for dump)Date last updated (for dump) Owner ID (who pays)Owner ID (who pays) Protection information Protection information
-- 15--Operating System Concepts
Operations Performed on DirectoryOperations Performed on Directory
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
-- 16--Operating System Concepts
Organize the Directory (Logically) to ObtainOrganize the Directory (Logically) to Obtain
EfficiencyEfficiency – locating a file quickly. – locating a file quickly. NamingNaming – convenient to users. – convenient to users.
Two users can have same name for different files. The same file can have several different names.
GroupingGrouping – logical grouping of files by properties, – logical grouping of files by properties, (e.g., all Java programs, all games, …)(e.g., all Java programs, all games, …)
-- 17--Operating System Concepts
Single-Level DirectorySingle-Level Directory
A single directory for all users.A single directory for all users.
Naming problem
Grouping problem
-- 18--Operating System Concepts
Two-Level DirectoryTwo-Level Directory
Separate directory for each user.Separate directory for each user.
•Path name•Can have the same file name for different user•Efficient searching•No grouping capability
-- 19--Operating System Concepts
Tree-Structured DirectoriesTree-Structured Directories
-- 20--Operating System Concepts
Tree-Structured Directories (Cont.)Tree-Structured Directories (Cont.)
Efficient searchingEfficient searching
Grouping CapabilityGrouping Capability
Current directory (working directory)Current directory (working directory) cd
-- 21--Operating System Concepts
Tree-Structured Directories (Cont.)Tree-Structured Directories (Cont.)
AbsoluteAbsolute or or relativerelative path name path name Creating a new file is done in current directory.Creating a new file is done in current directory. Delete a fileDelete a file
rmrm <file-name> <file-name> Creating a new subdirectory is done in current Creating a new subdirectory is done in current
directory.directory.mkdir <dir-name>
Example: if in current directory Example: if in current directory /mail/mailmkdirmkdir count count
prog copy prt exp count
Deleting “mail” deleting the entire subtree rooted by “mail”.
-- 22--Operating System Concepts
Acyclic-Graph DirectoriesAcyclic-Graph Directories
Have shared subdirectories and files.Have shared subdirectories and files.
-- 23--Operating System Concepts
Acyclic-Graph Directories (Cont.)Acyclic-Graph Directories (Cont.)
Two different names (aliasing)Two different names (aliasing)
Deletion of a link may cause dangling(Deletion of a link may cause dangling( 摇摆摇摆 ) ) pointer.pointer.
-- 24--Operating System Concepts
General Graph DirectoryGeneral Graph Directory
-- 25--Operating System Concepts
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 subdirectories. Garbage collection. Every time a new link is added use a cycle
detectionalgorithm to determine whether it is OK.
-- 26--Operating System Concepts
File System MountingFile System Mounting
A file system must be A file system must be mountedmounted before it can be before it can be accessed.accessed.
A unmounted file system (I.e. Fig. 11-11(b)) is A unmounted file system (I.e. Fig. 11-11(b)) is mounted at a mounted at a mount pointmount point..
-- 27--Operating System Concepts
((a) Existing. (b) Unmounted Partitiona) Existing. (b) Unmounted Partition
-- 28--Operating System Concepts
Mount PointMount Point
-- 29--Operating System Concepts
File SharingFile Sharing
Sharing of files on multi-user systems is desirable.Sharing of files on multi-user systems is desirable.
Sharing may be done through a Sharing may be done through a protectionprotection scheme. scheme.
On distributed systems, files may be shared across a On distributed systems, files may be shared across a network.network.
Network File System (NFS) is a common distributed Network File System (NFS) is a common distributed file-sharing method.file-sharing method.
-- 30--Operating System Concepts
ProtectionProtection
File owner/creator should be able to control:File owner/creator should be able to control: what can be done by whom
Types of accessTypes of access Read Write Execute Append Delete List
-- 31--Operating System Concepts
Access Lists and GroupsAccess Lists and Groups Mode of access: read, write, executeMode of access: read, write, execute Three classes of usersThree classes of users
RWXRWXa) a) owner accessowner access 77 1 1 11 1 1RWXRWXb) b) group accessgroup access 66 1 1 01 1 0RWXRWXc) c) public accesspublic access 11 0 0 10 0 1
Ask manager to create a group (unique name), say G, Ask manager to create a group (unique name), say G, and add some users to the group.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