OS-file system interface(用户角度)

2018-06-29  本文已影响0人  一只小小小小訸

File-system Interface

File--nonvolatile 非易失性

A file is a logical storage unit.

A file is  a named collection of related information that is recorded on secondary storage.

contiguous logical address space

File Attribute--kept in the directory,also maintained on the secondary storage

    A file's attributes vary from one OS to another but typically consist of :

name,identifier,type,location,size,protection,time,data and user identification

    A directory entry only consists of the file's name and its unique identifier,the identifier in turn locates the other file attributes.

FIle is an abstract data type.

6 basic system calls:

create:allocate space and create a directory entry

wirte and read:pointer

reposition within file:seek

delete:release space and erase the directory entry

truncate:file len=0,release space,all other attributes remain unchanged

OPEN-->find entry FI-->move the content of entry to memory

CLOSE-->写回属性

Open file table:a small table containing information about all open files

                            记录打开了哪些,读到了哪里

2 level 访问:

a per-process table(每个进程都有一个open file table,记录一些与进程相关的信息):

*file pointer:读到了哪些信息,写了哪些信息

*access control:访问模式,可读可写可执行

a system-wide table( with process-independent information,记录一些通用信息)

*file-open count:记录被打开的次数 

*disk location of the file

File Structure

*none 无结构的字节流,sequence of words,bytes

*simple record structure

*complex structure


Internal file structure

how to locate an offset within a file?

Packing-pack a number of logical records (vary in length) into physical blocks (fixed size)

把字节流打包成块,再映射

Internal fragmentation will occur.


Access Methods

Files store information.When it is used ,this information must be accessed and read into computer memory.

Sequential Access

the simplest access method.Information in the file is processed in order,one record after the other.

a most common access mode:editors,compilers

A tape model of file

Direct Access:

information in the file is processed in no particular order

File is made up of a number sequence of fixed-length logical records.

A disk model of file :allow random access,immediate access:databases ,airline-reservation system

can move quickly to any recored location by supplying a relative record number

Indexed Access

to improves seach time and reduce I/O

Make an index file for the file,which contains pointers to various records

search the index file first-->use the pointer to access the file directly -->find the desired record

with large files,the index file itself may become too large to be kept in memory --->multi-level index table


Directory Structure

partition=files+directories

directory:a collection of nodes containing information about all files

directory + files : all reside on disk

backups of these two structures are kept on tapes

Organize the directory (logically) to obtain :efficiency ,naming and grouping

Directory Structures:

1.Single-level directory

2.Two-level directory

3.Tree-structured directory

4.Acyclic-graoh directory

5.General-graph directory

Single-level directory:

esay but:

1.very low searching speed 2.name problem (small name space and name collison)

Two-level directory

Separate directory for each user

User File Directory(UFD) :for user

Master file directory(MFD): user name and a pointer to his UFD

same file name for different user is ok

efficient searching

easy management

no grouping capability

security and sharing

Tree-Structured Directory

root directory and directory and subdirectory

efficient searching

grouping capability

tree structure

prohibits the sharing of files and directories

用户可以访问到其他用户的文件

Acyclic-Graph Directories(无环图目录)

*Have shared subdirectories and files,with no cycles(结构无环)

*The same file or directory may be in two different directories,having two different names(aliasing)

这里是共享文件,而不是文件复制!对于共享文件,任何改变都会为其他用户所见 

Implementation

1.Symbolic links (另一文件或目录的指针)

链接通过路径定位文件来解析

A special new directory entry(link)

The content of  such file is the path name of the real file/directory

2.duplicates directory entries

hard to maintain consistency

Problem

1.Traverse Problem 

一个文件可以拥有多个绝对路径名

多次重复遍历共享目录

2.delete problem

dangling pointer

preserve the file until all reference to it are deleted

solutions:

file-reference list

reference count

通过禁止对目录的多重引用,维护无环图结构

General Graph Directory

traversing problem and deleting problem still exists,even more complicatedly

infinite loop

garbage and garbage collection

保证无环

allow only links to file not subdirectories

add new link,use a cycle detection algorithm to determine whether it's ok


Protection

reliability(可靠性):guarding against physical damage

protection(保护,安全性):guarding against improper access

Access control:

ID-dependent access:make access dependent on the ID of the user

implement:Access control list(ACL)

上一篇 下一篇

猜你喜欢

热点阅读