夜雨聆风学习资料网 资料列表 开通 VIP 用登录 / 注册 ⌄
PDF

操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程

查看资料信息、公开预览和下载状态。

共 92 页PDF · 1.5MB
下载

文档在线预览

公开展示前 10 页
100%
1
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第1页预览
2
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第2页预览
3
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第3页预览
4
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第4页预览
5
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第5页预览
6
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第6页预览
7
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第7页预览
8
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第8页预览
9
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第9页预览
10
《操作系统_第4章_文件管理_2026考研专业课_202026计算机_202026计算机_2026年优路计算机408_02.基础阶段_01.考研电子信息基础精讲课程_01.操作系统基础精讲课程》第10页预览

本文档共 92 页 剩余 82 页未展示,请下载后查阅

下载

文档文本内容

操作系统
第四章 文件管理统考真题
2020内 容
文件管理系统
1
文件的逻辑组织
2
文件目录
3
文件共享
4
文件存储空间的管理
5文件管理概述文件操作文件保护F i l e M a n a g e m e n t
File management system is considered part of the operating
●
system.
Input to applications is by means of a file.
●
Output is saved in a file for long-term storage.
●O b j e c t i v e s f o r a F i l e M a n a g e m e n t
S y s t e m
(符合系统管理数
Meet the data management needs and requirements of the user.
●
据的需要及用户的需求)
Guarantee that the data in the file are valid.
●
(保证系统性能及用户对响应时间的要求)
Optimize performance.
●
Provide I/O support for a variety of storage device types.
●O b j e c t i v e s f o r a F i l e M a n a g e m e n t
S y s t e m
Minimize or eliminate the potential for lost or destroyed
●
(减少或避免数据丢失及损坏)
data.
(提
Provide a standardized set of I/O interface routines.
●
供标准的I/O接口)
(支持多用户环境
Provide I/O support for multiple users.
●
下多个用户的I/O操作)F i l e M a n a g e m e n t F u n c t i o n s
Identify and locate a selected file.
●
Use a directory to describe the location of all files plus their attributes.
●
On a shared system describe user access control.
●
Blocking for access to files.
●
Allocate files to free blocks.
●
Manage free storage for available blocks.
●D e v i c e D r i v e r sB a s i c F i l e S y s t e m
Physical I/O.
●
Deals with exchanging blocks of data.
●
Concerned with the placement of blocks.
●
Concerned with buffering blocks in main memory.
●B a s i c I / O S u p e r v i s o r
Responsible for file I/O initiation and termination.
●
Control structures are maintained.
●
Concerned with scheduling access to optimize performance.
●
I/O buffers are assigned and secondary memory is allocated.
●
Part of the operating system.
●L o g i c a l I / O
Enables users and applications to access records.
●
Provides general-purpose record I/O capability.
●
Maintains basic data about file.
●A c c e s s M e t h o d
Reflect different file structures.
●
Different ways to store and process data.
●
如Pile、顺序访问、索引顺序访问、索引访问、Hash访问法等访问方法
●文件的逻辑结构
与访问方式F i l e O r g a n i z a t i o n
File organization refers to the logical structuring of the records as
●
determined by the way in which they are accessed.
The physical organization of the file on secondary storage depends on the
●
blocking strategy and the file allocation strategy.C r i t e r i a f o r F i l e O r g a n i z a t i o n
Rapid access
●
● Needed when accessing a single record.
● Not needed for batch mode.
Ease of update
●
● File on CD-ROM will not be updated, so this is not a concern.C r i t e r i a f o r F i l e O r g a n i z a t i o n
Economy of storage
●
● Should be minimum redundancy in the data.
● Redundancy can be used to speed access such as an index.
Simple maintenance
●
Reliability
●F i l e O r g a n i z a t i o n
Pile file(堆文件)
●
Sequential file(顺序文件)
●
Indexed sequential file(索引顺序文件)
●
Indexed file (索引文件)
●
Direct, or Hashed file(直接或hash文件)
●P i l e ( 堆 文 件 )
Data are collected in the order they arrive.
●
Purpose is to accumulate a mass of data and save it.
●
Records may have different fields.
●
No structure.
●
Record access is by exhaustive search.
●P i l eS e q u e n t i a l F i l e
Fixed format used for records.
●
Records are the same length.
●
All fields the same (order and length).
●
Field names and lengths are attributes of the file.
●
One field is the key filed
●
ØUniquely identifies the record.
ØRecords are stored in key sequence.S e q u e n t i a l F i l eS e q u e n t i a l F i l e
v The only one that is easily stored on tapes as well as
disk .
v Typically used in batch applications and the
applications processing of all records.
v For querying and/or updating an individual record,it
provides poor performance.
v New records are placed in a log file or transaction
file.
v Batch update is performed to merge the log file with
the master file.I n d e x e d S e q u e n t i a l F i l e
It maintains the key characteristic of
t h e s e q u e n t i a l f i l e : r e c o r d s a r e
o r g a n i z e d i n s e q u e n c e b a s e d o n a k e y
field.
Ø Add an index to the file to support random access,and an
overflow file.
Ø Index file contains key field and a pointer to the main file,
a n d p r o v i d e s a l o o k u p c a p a b i l i t y t o q u i c k l y r e a c h t h e
vicinity of the desired record.
Ø Overflow file is similar to the log file. It is integrated so
that records in the overflow file are located by following a
pointer from their processor record.I n d e x e d S e q u e n t i a l F i l e
v索引顺序文件的每一条记录中都包含一个指向overflow文件的指针
(该指针对应用程序透明)
§ New records are added to an overflow file
§ 如果新记录的前续记录在主文件(或overflow文件)中,则修改主文件
(或overflow文件)中该前续记录指针,使之指向overflow文件中的新插
入记录
§ The overflow is merged with the main file during a batch update.
§ Multiple indexes for the same key field can be set up to increase
efficiency.I n d e x e d S e q u e n t i a l F i l eS e q u e n t i a l vs. I n d e x e d S e q u e n t i a l
Example:
A file contains 1 million records.
●
On average 500,000 accesses are required to find a record in a sequential file.
●
If an index contains 1000 entries, it will take on average 500 accesses to find
●
the key, followed by 500 accesses in the main file. Now on average it is 1000
accesses.S e q u e n t i a l vs. I n d e x e d S e q u e n t i a l
Ø 若一级索引文件包含10,000条记录,再为之建立二级索
引,其中包含100条记录
Ø 在二级索引文件中平均检索50条记录,可以找到关键字
Ø 再在一级索引文件中平均检索50条记录找到指向主文件
的指针
Ø 最后平均检索50条记录,找到目标记录,共计平均检索
150条记录I n d e x e d F i l e
顺序文件和索引顺序文件都只允许按记录的唯一关键字检索
●
记录,这不符合某些应用需要按多个字段检索记录的要求
主文件的记录不必按关键字排序
●
Uses multiple indexes for different key fields.
●
May contain an exhaustive index(完备索引)that
●
contains one entry for every record in the main
file.
May contain a partial index(部分索引)that contains
●
entries to records where the field of interest
exists.I n d e x e d F i l eT h e D i r e c t , o r H a s h e d F i l e
Directly access a block at a known address.
●
Key field required for each record.
●
利用Hash函数,根据记录的关键字计算记录的存储位置,
●
并按关键字访问记录,提高记录的访问效率
常用于访问速率要求高、一次存取一条记录且记录为定
●
长的文件。如文件目录、价格表、名单等文件记录的存
取。F i l e D i r e c t o r i e s
Directory itself is a file owned by the operating system.
●
Provides mapping between file names and the files themselves.
●F i l e D i r e c t o r i e s
Contains information about files.
1. Basic Information
File Name, File Type, File Organization
●
2. Addr. Information
Volume, Starting Addr., Size Used, Size
●
Alloc.
3. Access Contr. Information
Owner, Access Info., Permitted Actions
●
4. Usage information
Date Created, ID. of Creator, Date Last Read
●
Access, ID of Last Reader, Date of Last
Modified, I
D of Last Modifier, Date of Last Backup,
Current UsageS t r u c t u r e f o r a D i r e c t o r y
v 可见,不同系统保存文件目录的方式不同。有的系统将其中部分信息保存在文
件头部,只将一些必要信息如文件名、文件大小、外存中的存储位置等保存在
文件目录中
v 对目录文件的典型操作:
§ Search:按文件名检索文件目录
§ Create file:建立文件时,必须为之建立一个新目录
§ Delete file:删除文件时,必须同时删除其文件目录
§ List Directory:用户常需要列文件目录及文件的某些属性S i m p l e S t r u c t u r e f o r a D i r e c t o r y
List of entries, one for each file.
●
Sequential file with the name of the file serving as the
●
key.
Provides no help in organizing the files.
●
Forces user to be careful not to use the same name for two
●
different files.T w o - l e v e l S c h e m e f o r a D i r e c t o r y
vOne directory for each user and a master directory.(用户目
录和主目录)
vMaster directory contains entry for each user.
§ Provides address and access control information.
vEach user directory is a simple list of files for that
user.
vStill provides no help in structuring collections of files.H i e r a r c h i c a l , o r T r e e - S t r u c t u r e d
D i r e c t o r y
Master directory with user directories underneath it.(主目
●
录下建立若干用户目录)
Each user directory may have subdirectories and files as
●
entries.(每个用户目录下允许再创建子目录及文件目录)H i e r a r c h i c a l , o r T r e e - S t r u c t u r e d
D i r e c t o r y
Files can be located by following a path from the root, or master, directory
●
down various branches.
● This is the pathname for the file.
Can have several files with the same file name as long as they have unique path
●
names.H i e r a r c h i c a l , o r T r e e - S t r u c t u r e d
D i r e c t o r y
Current directory is the working directory.(当前目录即工作
●
目录)
Files are referenced relative to the working directory.
●
(相对工作目录的文件路径为相对路径)F i l e S h a r i n g
In multiuser system, allow files to be shared among users.
●
Two issues
●
● Access rights
● Management of simultaneous access.(并行存取)A c c e s s R i g h t s
None
●
● User may not know of the existence of the file.
● User is not allowed to read the user directory that includes the file.
Knowledge(探知)
●
● User can only determine that the file exists and who its owner is.A c c e s s R i g h t s
Execution
●
● The user can load and execute a program but cannot copy it.
Reading
●
● The user can read the file for any purpose, including copying and execution.
Appending
●
● The user can add data to the file but cannot modify or delete any of the file’s
contents.A c c e s s R i g h t s
Updating
●
● The user can modify, deleted, and add to the file’s data.
This includes creating the file, rewriting it, and removing
all or part of the data.
Changing protection
●
● User can change access rights granted to other users.
Deletion
●
● User can delete the file.A c c e s s R i g h t s
Owners
●
● Has all rights previously listed.
● May grant rights to others using the following classes of
users.
● Specific user
● User groups
● All for public filesS i m u l t a n e o u s A c c e s s
User may lock entire file when it is to be updated.
●
User may lock the individual records during the update.
●
Mutual exclusion and deadlock are issues for shared access.
●R e c o r d B l o c k i n g
v记录是存取文件的逻辑单位,而数据块是I/O的基
本单位,记录必须组织成数据块以便于I/O
v问题:
§ 数据块的长度固定还是可变?
§ 根据记录的平均长度如何设置数据块的长度?数据块的长度固定还是可变?
大多数系统采用固定长度的数据块,以简化I/O操作、Buffer
的分配及辅存中数据块的组织管理如何设置数据块的长度?
数据块越大,一次I/O传输的记录就越多
●
大数据块适合文件顺序访问,因为这样可以减少I/O次数,加快处理
●
速度
当随机访问文件,或访问局部性很差时,传输的部分记录不会使用,
●
效率低。
另外,大数据块需要更大的I/O buffer,增加其管理复杂度
●v数据块由固定长度的若干条记录组成
v块内可能会存在一些被浪费空间F i x e d B l o c k i n gV a r i a b l e B l o c k i n g : S p a n n e d ( 可 变 长 跨 块 组 块 法 )
v 数据块由变长记录组成,一条记录可以跨越两个数据块,
可用指针记载一条跨块存储记录所在的下一数据块
v 块内无浪费空间V a r i a b l e B l o c k i n g : S p a n n e dV a r i a b l e B l o c k i n g U n s p a n n e d ( 可 变 长 非 跨 块 组 块 法 )
v 数据块由变长记录组成
v 不允许一条记录跨越两个数据块
v 块内可能存在被浪费空间V a r i a b l e B l o c k i n g U n s p a n n e d文件的物理组织和外存空闲空间管理S e c o n d a r y S t o r a g e M a n a g e m e n t
Space must be allocated to files.
●
Must keep track of the space available for allocation.
●M e t h o d s o f F i l e A l l o c a t i o n
● Contiguous allocation(连续分配)
● Chained allocation(链接分配)
● Indexed allocation(索引分配)
● 混合索引分配C o n t i g u o u s a l l o c a t i o n ( 连 续 分 配 )
Preallocatin strategy using variable-size portions.
●
Single set of blocks is allocated to a file at the time of creation.
●
Only a single entry in the file allocation table.
●
● Starting block and length of the file.Allocation Strategies (分配策略:可变分区)
First fit:Choose the first unused contiguous group of
●
blocks of sufficient size.
Best fit:Choose the smallest unused group of sufficient
●
size.(内零头最小)
Nearest fit:Choose the unused group of sufficient size
●
that is closest to the previous allocation for the file to
increase locality.C o n t i g u o u s A l l o c a t i o n
External fragmentation will occur.
●
It is necessary to perform a compaction algorithm to free
●
up additional space on the disk .C h a i n e d A l l o c a t i o n ( 链 接 分 配 )
Allocation on basis of individual block.
●
Each block contains a pointer to the next block in the chain.
●
Only single entry in the file allocation table.
●
Starting block and length of file
●
No external fragmentation.
●
Best for sequential files.
●
No accommodation of the principle of locality.
●C h a i n e d A l l o c a t i o n
To select an individual block of a file requires tracing
●
trough the chain to the desired block.
To access many blocks at a time, a series of accesses to
●
different parts of the disk are required.
T o o v e r c o m e t h i s p r o b l e m , s o m e s y s t e m p e r i o d i c a l l y
●
consolidate files.I n d e x e d A l l o c a t i o n ( 索 引 分 配 )
File allocation table contains a separate one-level index
●
for each file.(一级索引)
The index has one entry for each portion allocated to the
●
file.
The file index for a file is kept in a separate block, and
●
the file allocation table contains block number for the
index.
Allocation may be on the basis of fixed-size blocks.
●I n d e x e d A l l o c a t i o n
Or allocation may be on the basis of variable-size
●
portions.I n d e x e d A l l o c a t i o n
Eliminates external fragmentation.
●
File consolidation may be done from time to time,reducing
●
t h e s i z e o f t h e i n d e x i n t h e c a s e o f v a r i a b l e - s i z e
portions.
Supports both sequential and direct access to the file,
●
and thus is the most popular form of file allocation.多级索引文件结构混 合 索 引 例 题
【2010统考真题】设文件索引节点有7个地址项,4个直接索引,2个一次间接索引,1个二级间接索
引,每个地址项占4B,索引块和数据块大小均为256B,求单个文件最大长度?目 录
单级目录
●
两级目录
●
树形目录
●
无环图目录
●文 件 共 享
硬链接(基于索引节点的共享)
●
软链接(基于符号链的共享)
●文 件 系 统 结 构
I/O控制
●
基本文件系统
●
文件组织模块
●
逻辑文件系统
●文 件 系 统 布 局
主引导记录
●
引导块
●
超级块
●
空闲块信息
●F r e e S p a c e M a n a g e m e n t
Disk Allocation Table:
空闲表法
●
空闲链表法
●
位视图法
●
成组链接法
●B i t T a b l e
位表,又称为位示图,其中的每一位对应一个磁盘块。位的值为0或1,
●
分别表示磁盘块空闲,或磁盘块已分配
利用位表容易找到一个或一组空闲盘块
●
位表适合于以上各种文件分配方法
●
位表很小,可以装入内存
●1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 1 0 0 0 0 1 1 1 1 1 0 1 1 0 0 0
4
.
.
.
16
位示图C h a i n e d F r e e P o r t i o n
每个空闲分区包含一个指向下一个分区的指针,并记载
●
分区大小
无空闲分区表空间开销
●
适合于各种文件分配方法
●
若每次分配一个磁盘块,则可取空闲分区链的第一个盘
●
块进行分配,并调整空闲分区链首指针和分区链大小
若采用可变分区法,可用首次适应算法,从链表头开始
●
查找,找到的第一个适合的分区则可分配,然后调整空
闲分区链首指针和分区链大小I n d e x i n g
v将空闲分区视为文件,按文件存储空间分配法为
空闲分区建立索引
v索引表中为每一个空闲分区建立一个索引项
v为可变分区建立索引比为磁盘块建立索引效率高
v适合于各种文件分配法虚 拟 文 件 系 统
超级块对象
●
索引节点对象
●
目录项对象
●
文件对象
●