Article Directory
4.1.1 The concept of files
1. Definition of documents
file:文件是以计算机硬盘为载体的存储在计算机上的信息集合。
计算机是以进程为基本单位进行
Resource scheduling and allocation
Operating system responsible for managing and storing software file organization information is called文件管理系统
1)
data item 数据中可命名的最小元素
2)
record 相关数据项的集合
3)
fileUnstructured file又叫流式文件,二进制文件
Structured document一组相似的记录组成,又叫记录式文件
2. File attributes
- Name: unique file name
- Identifier: A unique label that identifies a file in the file system (transparent to users, since files with the same name can exist in different directories, the name cannot uniquely distinguish files)
- Type: the file type
- Location: The path where the file is stored (used by the user), the address in the external storage (used by the operating system)
- Size: file size
- Protection: Access control information for file protection
- Time: creation time, last modification time, last access time and other related information
3. Basic operations of files
- Create a file
- Write file
- Read file
- File relocation (file addressing):Search the directory based on certain conditions, set the current file to a given value, and will not read or write files
- Delete Files
- Truncate the file:Allow all attributes of the file to remain unchanged, and delete the file content, that is, set the length to 0 and release its space
4. Open and close the file.
Use an entry that 系统调用open
will specify the attributes of the file (including the physical address information of the file) 从外存复制到内存打开文件表
, and return the entry number of the entry to the user.
操作系统维护一个包含所有打开文件信息的
Open file table
** 2. The logical structure of the file**
1) Unstructured files (streaming files) binary files
2) Structured files (recording files) Each record consists of several data items. Generally speaking, each record has a data item that can be used as a keyword.
一、顺序文件
- Chain storage : Whether it is a fixed-length/variable-length record, you
都无法实现随机存取
can only search from the first record in sequence each time. - Sequential storage:
variable-length records:,
无法实现随机存取
also can only search backward
fixed-length records from the first record:
可以实现随机存取
if used串结构
,无法快速找到某关键字对应的记录
Single list
If used顺序结构
,可以快速查找关键字记录
(search by half)Sequence table
The disadvantage of sequential files is增加/删除记录比较困难
二、索引文件
For 定长
file
for 变长
file
三、索引顺序文件
(Solve the problem that the index table of the index file is too large)
It is 顺序
and 索引
are two types of binding.
四、Hash文件
4.1.3 Directory structure
1. File control block and index node
一、文件控制块
It is a data structure used to store various information required by the control file to realize "access by name".
The ordered set of 文件目录
FCB is called , one FCB is one文件目录项
FCB包含的信息
- Basic information: file name
物理地址
,, logical structure, physical structure, etc. - Access control information: file access permissions, etc.
- Usage information: file creation time, modification time, etc.
- The most important and basic is
文件名
and物理地址
because FCB main function is按名存取
, that is文件名到物理地址的映射
.
二、索引结点
The file description information forms a separate file called索引结点的数据结构
The file description information except the file name is placed in the index node
FCB必须连续存放
2. Directory structure
一、单级目录结构
There is only one directory table in the entire system, 每个文件占一个目录项
support "access by name", 但不允许文件重名。
single-level directory structure不适合多用户操作系统。
One FCB is one 文件目录项
二、两级目录结构
(Solve the single-level non-duplicate name problem)
Divided into 主文件目录
(MFD) and 用户文件目录
(UFD)
- Master file directory record Record user name and corresponding user file directory
- User file directory FCB information for user files
三、多级目录结构
(Tree directory structure)
It is convenient to realize the classification of files, and it is not convenient to realize the sharing of files
- relative path: Relative to current directory
- Absolute path: Start from the root directory
四、无环图目录结构
(Solve the shortcomings of inconvenient sharing of tree directories)
优点:
Conveniently realizes file sharing. When
缺点:
deleting a shared node, another shared user cannot accessMake system management more complicated
4.1.4 File Sharing
1、基于索引结点的共享方式
Hard link
count indicates the number of users linked to this index node (file)
count是几,即为几个用户正在共享该文件
2、利用符号链实现共享方式
Soft link
To enable user B to share a file F of user A, a file can be created by the systemNew file of type LINK, Also named F 并将F写入用户B的目录中
, called符号链接
在删除共享文件时,其他用户通过符号链访问,会在访问中出错
Deleting the symbolic chain has no effect
- When the symbolic link is established, the reference number is copied directly
- When the hard link is established,
新的硬链接
Number of references to the corresponding file+1
例题
- F1 reference number is 1, establish soft connection F2,
引用数直接复制
F2 reference number is 1 - The reference number of F1 is 1, the hard link F3 is established,
引用数+1
F3 reference number is 2
So when deleting:
- F2 is a soft link, just delete it directly, the count remains unchanged
- F3 is a hard link, count should be reduced by one
4.1.5 File protection
File protection passed 口令保护(通过口令)、加密保护(密钥)、访问控制(身份权限)
1. Access type
2. Access type
To solve access control, you can add one for each file and directory 访问控制表
.