Chapter 10: File System...

Preview:

Citation preview

Southeast University 10.1

Chapter 10: File System Interface

Operating System Concepts

张竞慧 办公室:计算机楼366室

电邮:jhzhang@seu.edu.cn 主页:http://cse.seu.edu.cn/PersonalPage/zjh/

电话:025-52091017

Southeast University 10.2 Operating System Concepts

Chapter 10: File-System Interface

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

Southeast University 10.3 Operating System Concepts

File Attributes

Name – only information kept in human-readable form.

Identifier – unique tag/number, identifies the file in the file system.

Type – needed for systems that support different types.

Location – pointer to file location on device. Size – current file size.

Southeast University 10.4 Operating System Concepts

File Attributes (Cont.)

Protection – controls who can do reading, writing, executing.

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

Southeast University 10.5

(a) fixed-size entries with the disk addresses and attributes (DOS) (b) each entry refers to an i-node. Directory entry contains

attributes. (Unix)

Implementing Directories structure

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Southeast University 10.6 Operating System Concepts

Implementing Directories structure

Southeast University 10.7 Operating System Concepts

File Operations

Create Write Read Reposition within file – file seek Delete Truncate

Southeast University 10.8 Operating System Concepts

File Operations (Cont.)

Open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory.

Close (Fi) – move the content of entry Fi in memory to directory structure on disk.

Southeast University 10.9

File Operations (Cont.)

File locking Advisory locking: requires cooperation from the

participating processes Mandatory locking: causes the kernel to check

every open, read, and write to verify that the calling process isn’t violating a lock on the given file

Operating System Concepts

Southeast University 10.10 Operating System Concepts

File Types – Name, Extension

Southeast University 10.11 Operating System Concepts

Access Methods Sequential Access access- read from the beginning, can’t skip around Corresponds to magnetic tape

Direct Access Random access- start where you want to start Came into play with disks

Southeast University 10.12 Operating System Concepts

Simulation of Sequential Access on a Direct-access File

Southeast University 10.13 Operating System Concepts

Directory Structure

disks are split into one or more partitions.

each partition contains information about files within it

The information is kept in entries in a device directory or volume table of contents

Southeast University 10.14 Operating System Concepts

A Typical File-system Organization

Southeast University 10.15 Operating System Concepts

Operations Performed on Directory

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

Southeast University 10.16 Operating System Concepts

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

Southeast University 10.17 Operating System Concepts

Single-Level Directory

A single directory for all users.

Naming problem Grouping problem

Southeast University 10.18 Operating System Concepts

Two-Level Directory Separate directory for each user.

•Path name •Can have the same file name for different user •Efficient searching •No grouping capability

Southeast University 10.19 Operating System Concepts

Tree-Structured Directories

Southeast University 10.20 Operating System Concepts

Tree-Structured Directories (Cont.)

Efficient searching

Grouping Capability

Current directory (working directory) cd /spell/mail/prog type list

Southeast University 10.21 Operating System Concepts

Absolute or relative path name

Creating a new file is done in current directory.

Delete a file rm <file-name>

Southeast University 10.22 Operating System Concepts

Tree-Structured Directories (Cont.)

Creating a new subdirectory is done in current directory. mkdir <dir-name>

Example: if in current directory /mail mkdir count

mail

prog copy prt exp count

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

Southeast University 10.23 Operating System Concepts

Acyclic-Graph Directories Have shared subdirectories and

files.

Southeast University 10.24 Operating System Concepts

Acyclic-Graph Directories (Cont.)

Two different names (aliasing)

If dict deletes count ⇒ dangling pointer. Solutions: Backpointers, so we can delete all pointers.

Entry-hold-count solution.

Southeast University 10.25

A UNIX directory tree.

Operating System Concepts

Southeast University 10.26

Example: Linux hard link and soft link

Explained following: https://www.ibm.com/developerworks/cn/linux/l-

cn-hardandsymb-links/

Operating System Concepts

Southeast University 10.27 Operating System Concepts

General Graph Directory

Southeast University 10.28 Operating System Concepts

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.

Southeast University 10.29 Operating System Concepts

File System Mounting

A file system must be mounted before it can be accessed.

An unmounted file system (I.e. Fig. 11-11(b)) is mounted at a mount point.

Southeast University 10.30 Operating System Concepts

(a) Existing. (b) Unmounted Partition

Southeast University 10.31 Operating System Concepts

Mount Point

Southeast University 10.32

Example: Mounting iso file under Linux

Operating System Concepts

mkdir -p /mnt/disk mount -o loop disk1.iso /mnt/disk umount /mnt/disk

Southeast University 10.33 Operating System Concepts

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.

Southeast University 10.34

NFS usage example

NFS server: directory to be shared [root@c01n08 tmp]# vi /etc/exports /tmp *(rw,no_root_squash)

[root@c01n08 tmp]# service nfs restart

NFS client: access the shared directory [root@c01n09 ~]# mkdir tmp [root@c01n09 ~]# mount -t nfs c01n08:/tmp tmp

Operating System Concepts

Southeast University 10.35 Operating System Concepts

Protection File owner/creator should be able to control: what can be done by whom

Types of access Read Write Execute Append Delete List

Southeast University 10.36 Operating System Concepts

Access Lists and Groups Mode of access: read, write, execute Three classes of users RWX a) owner access 7 ⇒ 1 1 1

b) group access 6 ⇒ 1 1 0 c) public access 1 ⇒ 0 0 1 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. owner group public

chmod 761 game Attach a group to a file chgrp G game

Southeast University 10.37 Operating System Concepts

A Sample UNIX Directory Listing

Southeast University 10.38

Directory access permission

做实验证明: root$ mkdir test/d1 -p root$ touch test/f1 root$ echo "test" > test/f2

验证读权限: root$ chmod 004 test (r读权限) robin$ ls test (可以看到d1, f1, f2) robin$ cat test/f2 (Permission denied) root$ chmod 005 test (rx读执行权限) robin$ cat test/f2 (看到“test”了)

Operating System Concepts

Southeast University 10.39

Directory access permission

验证执行权限: root$ chmod 001 test (执行权限) robin$ ls test (这边没有东西了哦!) robin$ cat test/f2(可以看到“test”)

验证写权限: root$ chmod 002 (w写权限) robin$ echo "test2" > test/f3 (Permission denied) root$ chmod 003 (wx写执行权限) robin$ echo "test2" > test/f3 (成功)

Operating System Concepts

Southeast University 10.40 Operating System Concepts

Windows XP Access-control List Management

Recommended