Top Banner
1 Chapter 11 File-System Interface
42

Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

Jun 06, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

1

Chapter 11 File-System Interface

Page 2: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

2

Outline

• File Concept• Access Methods• Directory Structure • File-System Mounting• File Sharing• Protection

Page 3: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

3

11.1 File Concept

Page 4: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

4

Introduction

• OS abstracts from the physical storage devices to define a logical storage unit: File

• Types: – Data: numeric, alphabetic, alphanumeric, binary– Program: source and object form

Page 5: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

5

File Attributes

• Name – only information kept in human-readable form• Type – needed for systems that support different types• Location – pointer to file location on device• Size – current file (and the maximum allowable) size• Protection – controls who can read, write, execute• 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 physical storage device.

Page 6: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

6

File Operations

• Create– Allocate space– Make an entry in the directory

• Write – Search the directory– Write is to take place at the

location of the write pointer• Read

– Search the directory– Read is to take place at the

location of the read pointer• Reposition within file – file seek

– Set the current file pointer to a given value

• Delete– Search the directory– Release all file space

• Truncate --– All attributes to remain unchanged,

but for the file to be reset to length zero

• Open(Fi)– Search the directory structure on

disk for Fi– Move the content of the directory

entry to memory• Close(Fi)

– move the content of entry Fi in memory to directory structure on disk

Page 7: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

7

Open-File Table

• OS keeps a small table containing information about all open files– Each time a file is opened, the content of the directory entry of the

file is moved into the table• File Handle (file descriptor, file control block): an index into the

table for a file• Two levels of internal tables in multi-user OS

– Per-process table: All the files opened by a process• Current file pointer

– System-wide open-file table: Process independent information• Location of file on disk, access dates, file size• File open count

Page 8: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

8

A Typical Open-File Table

Page 9: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

9

Two-Level Open-File Table

File name Location on Disk File Open Count …….

File Pointer …..

File Pointer …..

System-Wide Open File TableOpen File Table for Proc. B

Open File Table for Proc. A

Page 10: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

10

File Types – Name, Extension If OS recognizes the type of a file, it can

operate on the file in a reasonable way

Page 11: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

11

File Structure

• None - sequence of words, bytes• Simple record structure

– Lines – Fixed length– Variable length

• Complex Structures– Formatted document– Relocatable load file

• All operating systems must support at least one structure – that of an executable file

• Who decides:– Operating system– Program

Page 12: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

12

11.2 Access Methods

Page 13: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

13

Access Methods

• Sequential Access: information is processed in order– read next– write next (append to the end of the file)– reset to the beginning of file– skip forward or backward n records

• Direct Access: a file is made up of fixed length logical blocks or records– read n– write n– position to n– read next– write next – rewrite n

Sequential-access file

Page 14: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

14

Access Methods – Index and Relative File

Page 15: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

15

11.3 Directory Structure

Page 16: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

16

Directory Structure

• A collection of nodes containing information about all files.• Both the directory structure and the files reside on disk.• Backups of these two structures are kept on tapes.

Page 17: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

17

A Typical File-System Organization

Page 18: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

18

Information in a Device Directory

• Name • Type: file, directory, symbolic link, special file…• Address: device blocks to store a file• Current length• Maximum length• Date last accessed (for archival)• Date last updated (for dump)• Owner ID (who pays)• Protection information (discuss later)

Page 19: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

19

Operations Performed on Directory

• Search for a file• Create a file• Delete a file• List a directory• Rename a file• Traverse the file system

Page 20: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

20

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 Pascal programs, all games, …)

Page 21: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

21

Single-Level Directory

• A single directory for all users.

Naming problemGrouping problem

Page 22: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

22

Two-Level Directory

• Separate directory for each user.

Path nameCan have the same file name for different userEfficient searchingNo grouping capability

Page 23: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

23

Tree-Structured Directories

Subdirectory is just a special type of file…

Page 24: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

24

Tree-Structured Directories (Cont.)

• Efficient searching• Grouping Capability• Current directory (working directory)

– cd /spell/mail/prog– cat list

• Create a new file/subdirectory is done in current directory • Absolute path name & relative path name• How to handle the deletion of a directory

Page 25: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

25

Acyclic-Graph Directories

• Can have shared subdirectories and files.– A shared file can have different

names (aliasing)• Shared file implementation

– Symbolic link: a pointer to another file or directory

• ln -s /spell/count /dict/count– Hard link: duplicate all

information (especially device address) in shared directory

/spell/count

Page 26: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

26

Symbolic VS. Hard Link

Page 27: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

27

Acyclic-Graph Directories (Cont.)

• If /dict/w/list is deleted ⇒ dangling pointer.• Solutions: Preserve the file until all references to it are

deleted– Backpointers: a list of all references to a file (directory entries or

symbolic links) • Variable size records a problem

– Entry-hold-count solution: a count• A count of the number of references• Used in UNIX for hard links

Page 28: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

28

General Graph Directory

Page 29: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

29

General Graph Directory (Cont.)

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

algorithm to determine whether it is OK

• Traversal problem…– Don’t traverse the same directory or file twice

Page 30: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

30

11.4 File-System Mounting

Page 31: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

31

File-System Mounting

• A file system must be mounted before it can be accessed• A file system is mounted at a directory called the mount

point • Mounting steps: mount /device/dsk /users

– Give the device name and the mount point– Verify that the device contains a valid file system

• Check if the device directory has a valid format– OS notes that a file system is mounted at the specified mount point

• What if the mount-point contains files?– The original files are not available, until the file system is un-mounted

• Same file system can be mounted repeatedly, at different mount points

Page 32: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

32

File-System Mounting

ExistingUn-mounted

Partition(/device/disk)

Mount Point

Unavailable when /device/disk is mounted

Page 33: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

33

11.5 File Sharing

Page 34: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

34

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• A remote file system must be mounted before using

– mount claven.lib.nctu.edu.tw:/OS /chow/book– Once files are mounted, they are accessed by using the

concatenated logical path names without referencing either the remote hosts or local devices

Page 35: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

35

Remote File-System Mounting Example

root

chow

paper book

root

OS

DFS DSM

Local Client Remote Server

Export

Mount

DFS DSM /chow/book/DSM

/OS/DSM

Page 36: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

36

Remote File-System Mounting

• Different clients may perceive a different FS view– To achieve a global FS view – SA enforces mounting rules

• Export: a file server restricts/allows the mounting of all or parts of its file system to a predefined set of hosts– The information is kept in the server’s export file

• File system mounting:– Explicit mounting: clients make explicit mounting system calls

whenever one is desired– Boot mounting: a set of file servers is prescribed and all mountings

are performed the client’s boot time– Auto-mounting: mounting of the servers is implicitly done on demand

when a file is first opened by a client

Page 37: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

37

No Global Naming in NFS

Page 38: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

38

A Simple Automounter for NFS

Page 39: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

39

11.6 Protection

Page 40: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

40

Protection

• File owner/creator should be able to control– What can be done– By whom

• Types of access– Read– Write– Execute– Append– Delete– List

Page 41: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

41

Access Lists and Groups

• Mode of access: read, write, execute• Three classes of users: owner, group, universe

– User name and user identifier– Group name and group identifier

• 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

• In UNIX: three field of 3 bits each– field: read, write, execute– Bits: r(4), w(2), x(1)

Page 42: Chapter 11 File-System Interface - 國立臺灣大學d92005/OS 2008/ch11.pdf · File-System Mounting • A file system must be mounted before it can be accessed • A file system

42

Access Lists and Groups (Cont.)