(Ch11) File System Interface
(Ch11) File System Interface
Chapter 11
File-System Interface
1
File-System Interface
• File Concept
• Access Methods
• Directory Structure
• File-System Mounting
• File Sharing
• Protection
2
Objectives
4
File Concept (cont…)
5
File Concept (cont…)
• Types:
– Data files may be
• Numeric
• Alphabetic
• Character
• Binary
6
File Structure
• Certain defined structures according to its types.
7
File Attributes
• 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.
12
File Operations (cont…)
• File pointer.
– System must track the last read/write location as a
current file position pointer.
– Pointer is unique to each process operating on the file.
– Must be kept separate from the on-disk file attributes.
• Memory mapping.
– Allows a part of the virtual address space to be logically
associated with a section of file.
14
Open Files
15
Open File Locking
16
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(); 17
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();
}
}
} 18
File Types – Name, Extension
19
Access Methods
• Sequential Access:
– Simple access method.
– Information in the file is processed in order, one record
after the other.
– Editors and compliers usually access files in this
fashion.
read next
write next
reset
no read after last write
(rewrite)
20
Access Methods
• Direct Access (relative access)
– Allows arbitrary blocks to be read or written.
– We may read block 14, then 53, and then 7.
– No restrictions.
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
21
Access Methods
• Direct Access (relative access) (Contd).
22
Sequential-access File
23
Simulation of Sequential Access on a Direct-
Access File
24
Other Access Methods
25
Other Access Methods (cont…)
• Solution:
– Create an index for the index file.
– Primary index file would contain pointers to secondary
index files, which would point to the actual data items.
26
Example of Index and Relative Files
27
Directory Structure
• A collection of nodes containing information about all files.
Directory
Files
F1 F2 F4
F3
Fn
30
Information in a Device Directory
• Name
• Type
• Address
• Current length
• Maximum length
• Date last accessed
• Date last updated
• Owner ID
• Protection information
32
Organize the Directory (Logically) to Obtain
33
Single-Level Directory
Naming problem
Grouping problem
34
Two-Level Directory
• Path name
• Can have the same file name for different user
• Efficient searching
• No grouping capability
35
Tree-Structured Directories
36
Tree-Structured Directories (Cont…)
• Efficient searching
• Grouping Capability
37
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 mail
39
Acyclic-Graph Directories (Cont…)
• Two different names (aliasing)
40
General Graph Directory
41
General Graph Directory (Cont...)
42
File System Mounting
43
(a) Existing. (b) Unmounted Partition
44
Mount Point
45
File Sharing
• Sharing of files on multi-user systems is desirable
46
File Sharing – Multiple Users
47
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
48
access to information needed for remote computing
File Sharing – Failure Modes
49
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
– 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
50
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
51
Access Lists and Groups
• Mode of access: read, write, execute
• Three classes of users
RWX
a) owner access 7 111
RWX
b) group access 6 110
RWX
c) public access 1 001
• 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.
owner group public
53
A Sample UNIX Directory Listing
54