550 likes | 611 Views
Chapter 10: File-System Interface. Chapter 11: File-System Interface. File Concept Access Methods Disk and Directory Structure File-System Mounting File Sharing Protection. Objectives. To explain the function of file systems To describe the interfaces to file systems
E N D
Chapter 11: File-System Interface • File Concept • Access Methods • Disk and Directory Structure • File-System Mounting • File Sharing • Protection
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
File Concept • Contiguous logical address space • Types: • Data • numeric • character • binary • Program • Contents defined by file’s creator • Many types • Consider text file, source file, executable file
File Attributes 1.Name Every file carries a name by which the file is recognized in the file system. One directory cannot have two files with the same name. 2.Identifier Along with the name, Each File has its own extension which identifies the type of the file. For example, a text file has the extension .txt, A video file can have the extension .mp4. 3.Type In a File System, the Files are classified in different types such as video files, audio files, text files, executable files, etc. 4.Location In the File System, there are several locations on which, the files can be stored. Each file carries its location as its attribute. 5.Size The Size of the File is one of its most important attribute. By size of the file, we mean the number of bytes acquired by the file in the memory. 6.Protection The Admin of the computer may want the different protections for the different files. Therefore each file carries its own set of permissions to the different group of Users. 7.Time and Date Every file carries a time stamp which contains the time and date on which the file is last modified.
File Operations 1.Create Creation of the file is the most important operation on the file. Different types of files are created by different methods for example text editors are used to create a text file, word processors are used to create a word file and Image editors are used to create the image files. 2.Write Writing the file is different from creating the file. The OS maintains a write pointer for every file which points to the position in the file from which, the data needs to be written. 3.Read Every file is opened in three different modes : Read, Write and append. A Read pointer is maintained by the OS, pointing to the position up to which, the data has been read. 4.Re-position Re-positioning is simply moving the file pointers forward or backward depending upon the user's requirement. It is also called as seeking. 5.Delete Deleting the file will not only delete all the data stored inside the file, It also deletes all the attributes of the file. The space which is allocated to the file will now become available and can be allocated to the other files. 6.Truncate Truncating is simply deleting the file except deleting attributes. The file is not completely deleted although the information stored inside the file get replaced.
Open Files • Several pieces of data are needed to manage open files: • Open-file table: tracks 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
Open File Locking • Provided by some operating systems and file systems • Similar to reader-writer locks • Sharedlock similar to reader lock – several processes can acquire concurrently • Exclusive lock similar to writer lock • 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
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();
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 sharedLock.release(); }catch (java.io.IOException ioe) { System.err.println(ioe); }finally { if (exclusiveLock != null) exclusiveLock.release(); if (sharedLock != null) sharedLock.release(); } } }
File Structure • None - sequence of words, bytes • Simple record structure • Lines • Fixed length • Variable length • Complex Structures • Formatted document • Relocatable load file • Can simulate last two with first method by inserting appropriate control characters • Who decides: • Operating system • Program
Access Methods • Sequential AccessMost of the operating systems access the file sequentially. In other words, we can say that most of the files need to be accessed sequentially by the operating system. • In sequential access, the OS read the file word by word. A pointer is maintained which initially points to the base address of the file. If the user wants to read first word of the file then the pointer provides that word to the user and increases its value by 1 word. This process continues till the end of the file. • Modern word systems do provide the concept of direct access and indexed access but the most used method is sequential access due to the fact that most of the files such as text files, audio files, video files, etc need to be sequentially accessed.
Access Methods • Direct Access • The Direct Access is mostly required in the case of database systems. In most of the cases, we need filtered information from the database. The sequential access can be very slow and inefficient in such cases. • Suppose every block of the storage stores 4 records and we know that the record we needed is stored in 10th block. In that case, the sequential access will not be implemented because it will traverse all the blocks in order to access the needed record. • Direct access will give the required result despite of the fact that the operating system has to perform some complex tasks such as determining the desired block number. However, that is generally implemented in database applications.
Other Access Methods • Can be built on top of base methods • General involve creation of an index for the file • Keep index in memory for fast determination of location of data to be operated on (consider UPC code plus record of data about that item) • If too large, index (in memory) of the index (on disk) • IBM indexed sequential-access method (ISAM) • Small master index, points to disk blocks of secondary index • File kept sorted on a defined key • All done by the OS • VMS operating system provides index and relative files as another example (see next slide)
Directory Structure • A collection of nodes containing information about all files Directory Files F 1 F 2 F 3 F 4 F n Both the directory structure and the files reside on disk
Disk Structure Disk can be subdivided into partitions Disks or partitions can be RAID protected against failure Disk or partition can be used raw– without a file system, or formattedwith a file system Partitions also known as minidisks, slices Entity containing file system known as a volume Each volume containing file system also tracks that file system’s info in device directoryor volume table of contents As well as general-purpose file systemsthere are many special-purpose file systems, frequently all within the same operating system or computer
Types of File Systems • We mostly talk of general-purpose file systems • But systems frequently have may file systems, some general- and some special- purpose • Consider Solaris has • tmpfs – memory-based volatile FS for fast, temporary I/O • objfs – interface into kernel memory to get kernel symbols for debugging • ctfs – contract file system for managing daemons • lofs – loopback file system allows one FS to be accessed in place of another • procfs – kernel interface to process structures • ufs, zfs – general purpose file systems
Operations Performed on Directory • Search for a file • Create a file • Delete a file • List a directory • Rename a file • Traverse the file system
Directory Organization The directory is organized 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, …)
Single-Level Directory • A single directory for all users • The simplest method is to have one big list of all the files on the disk. The entire system will contain only one directory which is supposed to mention all the files present in the file system. The directory contains one entry per each file present on the file system. • Naming problem • Grouping problem
Single-Level Directory • This type of directories can be used for a simple system. Advantages • Implementation is very simple. • If the sizes of the files are very small then the searching becomes faster. • File creation, searching, deletion is very simple since we have only one directory. Disadvantages • We cannot have two files with the same name. • The directory may be very big therefore searching for a file may take so much time. • Protection cannot be implemented for multiple users. • There are no ways to group same kind of files. • Choosing the unique name for every file is a bit complex and limits the number of files in the system because most of the Operating System limits the numbe
Two-Level Directory • Separate directory for each user • Each files has a path name as /User-name/directory-name/ • Different users can have the same file name. • Searching becomes more efficient as only one user's list needs to be traversed. • The same kind of files cannot be grouped into a single directory for a particular user. • Every Operating System maintains a variable as PWD which contains the present directory name (present user name) so that the searching can be done appropriately.
Tree-Structured Directories • In Tree structured directory system, any directory entry can either be a file or sub directory. Tree structured directory system overcomes the drawbacks of two level directory system. The similar kind of files can now be grouped in one directory. • Each user has its own directory and it cannot enter in the other user's directory. However, the user has the permission to read the root's data but he cannot write or modify this. Only administrator of the system has the complete access of root directory. • Searching is more efficient in this directory structure. The concept of current working directory is used. A file can be accessed by two types of path, either relative or absolute. • Absolute path is the path of the file with respect to the root directory of the system while relative path is the path with respect to the current working directory of the system. In tree structured directory systems, the user is given the privilege to create the files as well as directories.
Tree-Structured Directories (Cont.) • Efficient searching • Grouping Capability • Current directory (working directory) • cd /spell/mail/prog • type list
Tree-Structured Directories (Cont) • Absolute or relative path name • Creating a new file is done in current directory • 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 Deleting “mail” deleting the entire subtree rooted by “mail”
Acyclic-Graph Directories • Have shared subdirectories and files
Acyclic-Graph Directories • The tree structured directory system doesn't allow the same file to exist in multiple directories therefore sharing is major concern in tree structured directory system. We can provide sharing by making the directory an acyclic graph. In this system, two or more directory entry can point to the same file or sub directory. That file or sub directory is shared between the two directory entries. • These kinds of directory graphs can be made using links or aliases. We can have multiple paths for a same file. Links can either be symbolic (logical) or hard link (physical). • If a file gets deleted in acyclic graph structured directory system, then • In the case of soft link, the file just gets deleted and we are left with a dangling pointer. • In the case of hard link, the actual file will be deleted only if all the references to it gets deleted.
Acyclic-Graph Directories (Cont.) • Two different names (aliasing) • If dict deletes list dangling pointer Solutions: • Backpointers, so we can delete all pointersVariable size records a problem • Backpointers using a daisy chain organization • Entry-hold-count solution • New directory entry type • Link – another name (pointer) to an existing file • Resolve the link – follow pointer to locate the file
Absolute vs. Relative Paths • There are two ways to specify a file path. • An absolute path, which always begins with the root folder • A relative path, which is relative to the program’s current working directory • There are also the dot (.) and dot-dot (..) folders. These are not real folders but special names that can be used in a path. A single period (“dot”) for a folder name is shorthand for “this directory.” Two periods (“dot-dot”) means “the parent folder.” • Here, is an example of some folders and files. When the current working directory is set to C:\bacon, the relative paths for the other folders and files are set as they are in the figure.
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
File System Mounting • A file system must be mounted before it can be accessed • A unmounted file system (i.e., Fig. 11-11(b)) is mounted at a mount point
10.4 File System Mounting • A file system must be mounted before it can be accessed • A unmounted file system (i.e. Fig. 10-11(b)) is mounted at a mount point existing mount point unmounted volume
Mount Point • The OS is first given the name of the device and the mount point • The OS verifies that the device contains a valid file system • Read the device directory and verify the directory format • The OS notes in the directory structure that a file system is mounted at the specified mount point • If the volume is unmounted, the file system is restored to the situation before mounting • OS may impose semantics to clarify functionality • May disallow a mount over a directory containing files; or may obscure the directory’s existing files until the file system is unmounted • May allow the same file system to be mounted repeatedly, at different mount points; or it may allow only one mount per file system
Mount Examples • Macintosh searches for a file system on a disk first encountered. If found, the file system is auto-mounted at the root level • Windows OS maintains an extended two-level directory structure, with devices and volumes assigned drive letters. • Recent Windows allow a file system to be mounted anywhere in the directory tree • Windows auto-discover all devices and mount all located file systems at boot time • Unix has explicit mount commands
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 • If multi-user system • User IDs identify users, allowing permissions and protections to be per-userGroup IDs allow users to be in groups, permitting group access rights • Owner of a file / directory • Group of a file / directory
File Sharing – Remote File Systems • Uses networking to allow file system access between systems • Manually via programs like FTP • Automatically, seamlessly using distributed file systems • Semi automatically via theworld wide web • Client-server model allows clients to mount remote file systems from servers • Server can serve multiple clients • Client and user-on-client identification is insecure or complicated • NFS is standard UNIX client-server file sharing protocol • CIFS is standard Windows protocol • Standard operating system file calls are translated into remote calls • Distributed Information Systems (distributed naming services) such as LDAP, DNS, NIS, Active Directory implement unified access to information needed for remote computing
File Sharing – Failure Modes • All file systems have failure modes • For example corruption of directory structures or other non-user data, called metadata • Remote file systems add new failure modes, due to network failure, server failure • Recovery from failure can involve state information about status of each remote request • Stateless protocols such as NFS v3 include all information in each request, allowing easy recovery but less security
File Sharing – Consistency Semantics • Specify how multiple users are to access a shared file simultaneously • Similar to Ch 5 process synchronization algorithms • Tend to be less complex due to disk I/O and network latency (for remote file systems • Andrew File System (AFS) implemented complex remote file sharing semantics • Unix file system (UFS) implements: • Writes to an open file visible immediately to other users of the same open file • Sharing file pointer to allow multiple users to read and write concurrently • AFS has session semantics • Writes only visible to sessions starting after the file is closed
Protection • File owner/creator should be able to control: • what can be done • by whom • Types of access • Read • Write • Execute • Append • Delete • List
Access Lists and Groups • Mode of access: read, write, execute • Three classes of users on Unix / Linux RWX a) owner access 7 1 1 1 RWX b) group access 6 1 1 0 RWX c) public access 1 0 0 1 • Ask manager to create a group (unique name), say G, and add some users to the group. • For a particular file (say game) or subdirectory, define an appropriate access. Attach a group to a filechgrp G game