0% found this document useful (0 votes)
152 views33 pages

3.1. File System Interface-File Concepts, Access Methods

This document discusses Module 3 of the 22CS301 Operating Systems course which covers file system interfaces, concepts, and access methods. The module contains 12 sessions that cover topics such as file concepts, directory structure, file system mounting, allocation methods, free space management, mass storage structure, disk scheduling, disk management, I/O systems, and system protection and security. Session 3.1 specifically discusses file system concepts including what a file is, file attributes, types of file systems, and common file operations such as create, open, write, read, seek, delete, truncate, and close.

Uploaded by

dhurgadevi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views33 pages

3.1. File System Interface-File Concepts, Access Methods

This document discusses Module 3 of the 22CS301 Operating Systems course which covers file system interfaces, concepts, and access methods. The module contains 12 sessions that cover topics such as file concepts, directory structure, file system mounting, allocation methods, free space management, mass storage structure, disk scheduling, disk management, I/O systems, and system protection and security. Session 3.1 specifically discusses file system concepts including what a file is, file attributes, types of file systems, and common file operations such as create, open, write, read, seek, delete, truncate, and close.

Uploaded by

dhurgadevi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

22CS301 - Operating Systems

22CS301 OPERATING SYSTEM

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Module 3- File and Device Management


Session Topic
3.1 File-System Interface: File concept – Access Methods

3.2 Directory Structure – Directory organization

3.3 File system mounting - File Sharing and Protection;

File System Implementation: File System


3.4
Structure- Directory implementation

3.5 Allocation Methods

3.6 Free Space Management

3.7 Mass Storage Structure

3.8 Disk Scheduling

3.9 Disk Management

3.10 I/O Systems

3.11 System Protection and Security,

3.12 System Threats

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

3.1 – File System Concepts

What is File?

A file is a named collection of related information


that is recorded on secondary storage such as
magnetic disks, magnetic tapes and optical disks.

A file is a sequence of bits, bytes, lines or records


whose meaning is defined by the files creator and
user.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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
• 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
• Information kept in the directory structure

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

File Systems

• A file system is a method an operating system uses to store, organize, and


manage files and directories on a storage device.

Types of file systems include:


• FAT (File Allocation Table): An older file system used by older versions of Windows and
other operating systems.
• NTFS (New Technology File System): A modern file system used by Windows. It
supports features such as file and folder permissions, compression, and encryption.
• ext (Extended File System): A file system commonly used on Linux and Unix-based
operating systems.
• HFS (Hierarchical File System): A file system used by macOS.
• APFS (Apple File System): A new file system introduced by Apple for their Macs and iOS
devices.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Types of 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

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating 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

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

FILE OPERATIONS

1.Create operation

This operation is used to create a file in the file system.


It is the most widely used operation performed on the file system.
To create a new file of a particular type the associated application program calls the file
system.
This file system allocates space to the file.
As the file system knows the format of directory structure, so entry of this new file is made
into the appropriate directory.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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.

– Open-file table: tracks open files


– 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 – to allow
removal of data from open-file table when last processes closes it
– Disk location of the file: cache of data access information
– Access rights: per-process access mode information

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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

• Reads the contents from a file.


• A Read pointer is maintained by the OS, pointing to the position up to which
the data has been read.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

5. Re-position or Seek operation


• The seek system call re-positions the file pointers from the current position to a
specific place in the file i.e. forward or backward depending upon the user's
requirement.
• This operation is generally performed with those file management systems that
support direct access files.

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.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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.

10. Rename operation

This operation is used to rename the existing file.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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();

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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();
}
}
}

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

File Types – Name, Extension

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Access Methods

• A file is fixed length logical records


• File access method is a way of accessing and manipulating data stored in a
file. It determines how data is read and written in computer storage devices.
• It can be accessed in one of the following ways:
• Sequential Access
• Direct Access
• Other Access Methods

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Direct Access

• Also known as relative access method.


• A fixed-length logical record that allows the program to read and write record rapidly in no
particular order.
• The direct access is based on the disk model of a file since disk allows random access to
any file block.
• For direct access, the file is viewed as a numbered sequence of block or record.
• There is no restriction on the order of reading and writing for a direct access file.
A block number provided by the user to the operating system is normally a relative block
number, the first relative block of the file is 0 and then 1 and so on.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

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

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Other Access Methods

Index sequential method


• It is the other method of accessing a file that is built on the top of the sequential
access method.
• These methods construct an index for the file.
• The index, like an index in the back of a book, contains the pointer to the various
blocks. To find a record in the file, we first search the index, and then by the help
of pointer we access the file directly.

.Relative Record Access –


• Records are accessed relative to the current position of the file pointer.
• Records are located based on their position relative to the current record, rather
than by a specific address or key value.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Example of Index and Relative Files

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

A Typical File-system Organization

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Advantages of using a file system

• Organization: A file system allows files to be organized into directories and


subdirectories, making it easier to manage and locate files.
• Data protection: File systems often include features such as file and folder
permissions, backup and restore, and error detection and correction, to protect
data from loss or corruption.
• Improved performance: A well-designed file system can improve the
performance of reading and writing data by organizing it efficiently on disk.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Disadvantages of using a file system

• 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.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Try……

• Find what type of file access method is this image…

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

• Sequential file access

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Try……

• Tell me the advantages and disadvantages of Direct and sequential file access.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Advantages of Sequential Access Method :


• It is simple to implement this file access mechanism.
• It uses lexicographic order to quickly access the next entry.
• It is less prone to data corruption as the data is written sequentially and not randomly.
• It is a more efficient method for reading large files, as it only reads the required data
and does not waste time reading unnecessary data.
• It is a reliable method for backup and restore operations.
Disadvantages of Sequential Access Method :
• If the file record that needs to be accessed next is not present next to the current
record, this type of file access method is slow.
• Moving a sizable chunk of the file may be necessary to insert a new record.
• It does not allow for quick access to specific records in the file.
• It is not well-suited for applications that require frequent updates or modifications to
the file.

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Advantages of Direct Access Method :


• The files can be immediately accessed decreasing the average access time.
• In the direct access method, in order to access a block, there is no need of
traversing all the blocks present before it.

Disadvantages of Direct Access Method :

• Requires additional storage space for index.


• Cost is more
• Complexity is high

MODULE 3 -File System Interface-File Concepts and Access Methods


22CS301 - Operating Systems

Next Session…
3.2 Directory Structure and organization

MODULE 3 -File System Interface-File Concepts and Access Methods

You might also like