Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating System File System Monday, August 11, 2008.

Similar presentations


Presentation on theme: "Operating System File System Monday, August 11, 2008."— Presentation transcript:

1 Operating System File System Monday, August 11, 2008

2 Objectives Understand basic concepts of file and file system
Understand physical and logic structure Know the way for managint file store space Know the file sharing and protection 8/11/2008 6:14 PM

3 Roadmap File Concept Access Methods Directory Structure
File System Implementation Allocation Methods Free-Space Management File Sharing and Protection 8/11/2008 6:14 PM

4 File Concept A file is a named collection of related information that recorded on secondary storage. From a user’s perspective, a file is the smallest allotment storage. The file is an entry in a directory. The file may have attributes (name, creator, date, type, permissions) The file may have structure ( O.S. may or may not know about this.) It's a tradeoff of power versus overhead. 8/11/2008 6:14 PM

5 File Structure Many different types of information may be stored in a file, according to which a file has a certain defined structure Text file: a sequence of characters organized into lines. Source file: a sequence of subroutines and functions, each of which is further organized as declarations followed by executable statements. Object file: a sequence of bytes organized into blocks understandable by the system’s linker. Executable file: a series of code sections that the loader can bring into memory and execute. 文件根据其类型具有一定结构。 8/11/2008 6:14 PM

6 File Attributes A file typically consist of:
Name: only information kept in human-readable form Identifier: unique tag, identifies the file Type: needed for systems that support different types Location: pointer to file location on device Size: current file size Protection: controls who can do reading, writing, executing Time, date, and user identification: data for protection, security, and usage monitoring 文件是有名称的,以方便用户通过名称对之加以引用。有了名称之后,文件就独立于进程、用户、甚至创建它的操作系统了。 8/11/2008 6:14 PM

7 File Attributes A file typically consist of:
Name: only information kept in human-readable form Identifier: unique tag, identifies the file Type: needed for systems that support different types Location: pointer to file location on device Size: current file size Protection: controls who can do reading, writing, executing Time, date, and user identification: data for protection, security, and usage monitoring 文件是有名称的,以方便用户通过名称对之加以引用。有了名称之后,文件就独立于进程、用户、甚至创建它的操作系统了。 Information about files are kept in the directory structure, which is maintained on the disk. 8/11/2008 6:14 PM

8 File Operations A file is an abstract data type. To define a file properly, we need to consider the operations that can be performed on files. Create: find space and make an entry for the file Write: keep and update the write pointer Read: keep and update the read pointer File seek: reposition within file Delete: release space and erase the directory entry Truncate: allows all attributes to remain unchanged except for file length. 8/11/2008 6:14 PM

9 File Operations (cont.)
Open(Fi) search the directory structure on disk for entry Fi and move the content of entry to memory Close(Fi) move the content of entry Fi in memory to directory structure on disk 绝大多数文件操作都涉及到为给定文件搜索相关目录条目。为了避免这种不断搜索操作,许多系统要求在首次使用文件时,使用系统调用open。操作系统维护一个包含所有打开文件的信息的表(打开文件表)。当需要一个文件操作时,通过该表的一个索引指定文件,而不需要搜索。当不再使用时,进程可以关闭文件,操作系统从打开文件表中删除这一条目。 8/11/2008 6:14 PM

10 Open Files Several pieces of data are needed to manage open files:
File pointer: pointer to last read/write location, per process that has the file open File-open count: counter of number of times a file is open – to allow removal of data from open-file table when last processes closes it Disk location of the file: cache of data access information Access rights: per-process access mode information 8/11/2008 6:14 PM

11 Open File Locking Provided by some operating systems and file systems
Mediates access to a file Mandatory or advisory: Mandatory – access is denied depending on locks held and requested Advisory – processes can find status of locks and decide what to do 8/11/2008 6:14 PM

12 File Locking Example – Java API
import java.io.*; import java.nio.channels.*; public class LockingExample { public static final boolean EXCLUSIVE = false; public static final boolean SHARED = true; public static void main(String arsg[]) throws IOException { FileLock sharedLock = null; FileLock exclusiveLock = null; try { RandomAccessFile raf = new RandomAccessFile("file.txt", "rw"); // get the channel for the file FileChannel ch = raf.getChannel(); // this locks the first half of the file - exclusive exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE); /** Now modify the data */ // release the lock exclusiveLock.release(); 8/11/2008 6:14 PM

13 File Locking Example – Java API
// this locks the second half of the file - shared sharedLock = ch.lock(raf.length()/2+1, raf.length(), SHARED); /** Now read the data */ // release the lock exclusiveLock.release(); } catch (java.io.IOException ioe) { System.err.println(ioe); }finally { if (exclusiveLock != null) if (sharedLock != null) sharedLock.release(); } 8/11/2008 6:14 PM

14 File Types – Name, Extension
当设计文件系统时,总是要考虑操作系统是否应该识别和支持文件类型。如果能识别文件类型,就能按合理方式对文件进行操作。 实现文件类型通常的技术是在文件名称内包含类型。名称可分为两部分:名称和扩展名。 8/11/2008 6:14 PM

15 Roadmap File Concept Access Methods Directory Structure
File System Implementation Allocation Methods Free-Space Management File Sharing and Protection 8/11/2008 6:14 PM

16 Sequential Access Sequential Access: information in the file is processed in order, one record after another Implemented by the filesystem. Data is accessed one record right after the last. Reads cause a pointer to be moved ahead by one. Writes allocate space for the record and move the pointer to the new End Of File. Such a method is reasonable for tape 8/11/2008 6:14 PM

17 Direct Access Direct Access: a file is made up of fixed-length logical records that allow programs to read and write records rapidly in no particular order. Method useful for disks. The file is viewed as a numbered sequence of blocks or records. There are no restrictions on which blocks are read/written in any order. User now says "read n" rather than "read next". "n" is a number relative to the beginning of file, not relative to an absolute physical disk location. 8/11/2008 6:14 PM

18 Simulation of Sequential Access on a Direct-access File
可以用直接访问来模拟顺序访问,而用顺序访问模拟直接访问则是极为低效和笨重的。 8/11/2008 6:14 PM

19 Other Methods Other access methods can be built on top of a direct-access method. Indexed These methods generally involve the construction of an index for the file. The index contains pointers to the various blocks. An index block says what's in each remaining block or contains pointers to blocks containing particular items. Suppose a file contains many blocks of data arranged by name alphabetically. 8/11/2008 6:14 PM

20 Examples Example 1: Index contains the name appearing as the first record in each block. There are as many index entries as there are blocks. Example 2: Index contains the block number where "A" begins, where "B" begins, etc. Here there are only 26 index entries. Adams Arthur Asher Smith, John | data Smith Adams Adams | Data Baker Arthur | Data Charles Asher | Data Baker | Data Saarnin Saarnin | data Smith, John | data 8/11/2008 6:14 PM

21 Roadmap File Concept Access Methods Directory Structure
File System Implementation Allocation Methods Free-Space Management File Sharing and Protection 8/11/2008 6:14 PM

22 Directory Structure Directories maintain information about files:
Name The user visible name. Type The file is a directory, a program image, a user file, a link, etc. Location Device and location on the device where the file header is located. Size Number of bytes/words/blocks in the file. Position Current next-read/next-write pointers. Protection Access control on read/write/ execute/delete. Usage Open count Usage time of creation/access, etc. Mounting a filesystem occurs when the root of one filesystem is "grafted" into the existing tree of another filesystem. There is a need to PROTECT files and directories. Actions that might be protected include: read, write, execute, append, delete, list In Memory only! 8/11/2008 6:14 PM

23 Directory Structure A collection of nodes containing information about all files F 1 F 2 F 3 F 4 F n Directory Files Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes 8/11/2008 6:14 PM

24 A Typical File-system Organization
8/11/2008 6:14 PM

25 Information in a Device Directory
Name Type Address Current length Maximum length Date last accessed (for archival) Date last updated (for dump) Owner ID Protection information (discuss later) 8/11/2008 6:14 PM

26 Operations Performed on Directory
Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system 8/11/2008 6:14 PM

27 Organize the Directory to Obtain
Efficiency: locating a file quickly Naming: convenient to users Two users can have same name for different files The same file can have several different names Grouping: logical grouping of files by properties, (e.g., all Java programs, all games, …) 8/11/2008 6:14 PM

28 Logical Structure of A Directory
The most common schemes for defining logical structure of a directory are: Single-Level Directory Two-Level Directory Tree-Structured Directory Acyclic-Graph Directory General Graph Directory 8/11/2008 6:14 PM

29 Single-Level Directory
A single directory for all users Easy to support and understand It has significant limitations, since all files must have unique names in the same directory. 易于支持和理解,但是由于文件名需要唯一造成很复杂的情况 8/11/2008 6:14 PM

30 Two-Level Directory Separate directory for each user
When a user refers to a particular file, only his own UFD is searched. Different users may have files with the same name. Difficult to cooperate on some task and to access one another’s files between users. 单层目录通常会在不同用户之间引起文件名称的混淆。标准解决方法是为每个用户创建独立目录。 8/11/2008 6:14 PM

31 Tree-Structured Directories
The most common directory structure. The tree has a root directory Every file in the system has a unique path name A path name is the path from the root, through all the subdirectories, to specified file. 树是最为常用的目录结构。树有根目录。系统内的每个文件都有惟一路径名。路径名是从根经过所有子目录再到指定文件的路径。 8/11/2008 6:14 PM

32 Tree-Structured Directories
The most common directory structure. The tree has a root directory Every file in the system has a unique path name A path name is the path from the root, through all the subdirectories, to specified file. 树是最为常用的目录结构。树有根目录。系统内的每个文件都有惟一路径名。路径名是从根经过所有子目录再到指定文件的路径。 8/11/2008 6:14 PM

33 Acyclic-Graph Directories
Have shared subdirectories and files 树形结构禁止共享文件和目录。无环图允许目录含有共享子目录和文件。 8/11/2008 6:14 PM

34 General Graph Directory
8/11/2008 6:14 PM

35 General Graph Directory (Cont.)
How do we guarantee no cycles? Allow only links to file not subdirectories Garbage collection Every time a new link is added use a cycle detection algorithm to determine whether it is OK 8/11/2008 6:14 PM

36 Keystone Three access methods Common directory structure
8/11/2008 6:14 PM

37 Operating System File and Directory Monday, August 11, 2008


Download ppt "Operating System File System Monday, August 11, 2008."

Similar presentations


Ads by Google