You are on page 1of 23

22CS301 - Operating Systems

22CS301 OPERATING SYSTEM

MODULE 3 -File System Implementation: File System Structure- Directory implementation


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;

3.4 File System Implementation: File System


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 Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

3.4.File System Implementation: File System

Structure- Directory implementation

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 Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

File-System Structure
• File structure
– Logical storage unit
– Collection of related information
• The file system implementation plays a critical role in ensuring the reliability,
performance, and security of an operating system's file storage capabilities.
• Without an effective file system implementation, an operating system
cannot efficiently manage the storage of data on a storage device, resulting
in data loss, corruption, and inefficiency.
• Disk provides in-place rewrite and random access
– I/O transfers performed in blocks of sectors (usually 512 bytes)
• File control block (FCB) – storage structure consisting of information about a
file
• Device driver controls the physical device
• File system organized into layers

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

Layered File System


• I/O Control level – Device drivers act as an interface between
devices and OS, they help to transfer data between disk and main
memory. It takes block number as input and as output, it gives low-
level hardware-specific instruction.
• Basic file system – It Issues general commands to the device driver
to read and write physical blocks on disk. It manages the memory
buffers and caches. A block in the buffer can hold the contents of the
disk block and the cache stores frequently used file system metadata.
• File organization Module – It has information about files, the location
of files and their logical and physical blocks. Physical blocks do not
match with logical numbers of logical blocks numbered from 0 to N. It
also has a free space that tracks unallocated blocks.
• Logical file system – It manages metadata information about a file
i.e includes all details about a file except the actual contents of the
file. It also maintains via file control blocks. File control block (FCB)
has information about a file – owner, size, permissions, and location of
file contents.

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems
File System Layers (Cont.)
• Many file systems, sometimes many within an operating system
– Each with its own format:
– CD-ROM is ISO 9660;
– Unix has UFS, FFS;
– Windows has FAT, FAT32, NTFS as well as floppy, CD, DVD Blu-ray,
– Linux has more than 130 types, with extended file system ext3 and ext4
leading; plus distributed file systems, etc.)
– New ones still arriving – ZFS, GoogleFS, Oracle ASM, FUSE

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

File-System Implementation
• We have system calls at the API level, but how do we implement their
functions?
– On-disk and in-memory structures
• Boot control block contains info needed by system to boot OS from
that volume
– Needed if volume contains OS, usually first block of volume
• Volume control block (superblock, master file table) contains
volume details
– Total # of blocks, # of free blocks, block size, free block pointers or
array
• Directory structure organizes the files
– Names and inode numbers, master file table
22CS301 - Operating Systems

File-System Implementation (Cont.)


• Per-file File Control Block (FCB) contains many details about the
file
– inode number, permissions, size, dates
– NFTS stores into in master file table using relational DB
structures
22CS301 - Operating Systems

In-Memory File System Structures

• Mount table storing file system mounts, mount points, file system
types
• The following figure illustrates the necessary file system structures
provided by the operating systems
• Figure 12-3(a) refers to opening a file
• Figure 12-3(b) refers to reading a file
• Plus buffers hold data blocks from secondary storage
• Open returns a file handle for subsequent use
• Data from read eventually copied to specified user process
memory address
22CS301 - Operating Systems

In-Memory File System Structures


22CS301 - Operating Systems

Partitions and Mounting


• Partition can be a volume containing a file system (“cooked”) or raw –
just a sequence of blocks with no file system
• Boot block can point to boot volume or boot loader set of blocks that
contain enough code to know how to load the kernel from the file system
– Or a boot management program for multi-os booting
• Root partition contains the OS, other partitions can hold other Oses,
other file systems, or be raw
– Mounted at boot time
– Other partitions can mount automatically or manually
• At mount time, file system consistency checked
– Is all metadata correct?
• If not, fix it, try again
• If yes, add to mount table, allow access
22CS301 - Operating Systems

File-System Operations

• We have system calls at the API level, but how do we implement their
functions?
– On-disk and in-memory structures
• Boot control block contains info needed by system to boot OS from that
volume
– Needed if volume contains OS, usually first block of volume
• Volume control block (superblock, master file table) contains volume details
– Total # of blocks, # of free blocks, block size, free block pointers or
array
• Directory structure organizes the files
– Names and inode numbers, master file table

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

File Control Block (FCB)

• OS maintains FCB per file, which contains many details about


the file
– Typically, inode number, permissions, size, dates
– Example

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

Directory Implementation

• Linear list of file names with pointer to the data blocks


– Simple to program
– Time-consuming to execute
• Linear search time
• Could keep ordered alphabetically via linked list or use B+
tree
• Hash Table – linear list with hash data structure
– Decreases directory search time
– Collisions – situations where two file names hash to the same
location
– Only good if entries are fixed size, or use chained-overflow
method

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

1. Linear List

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

1. Linear List
• The implementation of directories using a singly linked list is easy to program but is
time-consuming to execute.
• Implement a directory by using a linear list of filenames with pointers to the data
blocks.
• To create a new file the entire list has to be checked such that the new directory
does not exist previously.
• The new directory then can be added to the end of the list or at the beginning of the
list.
• In order to delete a file, we first search the directory with the name of the file to be
deleted. After searching we can delete that file by releasing the space allocated to it.
• To reuse the directory entry we can mark that entry as unused or we can append it
to the list of free directories.
• To delete a file linked list is the best choice as it takes less time.
• The main disadvantage of using a linked list is that when the user needs to find a
file the user has to do a linear search.

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

2. Hash Table

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

2. Hash Table

• In the hash table for each pair in the directory key-value pair is generated.
• The hash function on the file name determines the key and this key points
to the corresponding file stored in the directory.
• This method efficiently decreases the directory search time as the entire
list will not be searched on every operation.
• Using the keys the hash table entries are checked and when the file is
found it is fetched.
• The major drawback of using the hash table is that generally, it has a fixed
size and its dependency on size. But this method is usually faster than
linear search through an entire directory using a linked list.

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

Try……
Give the purpose of following file system key components:

» Disk space allocation


» Directory structure.
» File metadata
» File operations
» File access control
» File system utilities

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

Try……
The purpose of following file system key components:
• Disk space allocation: Determines how disk space is allocated to files and
directories.
• Directory structure: Defines the organization of files and directories in a
hierarchical structure.
• File metadata: Stores information about files, such as file name, size,
creation/modification timestamps, permissions, and ownership.
• File operations: Provides functions to create, read, write, delete, and modify files.
• File access control: Manages permissions and access rights to files and
directories to ensure security and privacy.
• File system utilities: Includes tools for formatting, checking, and repairing file
systems.

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

Try……

Give some of the file system that you know…………..

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

Try……
• FAT32 (File Allocation Table 32): Commonly used in older versions of Windows
and compatible with various operating systems.
• NTFS (New Technology File System): Used in modern Windows operating
systems, offering improved performance, reliability, and security features.
• ext4 (Fourth Extended File System): Used in Linux distributions, providing
features such as journaling, large file support, and extended file attributes.
• HFS+ (Hierarchical File System Plus): Used in macOS systems prior to macOS
High Sierra, offering support for journaling and case-insensitive file names.
• APFS (Apple File System): Introduced in macOS High Sierra and the default file
system for macOS and iOS devices, featuring enhanced performance, security,
and snapshot capabilities.
• ZFS (Zettabyte File System): A high-performance file system known for its
advanced features, including data integrity, volume management, and efficient
snapshots.

MODULE 3 -File System Implementation: File System Structure- Directory implementation


22CS301 - Operating Systems

Next Session…
3.5 Allocation Methods

MODULE 3 -File System Implementation: File System Structure- Directory implementation

You might also like