操作系统--实现文件系统上篇
Objectives
目标
n To describe the details of implementing local file
描述实施本地文件的细节
systems and directory structures
系统和目录结构
n To describe the implementation of remote file
描述远程文件的实现
systems
系统
n To discuss block allocation and freeblock algorithms
讨论块分配和自由块算法
and tradeoffs
和权衡
11.3
11.3
FileSystem Structure
文件系统结构
n File structure
文件结构
l Logical storage unit
逻辑存储单元
l Collection of related information
相关信息的收集
n File system resides on secondary storage (disks)
文件系统位于辅助存储器(磁盘)上
n File system organized into layers
文件系统分层组织
n File control block storage structure consisting of
文件控制块存储结构包括
information about a file
关于文件的信息
Layered File System
分层文件系统
A Typical File Control Block
典型的文件控制块
InMemory File System Structures
内存文件系统结构
n The necessary file system structures provided by the OS.
操作系统提供的必要文件系统结构。
opening a file
打开文件
Virtual File Systems
虚拟文件系统
n Modern OS must concurrently support multiple types of
现代操作系统必须同时支持多种类型的
file systems.
文件系统。
n How does an OS allow multiple types of file systems to be
操作系统如何允许多种类型的文件系统
integrated into a directory structure ?
集成到目录结构中?
l To write directory and file routines for each type.
为每种类型编写目录和文件程序。
n Most Operating systems provide an objectoriented way of implementing file systems, including UNIX.
大多数操作系统提供了一种面向对象的方法来实现文件系统,包括UNIX。
n The filesystem implementation consists of three major layers (Figure 11.4)
文件系统实现由三个主要层组成(图11.4)
n The first layer is the filesystem interface, based on open(), read(), write(), and close() calls
第一层是文件系统接口,基于open(),read(),write()和close()调用
n The 2 nd layer is called the virtual file system (VFS) layer
第二层称为虚拟文件系统(VFS)层
Schematic View of a Virtual File System
虚拟文件系统示意图
Virtual File Systems
虚拟文件系统
n The VFS serves two important functions
VFS有两个重要功能
l It separates filesystemgeneric operations from
它将文件系统一般操作与
their implementation by defining a clean VFS
通过定义一个干净的VFS
interface.
界面。
l It provides a mechanism for uniquely representing a file throughout a network.
它提供了一种在整个网络中唯一表示文件的机制。
4The VFS is based on a filerepresentation
4The VFS基于文件表示
structure, called a vnode, that contains
结构,称为vnode,它包含
numerical designator for a networkwild unique
网络唯一性的数字指示符
file.
文件。
Virtual File Systems
虚拟文件系统
l Unix inodes are unique only within a single file
Unix索引节点仅在单个文件中是唯一的
system
系统
l The kernel maintains one vnode structure for
内核维护一个vnode结构,用于
each active node (file or directory)
每个活动节点(文件或目录)
n The VFS distinguishes local files from remote files,
VFS区分本地文件和远程文件,
and local files are further distinguished according
并且本地文件根据
to their filesystem types.
文件系统类型。
Virtual File Systems
虚拟文件系统
n VFS allows the same system call interface (the API) to be
VFS允许相同的系统调用接口
Virtual File Systems
虚拟文件系统
n The VFS architecture in Linux defines four
Linux中的VFS架构定义了四个
major object types
主要对象类型
l The inode object, represents an individual file
索引节点对象代表一个单独的文件
l The file object, represents an open file
文件对象代表一个打开的文件
l The Superblock object, represents an entire file
超级块对象代表整个文件
system
系统
l The dentry object, represents an individual
齿状物体代表一个人
directory entry.
目录条目。
Directory Implementation
目录实现
n The selection of directoryallocation and directory
目录位置和目录的选择
management algorithms affects the efficiency, performance, and reliability of the file system
管理算法影响文件系统的效率、性能和可靠性
n Linear list of file names with pointer to the data blocks.
指向数据块的线性文件名列表。
l simple to program
易于编程
l timeconsuming to execute
执行起来很耗时
n Hash Table linear list stores the directory entries, but a hash
哈希表线性列表存储目录条目,但不是哈希表
data structure is also used.
也使用数据结构。
l decreases directory search time
减少目录搜索时间
l collisions situations where two file names hash to the
两个文件名散列到一起的冲突情况
same location
相同的位置
l fixed size
固定尺寸
Allocation Methods
分配方法
n An allocation method refers to how disk blocks
分配方法是指磁盘块
are allocated for files:
为文件分配:
l Contiguous allocation
连续分配
l Linked allocation
关联分配
l Indexed allocation
指数化分配
Contiguous Allocation
连续分配
n Each file occupies a set of contiguous blocks on
每个文件占用上的一组连续块
the disk
磁盘
n Simple only starting location (block #) and
仅简单的起始位置(区块#)和
length (number of blocks) are required
需要长度(块数)
n Random access
随机访问
n Wasteful of space (dynamic storageallocation problem), external fragmentation
空间浪费(动态存储位置问题)、外部碎片
n Files cannot grow
文件无法增长
Contiguous Allocation of Disk Space
磁盘空间的连续分配
ExtentBased Systems
基于扩展的系统
n Many newer file systems use a modified contiguous
许多较新的文件系统使用修改后的连续
allocation scheme
配线图
n Extentbased file systems allocate disk blocks in extents
基于扩展的文件系统以扩展方式分配磁盘块
n An extent is a contiguous block of disks
扩展区是一个连续的磁盘块
l Extents are allocated for file allocation
为文件分配分配范围
l A file consists of one or more extents.
文件由一个或多个范围组成。
n The location of a file’s blocks is then recorded as a location
文件块的位置被记录为一个位置
and a block count, plus a link to the first block of the next
和块计数,加上到下一个块的第一块的链接
extent.
范围。
n The commercial Veritas File System uses extents to optimize
商用维尔软件文件系统使用扩展来优化
performance.It is a highperformance replacement for
性能。它是的高性能替代品
standard UNIX UFS.
标准的UNIX。
Linked Allocation
链接分配
n Each file is a linked list of disk blocks: blocks may
每个文件都是磁盘块的链表:块可以
be scattered anywhere on the disk.
分散在磁盘上的任何地方。
Linked Allocation (Cont.)
链接分配(续。)
n Simple need only starting address
简单只需要起始地址
n Freespace management system no waste of
自由空间管理系统没有浪费
space
空间
n Some disadvantages
一些缺点
l No random access (only for sequential access files)
无随机存取(仅用于顺序存取文件)
l Space required for pointers, If a pointer requires 4 bytes out of a 512 bytes block, 0.78 percent is used
指针所需的空间,如果指针需要512字节块中的4个字节,则使用0.78%
for pointers
对于指针
4Clusters (k blocks)
4Clusters (k区)
l Reliability Issue
可靠性问题
Linked Allocation
链接分配
FileAllocation Table
文件分配表
n An important variation on linked allocation is the
关联分配的一个重要变化是
use of a fileallocation table (FAT)
文件分配表的使用
nThe FAT allocation scheme can result in a
FAT分配方案可能会导致
significant number of disk head seeks, unless the
大量磁盘磁头寻道,除非
FAT is cached.
FAT被缓存。
Indexed Allocation
索引分配
n Brings all pointers together into the index block.
将所有指针放入索引块。
n Logical view.
逻辑观点。
blocks
块
index table
索引表
Example of Indexed Allocation
索引分配示例
Indexed Allocation (Cont.)
指数分配(续。)
n Need index table
需要索引表
n Random access
随机访问
n Dynamic access without external fragmentation,
没有外部碎片的动态访问,
but have overhead of index block.
但是具有索引块开销。
n Mapping from logical to physical in a file of
文件中从逻辑到物理的映射
maximum size of 256K words and block size of 512
最大256千字,块大小512
words.
文字。
l Only 1 block is needed for index table.
索引表只需要一个块。
256K/0.5K = 512 blocks
256K/0.5K = 512块
Indexed Allocation Mapping (Cont.)
索引分配映射(续。)
n Mapping from logical to physical in a file of
文件中从逻辑到物理的映射
unbounded length (block size of 512 words).
无界长度(块大小为512个字)。
l Linked scheme Link blocks of index table
链接方案链接索引表的块
(no limit on size).
(大小不限)。
Indexed Allocation Mapping (Cont.)
索引分配映射(续。)
index table
索引表
File
文件
Combined Scheme: UNIX (4K bytes per block)
组合方案:UNIX(每块4K字节)
FreeSpace Management