3.1. File System Interface-File Concepts, Access Methods
3.1. File System Interface-File Concepts, Access Methods
Course Outcome:
Upon completion of the session, students shall have ability to
CO5 Apply concepts of file system interface,implementation, and disk management [AP]
to optimize storage utilization and random access to files.
What is File?
File Attributes
File Systems
• In 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
File 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
FILE OPERATIONS
1.Create operation
2.Open Files
– This operation is the common operation performed on the file.
– Once the file is created, it must be opened before performing the file
processing operations.
– When the user wants to open a file, it provides a file name to open the
particular file in the file system.
– It tells the operating system to invoke the open system call and passes the
file name to the file system.
3. Write operation
• To write the information into a file.
• A system call write is issued that specifies the name of the file and the length of
the data has to be written to the file.
• Whenever the file length is increased by specified value and the file pointer is
repositioned after the last byte written.
4. Read operation
6. Delete operation
• Deleting the file will not only delete all the data stored inside the file it is also
used so that disk space occupied by it is freed.
• In order to delete the specified file the directory is searched. When the
directory entry is located, all the associated file space and the directory entry is
released.
7. Truncate operation
• Truncating is simply deleting the file except deleting attributes. The file is not
completely deleted although the information stored inside the file gets replaced.
8. Close operation
• When the processing of the file is complete, it should be closed so that all the
changes made permanent and all the resources occupied should be released.
• On closing it deallocates all the internal descriptors that were created when the
file was opened.
9. Append operation
This operation adds data to the end of the file.
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:
– Mandatory – access is denied depending on locks held and
requested
– Advisory – processes can find status of locks and decide what to do
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 Structure
Access Methods
Sequential Access
• Information in the file is processed in order, one record after the other.
• Read command begin a pointer to change its position ahead by one.
• Write command assigns space for the account and move the pointer to the new
Head Of the current File.
• Such a way is cheap for tape.
• Operations
– read next
– write next
– Reset
– no read after last write (rewrite)
• Figure
Direct Access
Direct Access
• Operations
– read n
– write n
– position to n
• read next
• write next
• rewrite n
n = relative block number
• Relative block numbers allow OS to decide where file should be placed
• Compatibility issues: Different file systems may not be compatible with each
other, making it difficult to transfer data between different operating systems.
• Disk space overhead: File systems may use some disk space to store metadata
and other overhead information, reducing the amount of space available for user
data.
• Vulnerability: File systems can be vulnerable to data corruption, malware, and
other security threats, which can compromise the stability and security of the
system.
Try……
Try……
• Tell me the advantages and disadvantages of Direct and sequential file access.
Next Session…
3.2 Directory Structure and organization