• 沒有找到結果。

Operating System: Chap10 File System Interface

N/A
N/A
Protected

Academic year: 2021

Share "Operating System: Chap10 File System Interface"

Copied!
37
0
0

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

全文

(1)

Operating System:

Chap10 File System Interface

National Tsing-Hua University

2016, Fall Semester

(2)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 2

Overview

File Concept

Access Methods

Directory Structure

File System Mounting

File Sharing

Protection

(3)

File Concept

File : a logical storage unit created by OS

v.s. physical storage unit in disk ( sector, track )

File attributes

Identifier: non-human-readable name

Name

Type

Location

Size

sector track

platter

(4)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 4

File Operations

File operations include

Creating a file

Writing a file

Reading a file

Repositioning within a file (i.e. file seek)

Deleting a file

Truncating a file

Process: open-file table

OS: system-wide table

(5)

Open-File Tables

Per-process table

Tracking all files opened by this process

Current file pointer for each opened file

Access rights and accounting information

System-wide table

Each entry in the per-process table points to this table

Process-independent information such as disk location, access dates, file size

Open count

files

P1 PCB Open-file table a.txt

b.txt

System open-file table

(6)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 6

Open File Attributes

Open-file attributes (metadata)

File pointer (per-process)

File open count (system table)

Disk location (system table)

Access rights (per-process)

File types

.exe, .com, .obj, .cc, .mov, etc

Hint for OS to operate file in a reasonable way

(7)

Access Method

(8)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 8

Access Methods

Sequential access

Read/write next (block)

Reset: repositioning the file pointer to the beginning

Skip/rewind n records

(9)

Access Methods

Direct (relative) access

Access an element at an arbitrary position in a sequence

File operations include the block # as parameter

Often use random access to refer the access pattern from direct access

(10)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 10

Index Access Methods

Index: contains pointers to blocks of a file

To find a record in a file:

search the index file  find the pointer

use the pointer to directly access the record

With a large file  index could become too large

(11)

Review Slides ( I )

File vs. Sector, Track

Open-file (in-memory) attributes

Per-process, system-wide?

File-access methods?

Sequential access

Direct access

Index access

(12)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 12

Directory Structure

(13)

Partition, Volume & Directory

A partition (formatted or raw)

raw partition (no file system): UNIX swap space, database

Formatted partition with file system is called volume

a partition can be a portion of a disk or group of multiple disks (distributed file system)

Some storage devices (e.g.: floppy disk) does not and cannot have partition

Directories are used by file system to store the

(14)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 14

File-System Organization

(15)

Directory vs. File

Directory: A collection of nodes containing information about all files

Both the directory structure and the files reside on disk

(16)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 16

Directory Operations

Search for a file

Create a file

Delete a file

List a directory

Rename a file

Traverse the file system

(17)

Single-Level Directory

All files in one directory

Filename has to be unique

Poor efficiency in locating a file as number of files

(18)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 18

Two-Level Directory

a separate dir for each user

path = user name + file name

single-level dir problems still exists per user

(19)

Tree-Structured Directory

Absolute path : starting from the root

Relative path : starting from a directory

current

(20)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 20

Acyclic-Graph Directory

Use links to share files or directories

UNIX-like: symbolic link (ln -s /spell/count /dict/count)

A file can have multiple absolute paths

When does a file actually get deleted?

deleting the link but not the file

deleting the file but leaves the link  dangling pointer

 deleting the file when reference counters is 0

(21)

General-Graph Directory

(22)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 22

General-Graph Directory

May contain cycles

Reference count does not work any more

E.g. self-referencing file

How can we deal with cycles?

Garbage collection

First pass traverses the entire graph and marks accessible files or directories

Second pass collect and free everything that is un-marked

 Poor performance on millions of files …

Use cycle-detection algorithm when a link is created

/

home bin

g1 g2

t1

(23)

Review Slides ( II )

Directory structure: pros & cons

One-level directory

Two-level directory

Tree-structured directory

Acyclic-graph directory

General-graph directory

(24)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 24

File-System Mounting &

File Sharing

(25)

File System Mounting

A file system must be mounted before it can be accessed

Mount point : the root path that a FS will be mounted to

Mount timing:

boot time

automatically at run-time

(26)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 26

File System Mounting Example

/

local usr home

jane john

games

/home/john/games Partition A

Partition C Partition B

(27)

Root Info local

m usr

P1

Root Info students m home

P2

Root Info P3

\

usr local

…...

…...

students home

…...

P3

m usr m home

P2

m home

…...

students home

…...

Mount Table

usr P2

P3 home

Linux command: mount -t type device dir mount –t ext2 /dev/sda0 /mnt mnt

m mnt

P4 mnt

(28)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 28

File Sharing on Multiple Users

Each user: (userID, groupID)

ID is associated with every ops/process/thread the user issues

Each file has 3 sets of attributes

owner, group, others

Owner attributes describe the privileges for the owner of the file

same for group/others attributes

group/others attributes are set by owner or root

group1

group2

group3

Owner Other users

Group user

(29)

Access-Control List

We can create an access-control list (ACL) for each user

check requested file access against ACL

problem: unlimited # of users

3 classes of users  3 ACL ( RWX ) for each file

owner (e.g. 7 = RWX = 111)

group (e.g. 6 = RWX = 110)

public (others) (e.g. 4 = RWX = 100) chmod 664 intro.ps

(30)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 30

File Protection

File owner/creator should be able to control

what can be done

by whom

 Access control list (ACL)

Files should be kept from

physical damage (reliability): i.e. RAID

improper access (protection): i.e. password

(31)

Review Slides ( III )

File system mounting point, timing?

Access-control list? How does it function?

(32)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 32

Reading Material & HW

Chap 10

Problems

10.1: Consider a file system where a file can be deleted and its disk space reclaimed while links to that file still exist.

What problems may occur if a new file is created in the same storage area or with the same absolute path name?

How can these problems be avoided?

10.4: Provide examples of applications that typically access files according to “sequential” and “random”.

10.6: If the operating system knew that a certain application was going to access file data in a sequential manner, how could it exploit this information to improve performance?

(33)

Consistency Semantics

When files are shared, ops from different users to the same file must be synchronized

UNIX semantics

write is visible to all other users opening the same file

Open-file option: share the same file pointer

Session semantics (AFS file system)

write is not visible to all other users

once a file is closed, changes are visible for sessions

(34)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 34

File Sharing on Remote File Systems

Uses networking to allow file system access between systems

Manually via programs like FTP

Semi automatically via the world wide web

Automatically, seamlessly using distributed

file systems

(35)

Client-server model

Allows clients to mount remote file systems from servers

Sever : the machine that owns the files and serves multiple clients

Client: the machine that accesses remote files

Standard OS file calls are translated into remote calls

Client and user-on-client identification is insecure or complicated

Example:

(36)

Chapter10 FS Interface Operating System Concepts – NTHU LSA Lab 36

Distributed Information Systems

Distributed naming services

Provide unified access to the info for remote computing

Clusters/

Datacenters Frontend nodes Client side

Server side DIS:

DNS (Domain Name System) NIS (Network Info Service)

(37)

Failure Modes

Failures:

HW: disk, network cable, switch, server, etc.

SW: corruption or inconsistency of file, directory structure, etc.

We need to recover:

Data: files, directory contents

Metadata: data and system management info.

Stateful vs. Stateless communication protocol:

Stateless: treats each request as an independent transaction

參考文獻

相關文件

* All rights reserved, Tei-Wei Kuo, National Taiwan University,

* All rights reserved, Tei-Wei Kuo, National Taiwan University,

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005!.

Tei-Wei Kuo, Embedded System and Wireless Networking Lab, National Taiwan University.. Real-Time

– Transfers operating system from mass storage to main memory. – Executes jump to

Technique Work Webmaster Group Account Manager Group Monitoring and Client Group PC Manager Group. Non-Technique Work 215 management property/purchase fix

– Runs replay mode to search for a solution – Reports to the user to run observation

‡網路作業系統( network operating system). ‡網路作業系統( network