您的位置:首页 > 其它

操作系统概念(第十章) 文件系统接口

2015-12-23 20:20 211 查看


文件概念

文件是记录在外存上得相关信息的具有名称的集合。其具有连续的逻辑地址空间

通常,文件表示数据程序

数据文件可以包括,数字、字符、字符串或二进制。文件可以是自由形式,如文本文件,也可以具有严格的格式。

文件必须具有可以长期信息存储的性质、必须能够保存大容量数据、在进程终止后信息能够保留下来、能够多进程并发访问文件中的信息。



其中a是执行文件,b是文档文件。

文件属性(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 size.

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

Time, date, and user identification – data for protection, security, and usage monitoring.

文件的属性信息保存在硬盘上的目录结构中

文件结构

None - sequence of words, bytes无序的字,字节

Simple record structure简单记录结构

Lines 行

Fixed length固定长度

Variable length变长

Complex Structures复杂结构

Formatteddocument 格式文档

Relocatable load file 可重定位装载文件

Can simulate last two with first method by inserting appropriate control characters.

由程序和操作系统决定文件的结构。

文件的操作(File Operations)

Create 创建

Write 写

Read 读

Reposition within file – file seek 定位

Delete 删除

Truncate 截断

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.

扩展名(File Types – Name, Extension)



访问方法

顺序(Sequential Access)

read next
write next
reset
noread after last write
(rewrite)




随机(Random Access)

read n
write n
position to n
read next
write next
rewrite n


其中n表示相关的块(block)数。

其他访问方式

其他访问方式可建立在直接访问方式上,这些访问通常涉及创建文件索引。索引包括各块的指针。为了查找文件中的记录,首先搜索索引,再根据指针直接访问文件,以查找所需要的内容。

索引及其对应文件关系如下图所示。



有很多例题考察一级索引、二级索引之类的。

里面有很多的内容,所以需要更加仔细地看题。

目录结构(Directory Structure)

目录是一个包含若干文件属性信息的节点的集合,结构如下图所示。



目录和文件都保存在磁盘上。逻辑卷(可跨磁盘)的概念

有时候需要在一个磁盘上装多种文件系统,这些部分称为分区(partition)或者片。



设备上目录中的文件属性信息

Name

Type

Address

Current length当前长度

Maximum length最大长度

Date last accessed (for archival)最后访问日期

Date last updated (for dump)最后更新

Owner ID (who pays)属主ID

Protection information (discuss later)

对目录的操作

Search for a file查找文件

Create a file创建文件

Delete a file删除文件

List a directory罗列目录内容

Rename a file文件重命名

Traverse the file system遍历文件系统

组织目录的目标

高效(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, …)

单级目录(Single-Level Directory)



在一个目录下存在:

命名问题:文件位于同一个目录下,他们必须具有唯一名称。

分组问题

两级目录(Two-Level Directory)

对于双层结构目录的结构,每个用户都有自己的用户文件目录(user file directory,UFD)

因此在每个UFD中所有的文件名称唯一即可,不同的用户可以有相同拥有文件名的问题。



虽然双层结构目录解决了名称冲突问题,但是它仍有缺点。这种解耦股有效地对用户加以隔离。这种隔离在用户需要完全独立时是有点,但是在用户需要在某个任务上进行合作和访问其他文件时却是一个缺点。

为了访问指定的文件唯一,用户必须知道要访问文件的路径名(path name)

树型目录(Tree-Structured Directories)



高效的搜索(Efficient searching)

分组能力(Grouping Capability)

当前目录(Current directory / working directory)

路径名有两种形式:绝对路径和相对路径。

无环图目录(Acyclic-Graph Directories)



这样对于相同的文件可能有不同的名字,因此有别名。一个文件也可有多个绝对路径名。

如果文件被删除,这样可能会留下悬挂指针指向不再存在的文件,更为糟糕的是,这些剩余文件指针可能指向包括实际磁盘地址,而该空间可能正在被其他文件使用。

通用图目录(General Graph Directory)



采用五环图解耦股的一个特别重要的问题是如何保证没有环。

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.

建立新连接时进行循环检测

文件共享(Two-Level Directory)

Sharing of files on multi-user systems is desirable.

对多用户系统尤其必要

Sharing may be done through a protectionscheme.

通过“保护”系统实现

On distributed systems, files may be shared across a

network.

在分布式系统中,文件甚至可通过网络共享

Network File System (NFS)网络文件系统is a common

distributed file-sharing method.

NFS是一种普遍的分布式文件共享方式

保护

文件的属主(owner)应该能够控制

what can be done对文件可做什么

by whom 谁来做

访问的类型

Read读

Write写

Execute执行

Append追加

Delete删除

List罗列
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息