• 沒有找到結果。

11.1 File Concept

N/A
N/A
Protected

Academic year: 2022

Share "11.1 File Concept"

Copied!
42
0
0

加載中.... (立即查看全文)

全文

(1)

Chapter 11 File-System Interface

(2)

2

Outline

• File Concept

• Access Methods

• Directory Structure

• File-System Mounting

• File Sharing

• Protection

(3)

11.1 File Concept

(4)

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

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

(6)

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

(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

(8)

8

A Typical Open-File Table

(9)

Two-Level Open-File Table

File name Location on Disk File Open Count …….

File Pointer …..

File Pointer …..

System-Wide Open File Table Open File Table

for Proc. B

Open File Table for Proc. A

(10)

10

File Types – Name,

Extension

If OS recognizes the type of a file, it can operate on the file in a reasonable way

(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

(12)

12

11.2 Access Methods

(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

(14)

14

Access Methods – Index and

Relative File

(15)

11.3 Directory Structure

(16)

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.

(17)

A Typical File-System

Organization

(18)

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)

(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

(20)

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

(21)

Single-Level Directory

• A single directory for all users.

™ Naming problem

™ Grouping problem

(22)

22

Two-Level Directory

• Separate directory for each user.

™ Path name

™ Can have the same file name for different user

™ Efficient searching

™ No grouping capability

(23)

Tree-Structured Directories

Subdirectory is just a special type of file…

(24)

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

(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

(26)

26

Symbolic VS. Hard Link

(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

(28)

28

General Graph Directory

(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

(30)

30

11.4 File-System Mounting

(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

(32)

32

File-System Mounting

Existing

Un-mounted Partition (/device/disk)

Mount Point

Unavailable when /device/disk is mounted

(33)

11.5 File Sharing

(34)

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

(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

(36)

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

(37)

No Global Naming in NFS

(38)

38

A Simple Automounter for

NFS

(39)

11.6 Protection

(40)

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

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

(42)

42

Access Lists and Groups

(Cont.)

參考文獻

相關文件

– File and index layers organize records on files, and manage the indexing data

The tool to convert user programs from MIPS’s COFF into Nachos’s NOFF format (NOFF: Nachos Object File Format).. Building directories for different

[r]

For any self-financing post-secondary education institutions registered under the Ordinance aspiring to become private universities, we shall maintain the current

存放檔案的 inode 資訊, inode 一旦滿了也一樣會 無法儲存新檔案, inode 會告知檔案所使用的 data block 位置。. Q :如何知道那些 inode 和

Briefing of the home assignment (Designing a plan for e-assessment) Ø  Participants have to complete the assignment before attending Session 2 Ø  File name:

A=fscanf(fid , format, size) reads data from the file specified by file identifier fid , converts it according to the specified format string, and returns it in matrix A..

In addition to speed improvement, another advantage of using a function handle is that it provides access to subfunctions, which are normally not visible outside of their