Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11: File-System Interface

Similar presentations


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

1 Chapter 11: File-System Interface

2 Chapter 11: File-System Interface
File Concept Access Methods Disk and 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 User Requirements for Data
Persistence – data stays between program invocations, power cycles, crashes. (Requires nonvolatile storage). Speed – get data quickly. Size – can store as much data as needed. Sharing/Protection – share when appropriate or keep private if necessary. Ease of use – user can easily find, examine, modify data, etc.

5 Hardware / OS Features Hardware provides:
Persistence: Disks provide non-volatile memory. Speed: Speed gained through random (direct) access. Size: Disks keep getting bigger. Operating System provides: Persistence: Redundancy allows for recovery from failures Sharing/Protection: Ease of Use: Associate names with chunks of data (files). Organize large collections of files into directories. Map user’s concept of files and directories onto storage devices.

6 File Systems File System consists of A collection of files
A directory structure (possibly) Partitions Important Issues File protection The semantics of file sharing Note: Historically speaking, operating systems and file systems have been viewed as distinct entities. From the perspective of the modern user, this distinction is often blurred. Storage devices for file systems are nonvolatile.

7 File Concept File is the logical unit of data on a storage device.
A uniform logical abstraction for the physical storage of information Represented as a contiguous logical address space Types of files: Data numeric character binary Program, Documents, Images Contents defined by file’s creator Many types - examples Consider text file, source file, executable file

8 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

9 File Types – Name, Extension

10 File Attributes - metadata
Name – 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 Protection – controls who can do reading, writing, executing Time, date, and user identification – data for protection, security, and usage monitoring, last access, last modification, create date. Information about files are kept in the directory structure, which is maintained on the disk Many variations, including extended file attributes such as file checksum

11 File info Window on Mac OS X

12 Open File Data Structures
Several pieces of data are needed to manage open files: Open-file table: tracks open files 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. (Reference counts) Disk location of the file: cache of data access information Location of contents in memory Per-process file table: tracks file pointer for each process. Open-file table pointer: back to open file table File pointer: pointer to last read/write location, per process that has the file open Access rights: per-process access mode information

13 File Operations File is an abstract data type supporting following operations Create Write – at write pointer location Read – at read pointer location Reposition within file – seek Delete Truncate 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

14 File Operations: Create
Create(name) Allocate disk space (check disk quotas, permissions, etc.) Create a file descriptor (unique identifier) for the file including name, location on disk, and all file attributes (other metadata). Add the file descriptor to the directory that contains the file. Optional file attribute: file type (Word, executable, etc.) Advantages: better error detection, specialized default operations (double clicking on file knows what application to start), enables storage layout optimizations. Improves ease of use. Disadvantages: makes the file system and operating system more complicated. Less flexible for user.

15 File Operations: Delete
Delete(name) Find the directory containing the file. Decrement the reference counts, in case of hard links. Free disk blocks used by file. Remove file descriptor from directory. Most of the time, contents remains on disk until the blocks are reallocated to another file. Forensics can find contents.

16 File Operations: open and close
fileID = open(name, mode) Check the protection of the file against the requested mode. If not allowed, abort. Otherwise… Check if the file is already opened by another process, if not, copy the file descriptor into the system wide open-file table Increment the file open count Create an entry in the process open file table pointing to the system open file table. Initialize current file pointer depending on mode. close(fileID) Remove the file from the process open file table. Decrement the open file count in the system-wide open file table. If open count is zero, remove from system-wide open file table.

17 File Operations: read read(fileID, from, size, bufferAddress) – random/direct access OS reads “size” bytes starting at “from” into “bufferAddress” for (int i = from; i < size; i++) bufferAddress[i-from] = file[i]; read(fileID, size, bufferAddress) - sequential access OS reads “size” bytes from current position (fp), into “bufferAddress” OS increments current file position by size. for (int i = 0; i < size; i++) bufferAddress[i] = file[fp+i]; fp += size;

18 File Operations write(fileID, size, bufferAddress);
Similar to read except that it copies from the buffer to the file. seek(fileID, position) Updates the fp (File Position) to the new position Used for random access in a sequential access file. Memory mapping file Map a portion of the virtual address space to the file. Read/write to that portion of memory – implies OS reads/writes from corresponding location in the file. File accesses are greatly simplified (no read/write system call required).

19 File Access Methods Common file access patterns from the programmer’s perspective: Sequential: data processed in order, a byte or record at a time. Most programs use this method. Example: compiler reading a source file. Direct: address a block based on a key value. Example: database search, hash table, dictionary Common file access patterns from the operating system perspective: Sequential: keep a pointer to the next byte in the file. Update the pointer on each byte. Direct: address any block within the file directly given an offset within the file. Also known as Random Access.

20 Open File Locking Provided by some operating systems and file systems
Similar to reader-writer locks Shared lock similar to reader lock – several processes can acquire concurrently Exclusive lock similar to writer lock Mediates access to a file Mandatory or advisory: depending on system Mandatory – access is denied depending on locks held and requested (Windows – which is why you can’t copy an open file) Advisory – processes can find status of locks and decide what to do (Linux – Advisory by default, Mandatory can be configured on a file system level when disk is mounted.)

21 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"); FileChannel ch = raf.getChannel(); // get the channel for the file // this locks the first half of the file - exclusive exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE); /** Now modify the data */ exclusiveLock.release(); // release the lock

22 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) }

23 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

24 Sequential-access File

25 Access Methods Sequential Access read next write next reset
no read after last write (rewrite) Direct Access – file is fixed length logical records read n write n position to n rewrite n n = relative block number Relative block number – index relative to the beginning of the file u the first relative block if the index 0, Assumes fixed record length. Given a logical record length L and a request for record N, an I/O request must be made starting at location N * L.

26 Simulation of Sequential Access on Direct-access File

27 Other Access Methods Can be built on top of base methods
Generally 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) UPC=Universal Product Code 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)

28 Example of Index and Relative Files

29 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

30 Disk Structure Disk can be subdivided into partitions
Disks or partitions can be RAID protected against failure The most common types are RAID 0 (striping=no protection), RAID 1 and its variants (mirroring), RAID 5 (distributed parity 3 disks), and RAID 6 (dual parity). Disk or partition can be used raw – without a file system, or formatted with 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 directory or volume table of contents As well as general-purpose file systems there are many special-purpose file systems, frequently all within the same operating system or computer

31 A Typical File-system Organization

32 Operations Performed on Directory
Search for a file Simple search or complicated pattern match: Unix/Linux find command Windows File Explorer Create a file When a new file is created, add the info to the directory Delete a file List a directory Rename a file Traverse the file system

33 Information in a Device Directory
Name Type Address Current length Date created Date last accessed Date last updated Owner ID Protection information

34 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, …)

35 Directory Structure A disk can be divided into one or more partitioned
MS-DOS/Windows – each partition is treated as a separate storage. ie. only dividing In Unix, several partitions can be organized into one logical structure Each partition contains a device directory, or volume table of contents (VTOC) to keep information about file within it name, location, size, type, and so forth

36 Single-Level Directory
A single directory for all users Naming problem Grouping problem FAT16, FAT32 – old Windows File Allocation Table. Directory up front, flat system. Limited file size, limited file system size. Used for simple, low memory storage devices. extFAT – still used for zip drives

37 Two-Level Directory Separate directory for each user Path name
Can have the same file name for different user Efficient searching No grouping capability

38 Tree-Structured Directories

39 Tree-Structured Directories (Cont.)
Efficient searching Grouping Capability Current directory (working directory) cd /spell/mail/prog type list

40 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”

41 Acyclic-Graph Directories
Have shared subdirectories and files – rectangle=link, circle=file A link that points to another link is a soft link, a link that points to a file is a hard link.

42 Acyclic-Graph Directories (Cont.)
Two different names (aliasing) If someone deletes /dict/w/list  dangling pointer for /dict/w and /spell/words – even though the file is still there! (/dict/all still has it) Solutions: Backpointers, so we can delete all pointers Variable 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

43 General Graph Directory

44 General Graph Directory (Cont.)
How do we guarantee no cycles? Allow only links to file not subdirectories Garbage collection Traverse an entire file system Time consuming task – inadequate Every time a new link is added use a cycle detection algorithm to determine whether it is OK

45 File System Mounting A file system must be mounted before it can be accessed For a given name of device, attach the device to a file system A unmounted file system (i.e., Fig (b)) is mounted at a mount point

46 Mount Point + MS Windows – a device (, or partition) can be mounted by assigning a drive letter (e.g. C:\\) + Unix – a device can be mounted any directory, or subdirectory

47 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-user Group IDs allow users to be in groups, permitting group access rights Owner of a file / directory Group of a file / directory

48 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 the world 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

49 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 NFS v4 actually includes security protocols and is stateful

50 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

51 Protection File owner/creator should be able to control:
what can be done by whom Types of access Read Write Execute Append Delete List

52 Access Lists and Groups
Mode of access: read, write, execute Three classes of users on Unix / Linux RWX a) owner access 7  RWX b) group access 6  1 1 0 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 file chgrp G game

53 Windows 7 Access-Control List Management

54 A Sample UNIX Directory Listing

55 End of Chapter 11


Download ppt "Chapter 11: File-System Interface"

Similar presentations


Ads by Google