Operating System File System Monday, August 11, 2008.

Slides:



Advertisements
Similar presentations
1 Chapter 11: File-System Interface  File Concept  Access Methods  Directory Structure  File System Mounting  File Sharing  Protection  Chapter.
Advertisements

Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 11: File-System Interface File Concept Access Methods Directory Structure.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 10: File-System Interface File Concept.
Dr. Kalpakis CMSC 421, Operating Systems. Fall File-System Interface.
11.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 11: File-System Interface File Concept Access Methods Directory Structure.
Chapter 10: File System.
10: File Systems1 FILE SYSTEMS INTERFACE FILE CONCEPT A collection of related bytes having meaning only to the creator. The file can be "free formed",
File-System Interface CS 3100 File-System Interface1.
Chapter 10: File-System Interface. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition File-System Interface.
Chapter 10: File-System Interface
Chapter 10: File-System Interface
1 Chapter 10: File- System Interface. 2 File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 10: File-System Interface File Concept.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 10: File-System.
File Concept l Contiguous logical address space l Types: Data: numeric, character, binary Program: source, object (load image) Documents.
File Concept §Contiguous logical address space §Types: l Data: Numeric Character Binary l Program.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10: File-System Interface.
Chapter 10 File System Interface
ITEC 502 컴퓨터 시스템 및 실습 Chapter 10-1: File Systems Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 10: File-System Interface File Concept Access Methods Directory.
11.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 11: File-System Interface File Concept Access Methods Directory Structure.
Chapter 10: File-System Interface 10.1 Silberschatz, Galvin and Gagne ©2011 Operating System Concepts – 8 th Edition 2014.
File System Interface. File Concept Access Methods Directory Structure File-System Mounting File Sharing (skip)‏ File Protection.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Page 110/19/2015 CSE 30341: Operating Systems Principles Chapter 10: File-System Interface  Objectives:  To explain the function of file systems  To.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 11: File-System Interface File Concept Access Methods Directory Structure.
XE33OSA Chapter 10: File-System Interface. 10.2XE33OSA Silberschatz, Galvin and Gagne ©2005 Chapter 10: File-System Interface File Concept Access Methods.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10: File-System Interface.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 10: File-System Interface File Concept.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 11: File-System Interface.
Silberschatz and Galvin  Operating System Concepts Module 10: File-System Interface File Concept Access :Methods Directory Structure Protection.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 10: File-System Interface.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 10: File-System Interface File Concept.
Chapter 10: File-System Interface Hung Q. Ngo KyungHee University Spring 2009
Chapter 10: File-System Interface. 10.2CSCI Operating Systems Chapter 10: File-System Interface File Concept Access Methods Directory Structure.
Chapter 10: File-System Interface File Concept Contiguous logical address space Types: Data  numeric  character  binary Program.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 10: File-System Interface File Concept.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10: File-System Interface.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10 & 11: File-System Interface and Implementation.
It consists of two parts: collection of files – stores related data directory structure – organizes & provides information Some file systems may have.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 10: File-System Interface.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 Chapter 10: File-System.
Chapter 10: File-System Interface Adapted to COP4610 by Robert van Engelen.
10.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 10: File-System Interface.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 Chapter 10: File-System.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10: File-System Interface.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems File System Interface.
CSE Operating System Principles File Systems.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10: File-System Interface.
10.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 10: File-System 10.1 File Concept 10.2 Access Methods 10.3 Directory Structure.
Chapter 11: File-System Interface
Lecture 9 : chapter 9 and 10 file system
File System Interface CSSE 332 Operating Systems
Chapter 13: File-System Interface
Chapter 10: File-System Interface
Unit V File-System.
Module 10: File-System Interface
Chapter 10: File System.
Chapter 11: File-System Interface
Operating Systems (CS 340 D)
Chapter 10: File-System Interface
Chapter 11: File-System Interface
Chapter 10: File-System Interface
Chapter 10: File-System Interface
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 Chapter 10: File-System.
File-System Interface
Module 10: File-System Interface
Chapter 10 File-System Interface
Lecture 4: File-System Interface
Presentation transcript:

Operating System File System Monday, August 11, 2008

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

A Typical File-system Organization 8/11/2008 6:14 PM bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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 bettynj@gmail.com

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

General Graph Directory 8/11/2008 6:14 PM bettynj@gmail.com

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 bettynj@gmail.com

Keystone Three access methods Common directory structure 8/11/2008 6:14 PM bettynj@gmail.com

Operating System File and Directory Monday, August 11, 2008