Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10: File-System Interface

Similar presentations


Presentation on theme: "Chapter 10: File-System Interface"— Presentation transcript:

1 Chapter 10: File-System Interface

2 Chapter 10: File-System Interface
File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

3 Objectives To explain the function of file systems
To describe the interfaces to file systems To discuss file-system design tradeoffs, including access methods, file sharing, file locking, and directory structures To explore file-system protection

4 File Concept A logical storage unit is abstracted as file
Contiguous logical address space OS maps from the logical address space to physical devices. Types: Data numeric character binary Program ( source and object forms) File has certain structure Text file: a sequence of characters in lines Source file: a sequence of subroutines and function Object file: a sequence of bytes in blocks understandable by linker Executable file: a series of code sections that loader can bring into memory and execute

5 File Attributes Name – (a string of characters) only information kept in human-readable form Identifier – unique tag (number) identifies file within file system Type – needed for systems that support different types Location – pointer to file location on device Size – current file size in bytes, words or blocks Protection – controls who can do reading, writing, executing Time, date, and user identification – creation, last modification and last use. such data for protection, security, and usage monitoring Information about files are kept in the directory structure, which is maintained on the disk. Each directory entry consists of the file’s name and identifier. File directory will be read into memory piecemeal as needed.

6 File Operations File is an abstract data type
Create: allocate space and insert an entry in directory Write: system call with file name and information to be written. search directory to find location, write pointer to the file location. Read: system call with file name and location to read from. Reposition within file: directory is searched and the current file position pointer is repositioned to a given value. Delete: Search the directory, release all file space and erase the directory entry. Truncate: all attributed remain unchanged except the file length to be zero and space released. Top avoid constant searching: open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory in a open-file table. A pointer is returned. Close (Fi) – move the content of entry Fi in memory to directory structure on disk. Remove entry from open-file table.

7 Open Files Two levels of internal table: a per-process table and a system-wide table. Per-process table tracks all files that a process has open. e.g. current pointer, access right. System-wide table contains information that is process-independent e.g. location of file on disk, file size. Several pieces of data are needed to manage open files: File pointer: pointer to last read/write location, unique to each 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: most operations modify data of the file. Kept in memory so no need to read it every time from disk. Cache purpose. Access rights: per-process access mode information

8 Open File Locking Provided by some operating systems and file systems
file locks provide functionality similar to reader-writer locks. A shared lock is akin to a reader lock. An exclusive lock like a writer lock only one process at a time can acquire such a lock. Mandatory or advisory mechanism: Mandatory – access is denied depending on locks held and requested Advisory – processes can find status of locks and decide what to do. Windows use Mandatory locks and Unix use advisory locks. Programmers under mandatory locking must be careful to hold exclusive file lock only when they are accessing the file.

9 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();

10 File Locking Example – Java API (cont)
// 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(); }

11 File Types – Name, Extension

12 Access Methods Sequential Access: processed in order, one record after the other. E.g. read next: read the next portion of the file and automatically advances a file pointer. A program may be able to skip forward or backward n records. Editor and compilers usually access files in this fashion. Direct Access: file made up of fixed length logical records that allow random access in no particular order. For example, we can read block 14, then read block 53, and then write block 7

13 Sequential-access File

14 Simulation of Sequential Access on a Direct-access File

15 Example of Index and Relative Files
Other access method can be built on top of a direct-access method. For example, author index at the back of a book, can be used to find page number. To find a record in a file, we first search an index file and use the pointer to access the file directly and find the record. Index file in memory and is usually ordered and can be searched using binary search.

16 Directory Structure To manage files, we need to organize them. Symbol table that translates file names into their directory entries. 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

17 A Typical File-system Organization
A disk can be used entirely for one file system or partitioned to allow multiple file systems.

18 Operations Performed on Directory
Search for a file: find the entry for a file Create a file: new entry created and added to directory Delete a file: remove it from directory List a directory: show the contents of the all directory entries Rename a file: also allow it position within directory to be changed. Traverse the file system: access every directory and every file within that directory.

19 Organize the Directory (Logically) 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, …)

20 Single-Level Directory
All files are contained in the same directory. Easy to implement and understand. A single directory for all users: so all files must have unique names. Even single user may find it difficult to remember all names due to big number of files. Naming problem Grouping problem

21 Two-Level Directory Separate directory for each user. Each user has his own user file directory (UFD). Can have the same file name for different user Specify the Path name (user name and file name): The root is master file directory (MFD), below it are UFDs, below UFD are files. Efficient searching For system files (loaders, compilers, libraries), can be put in a special user directory, which will be searched in current UFD does not contain it.

22 Tree-Structured Directories

23 Tree-Structured Directories (Cont)
A directory contains a set of files or subdirectories. A directory is simply another file. Current directory (working directory) and should contain most of the files that are of current interest to the process. e.g. root/spell/mail Path names can be of two types: absolute and relative. Absolute path name begins at the root and follows a path down to the specified file. e.g. root/spell/mail/prt/first A relative path defines a path from the current directory. e.g. prt/first cd /spell/mail/prog type list

24 Tree-Structured Directories (Cont)
Delete a file rm <file-name> Creating a new subdirectory is done in current directory mkdir <dir-name> Example: if in current directory /mail mkdir count mail prog copy prt exp count Deleting “mail”  deleting the entire subtree rooted by “mail”

25 Acyclic-Graph Directories
For example, two programmers are working on a joint project. They need to share some files. A shared file/subdirectory can exist in the file system in two ore more places at once.

26 Acyclic-Graph Directories (Cont.)
Implemented in several ways: Unix create a new directory entry called a link. A pointer to another file or subdirectory. Link – another name (pointer) to an existing file Resolve the link – follow pointer to locate the file Same file may have multiple absolute path names. Problem arise if we want to traverse the entire file system since we do not want to traverse shared structures more than once. If deletes share file dangling pointer to the now-nonexistent file. If the disk space is reused by other file, then dangling point may change the content of other file. Preserve the file until all references to it are deleted. If using symbolic link for sharing, only the link is removed and the file is intact. If file removed, links are left. User can find out missing file error.

27 General Graph Directory

28 General Graph Directory (Cont.)
When we add links to existing tree structures, we may end up with graph structure with cycles. Acyclic graph is simple to traverse and to determine when there are no more references to a file. A reference count associated with each file or directory to indicate if we can safely delete it. If cycle exists, a poor algorithm might result in infinite loop searching through the cycle.

29 File System Mounting A file must be opened before use.
A file system must be mounted before it can be accessed OS is given the name of the device and the mount point --- the location within the file structure where the file system is to be attached. A mount point is usually an empty directory. OS verifies that the device contains a valid file system. Device driver reads the device directory with right format.

30 (a) Existing. (b) Unmounted Partition
A unmounted file system (i.e. Fig (b)) is mounted at a mount point

31 Mount Point Some system may not allow a mount over a directory that contains files. Or it may temporarily hide the existing files until the file system is unmounted.

32 File Sharing Sharing of files on multi-user systems is desirable
Sharing may be done through a protection scheme On distributed systems, files may be shared across a network Network File System (NFS) is a common distributed file-sharing method

33 File Sharing – Multiple Users
To implement sharing and protection, most system use concepts of file(or directory), owner ( or user) and group. Owner is the user who can change attributes and grant access. With the most control over the file. Group defines the subset of users who can share access to the file For example, owner of a file can issue all operations on a file, while members of a group can execute one subset of those operations. Such privileges are defined by the owner. Owner and group IDs of a give file are stored with other file attributes. When a user requests an operation on a file, the user ID can be compared with the owner ID.

34 File Sharing – Remote File Systems
Uses networking to allow file system access between remote computers Manually via programs like FTP Automatically, seamlessly using distributed file systems, in which remote directories are visible from local machine. Semi automatically via the world wide web Client-server model allows clients to mount remote file systems from servers Server can serve multiple clients NFS is standard UNIX client-server file sharing protocol, and its authentication is done by the client networking information. Distributed Information Systems (distributed naming services) such as DNS (domain name system) implement unified access to information needed for remote computing

35 File Sharing – Failure Modes
Local file system can fail due to disk failure, corruption of the directory structure etc. Remote file systems add new failure modes, due to network failure, and interaction between remote machines. Recovery from failure can involve state information about status of each remote request

36 File Sharing – Consistency Semantics
Consistency semantics specify how multiple users are to access a shared file simultaneously Similar to Ch 7 process synchronization algorithms Tend to be less complex due to disk I/O and network latency (for remote file systems Unix file system (UFS) implements: Writes to an open file visible immediately to other users of the same open file One mode allows sharing file pointer to allow multiple users to read and write a single image concurrently. Advancing pointer by one affects all sharing users.

37 Protection File should be safe from physical damage and improper access. File owner/creator should be able to control: what can be done by whom Types of access Read Write Execute Append Delete List

38 Access Lists and Groups
Mode of access: read, write, execute Three classes of users RWX a) owner access 7  RWX b) group access 6  1 1 0 c) public access 1  0 0 1 create a group (unique name), say G, and add some users to the group. Those users need to share the file with similar access right. For a particular file (say game) or subdirectory, define an appropriate access. owner group public chmod 761 game Attach a group to a file chgrp G game

39 Windows XP Access-control List Management

40 A Sample UNIX Directory Listing

41 End of Chapter 10


Download ppt "Chapter 10: File-System Interface"

Similar presentations


Ads by Google