Title: Chapter 10: FileSystem Interface
1Chapter 10 File-System Interface
2Motivation
- What is a file system?
- Why necessary?
- How to unify multiple file systems?
3What is a file system?
4File Concept
- Contiguous logical storage space
- With structure defined by OS/application
- Simple record structure
- Lines
- Fixed length
- Variable length
- Complex Structures
- Formatted document
5File Attributes
- Name for human identification
- Identifier unique tag (number) within file
system - Type
- Location
- Size
- Protection controls who can do reading,
writing, executing - Time, date, and owner data for protection,
security, and usage monitoring - File information kept in directory structure
6File Operations
- Create
- Write
- Read
- Reposition within file (eg., file seek)
- Delete
- Truncate (erasing the contents)
7Implementing File Operations
8Open Files
- Necessary information
- 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 (eg., multiple processes) - Disk location of the file cache of data access
information - Access rights per-process access mode information
9Open File Locking
- Provided by OS/file system
- Mediates access to a file
- Mandatory or advisory
- Mandatory access is denied depending on locks
- Advisory processes can find status of locks and
decide what to do (eg., readonly)
10File Locking Example
- 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("fi
le.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()
11File Locking Example
- // this locks the second half of the file -
shared - sharedLock ch.lock(raf.length()/21,
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()
-
-
-
12File Types Name, Extension
13Access Methods?
- File Attribute/Operation/Type
- Access?
14Access Methods
- Sequential Access
- read next
- write next
- reset
- Direct Access
- read n
- write n
- position to n
- n relative block address
- Indexed Access
-
- read (smith)
15Remote Control Analogy
16Sequential vs. Direct Access
17Brainstorming
- What does it take to support a direct access?
- Contiguous
- Otherwise
- What does it take to support an indexed access?
18Indexed Access
19Directory
- File
- Directory
- Why? What? How?
20Why Necessary?
- Efficiency locating a file quickly
- Convenience
- Naming convenient to users
- Files w/ same name can exist for different
directories - Grouping logical grouping of files by
properties, (e.g., all Java programs, all games,
)
21Directory Structure
- A collection of nodes containing information
about files within
Directory
Files
F 1
F 2
F 3
F 4
F n
22Directory Operations
- Create/delete/rename directories
- List a directory
- Search for a file
- Create a file
- Delete a file
- Rename a file
- Traverse the file system (eg., backup)
23What is an ideal structure?
24Single-Level Directory
- A single directory for all users
25Two-Level Directory
- Separate directory for each user
- Can have the same file name (if by different
user) - Inefficient search
- No grouping capability
26Then what?
27Tree-Structured Directories
28Tree-Structured Directories (Contd)
- Efficient searching
- Grouping capability
- Locating files
- Absolute path (from root)
- Relative path (from current)
29Is the structure always a tree?
30Acyclic-Graph Directory Structure
- May have shared subdirectories and files
31Pros and Cons
- Avoid inconsistent copies
- Complication
32Acyclic-Graph Complications
- dangling pointer
- Solutions
- Whenever file is deleted (soft link)
- Wait until all refs deleted (hard link)
- How can you implement these solutions?
33Now, General Graph Directory
34Brainstorming
- What are new complications?
- What are the solutions?
35General Graph Directory
- New complications
- Traversal may take forever
- ? possibly infinite paths
- Deciding whether to delete
- ? Reference count is infinite
36Unified file system structure
- Multiple disks
- Multiple machines
37NN mapping
38File System Mounting
- A remote file system can be mounted
39Do you see potential problems?
40Case Study Remote Failures
- Remote file systems add new failure modes, (e.g.,
network failure, server failure - Recovery from failure can involve state
information - Stateless protocols such as NFS include all
information in each request, allowing easy
recovery but less security
41File Consistency
42Consistency Unix vs. AFS
- Consistency semantics specify how multiple users
are to access a shared file - Unix file system implements
- Writes to an open file visible immediately to
other users of the same open file (modified,
reload?) - AFS has session semantics
- Writes only visible to sessions starting after
the file is closed
43File Protection
44A Sample UNIX Directory Listing
45Access Lists and Groups
- Mode of access read, write, execute
- RWX
- a) owner access 7 ? 1 1 1 RWX
- b) group access 6 ? 1 1 0
- RWX
- c) public access 1 ? 0 0 1
- For a particular file (say exam_solution) or
subdirectory, define an appropriate access.
owner
group
public
exam_solution
chmod
761
Attach a group to a file chgrp
staff exam_solution
46Protection
- File owner/creator should be able to control
- what can be done
- by whom
- Types of access
- Read
- Write
- Execute
- Append
- Delete
- List
47Windows Example
48End of Chapter 10