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(每個(gè)進(jìn)程都有一個(gè)open file table,記錄一些與進(jìn)程相關(guān)的信息):
*file pointer:讀到了哪些信息绊率,寫了哪些信息
*access control:訪問模式肠鲫,可讀可寫可執(zhí)行
a system-wide table( with process-independent information,記錄一些通用信息)
*file-open count:記錄被打開的次數(shù)?
*disk location of the file
File Structure
*none 無結(jié)構(gòu)的字節(jié)流曼追,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)
把字節(jié)流打包成塊,再映射
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(無環(huán)圖目錄)
*Have shared subdirectories and files,with no cycles(結(jié)構(gòu)無環(huán))
*The same file or directory may be in two different directories,having two different names(aliasing)
這里是共享文件,而不是文件復(fù)制叶堆!對于共享文件,任何改變都會為其他用戶所見?
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?
一個(gè)文件可以擁有多個(gè)絕對路徑名
多次重復(fù)遍歷共享目錄
2.delete problem
dangling pointer
preserve the file until all reference to it are deleted
solutions:
file-reference list
reference count
通過禁止對目錄的多重引用斥杜,維護(hù)無環(huán)圖結(jié)構(gòu)
General Graph Directory
traversing problem and deleting problem still exists,even more complicatedly
infinite loop
garbage and garbage collection
保證無環(huán)
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(保護(hù)虱颗,安全性):guarding against improper access
Access control:
ID-dependent access:make access dependent on the ID of the user
implement:Access control list(ACL)