File-System Interface: Silberschatz, Galvin and Gagne ©2018 Operating System Concepts
File-System Interface: Silberschatz, Galvin and Gagne ©2018 Operating System Concepts
File-System Interface
■ File Concept
■ Access Methods
■ File-System Mounting
■ File Sharing
■ Protection
● Create
● 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
● File pointer: pointer to last read/write location, per process that has the
file open
■ Mandatory or advisory:
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();
Directory
Files
F1 F2 F4
F3
Fn
● Each volume containing file system also tracks that file system’s info in
device directory or volume table of contents
■ Create a file
■ Delete a file
■ List a directory
■ Rename a file
■ Naming problem
■ Grouping problem
■ Path name
■ Can have the same file name for different user
■ Efficient searching
■ No grouping capability
■ Efficient searching
■ Grouping Capability
cd /spell/mail/prog
type list
■ Delete a file
rm <file-name>
mkdir <dir-name>
mkdir count
● Solutions:
4 Entry-hold-count solution
● Garbage collection
users
help doc
prog
(a) (b)
■ If multi-user system
■ Remote file systems add new failure modes, due to network failure,
server failure
4 Tend to be less complex due to disk I/O and network latency (for remote file
systems
4 Writes to an open file visible immediately to other users of the same open file
4 Sharing file pointer to allow multiple users to read and write concurrently
● by whom
■ Types of access
● Read
● Write
● Execute
● Append
● Delete
● List
■ 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
■ A major task for the operating system is to map the logical file
concept onto physical storage devices such as hard disk or NVM
device. Since the physical record size of the device may not be the
same as the logical record size, it may be necessary to order logical
records into physical records. Again, this task may be supported by
the operating system or left for the application program.