Chapter 11: File-System Interface

31
-- 1-- Operating System Concepts Chapter 11: File-System Chapter 11: File-System Interface Interface File Concept File Concept Access Methods Access Methods Directory Structure Directory Structure File System Mounting File System Mounting File Sharing File Sharing Protection Protection

description

Chapter 11: File-System Interface. File Concept Access Methods Directory Structure File System Mounting File Sharing Protection. File Concept. A named collection of related information Types: Data numeric character binary Program. File Structure. None - sequence of words, bytes - PowerPoint PPT Presentation

Transcript of Chapter 11: File-System Interface

Page 1: 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

Page 2: Chapter 11:  File-System Interface

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

Page 3: Chapter 11:  File-System Interface

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

Page 4: Chapter 11:  File-System Interface

-- 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.

Page 5: Chapter 11:  File-System Interface

-- 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.

Page 6: Chapter 11:  File-System Interface

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

Page 7: Chapter 11:  File-System Interface

-- 7--Operating System Concepts

File Types – Name, ExtensionFile Types – Name, Extension

Page 8: Chapter 11:  File-System Interface

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

Page 9: Chapter 11:  File-System Interface

-- 9--Operating System Concepts

Sequential-access FileSequential-access File

Page 10: Chapter 11:  File-System Interface

-- 10--Operating System Concepts

Simulation of Sequential Access on a Direct-access FileSimulation of Sequential Access on a Direct-access File

Page 11: Chapter 11:  File-System Interface

-- 11--Operating System Concepts

Other access methods:use of IndexOther access methods:use of Index

Page 12: Chapter 11:  File-System Interface

-- 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.

Page 13: Chapter 11:  File-System Interface

-- 13--Operating System Concepts

A Typical File-system OrganizationA Typical File-system Organization

Page 14: Chapter 11:  File-System Interface

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

Page 15: Chapter 11:  File-System Interface

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

Page 16: Chapter 11:  File-System Interface

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

Page 17: Chapter 11:  File-System Interface

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

Page 18: Chapter 11:  File-System Interface

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

Page 19: Chapter 11:  File-System Interface

-- 19--Operating System Concepts

Tree-Structured DirectoriesTree-Structured Directories

Page 20: Chapter 11:  File-System Interface

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

Page 21: Chapter 11:  File-System Interface

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

mail

prog copy prt exp count

Deleting “mail” deleting the entire subtree rooted by “mail”.

Page 22: Chapter 11:  File-System Interface

-- 22--Operating System Concepts

Acyclic-Graph DirectoriesAcyclic-Graph Directories

Have shared subdirectories and files.Have shared subdirectories and files.

Page 23: Chapter 11:  File-System Interface

-- 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.

Page 24: Chapter 11:  File-System Interface

-- 24--Operating System Concepts

General Graph DirectoryGeneral Graph Directory

Page 25: Chapter 11:  File-System Interface

-- 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.

Page 26: Chapter 11:  File-System Interface

-- 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..

Page 27: Chapter 11:  File-System Interface

-- 27--Operating System Concepts

((a) Existing. (b) Unmounted Partitiona) Existing. (b) Unmounted Partition

Page 28: Chapter 11:  File-System Interface

-- 28--Operating System Concepts

Mount PointMount Point

Page 29: Chapter 11:  File-System Interface

-- 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.

Page 30: Chapter 11:  File-System Interface

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

Page 31: Chapter 11:  File-System Interface

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