0% found this document useful (0 votes)
11 views19 pages

OS Unit-5

A file system is a software component of an operating system that manages how data is stored and retrieved on storage devices, allowing users to handle files efficiently. It includes various access methods (sequential, direct, indexed sequential), directory structures (single-level, two-level, tree, acyclic graph), and file protection mechanisms. Additionally, file system implementation involves on-disk and in-memory structures to facilitate file operations and ensure data integrity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views19 pages

OS Unit-5

A file system is a software component of an operating system that manages how data is stored and retrieved on storage devices, allowing users to handle files efficiently. It includes various access methods (sequential, direct, indexed sequential), directory structures (single-level, two-level, tree, acyclic graph), and file protection mechanisms. Additionally, file system implementation involves on-disk and in-memory structures to facilitate file operations and ensure data integrity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

UNIT-5

Q. What is file system in operating system?


Link: https://www.youtube.com/watch?v=0LtuQhNFFe0
File System in Operating System

What is a File System?


 A file system is a software component of the operating system (OS).
 It is responsible for managing how data is stored and retrieved on a storage device.
 Just like DBMS manages databases, the file system manages user data in the form of
files.

Why Do We Need a File System?


 Users manage data in the form of files (e.g., DOC, MP3, PDF).
 Data needs to be stored permanently (on hard disks, SSDs) – not in RAM (volatile).
 The file system handles:
o Storage: Where and how to save the data.
o Retrieval: How to access or fetch that data later.

File Systems in Different OS


Operating System File System Used

Windows NTFS (previously FAT)

DOS FAT (File Allocation Table)

UNIX UNIX File System (UFS)

Linux EXT (Extended File System)

Big Data Systems ZFS (Zettabyte File System)

How Data is Stored Internally


User Perspective:
 Files are stored in folders (Windows) or directories (Linux/UNIX).
 Files include documents, images, videos, etc.

File System Perspective:


 Disk consists of:
o Platters → Surfaces → Tracks → Sectors
 File System stores data on sectors of the disk.
Process:
1. User creates/downloads a file (e.g., 1 GB movie).
2. File System:
o Divides the file into logical blocks.
o Maps these blocks to physical sectors on the disk.
3. Mapping may or may not be contiguous.
o Example: If sectors are already used, data is stored in non-contiguous sectors.
4. This mapping is saved by the file system for future data retrieval.

Simple Analogy: Rooms and Students


 Think of sectors as rooms, and file blocks as students.
 File System assigns students to available rooms – not necessarily next to each other.
 During retrieval, it recalls which student (block) was sent to which room (sector).

Key Responsibilities of File System


 Manage file storage and retrieval
 Keep track of file attributes (name, size, creation date, etc.)
 Support file operations:
o Create
o Read
o Write
o Delete
o Truncate
o Rename
Q. Explain about file access methods?
Link: https://www.youtube.com/watch?v=UgS6gSkTJjM
File Accessing Methods – Operating System

What are File Accessing Methods?


 File Accessing refers to reading from or writing into a file (i.e., file manipulation).
 It determines how data in a file is accessed on secondary storage.
 There are three primary methods of file access:

Sequential Access
🔹 Description:
 Data is accessed in order, one piece after another.
 Reading and writing happen in the same sequence as the data was stored.
 Commands:
o Read Next
o Write Next (data is always appended at the end)
🔹 Example:
 Compiler Execution: Code is executed line-by-line in the order written.
 Tape drives (legacy systems) follow this access pattern.
Advantages:
 Simple to implement
Disadvantages:
 Slow for accessing data located far from the beginning.
 Requires traversal through all preceding data to reach the target.

Direct Access (Random Access)


🔹 Description:
 Data is accessed directly by specifying block or location.
 No need to follow a sequence.
 Ideal when data retrieval order is unpredictable.
🔹 Example:
 Databases, Media players, and Hard disks typically use direct access.
Advantages:
 Fast access to any part of the file.
 Less traversal needed.
Disadvantages:
 More complex to implement compared to sequential access.

Indexed Sequential Access


🔹 Description:
 Hybrid of sequential and direct access.
 Maintains an index for data blocks (like a book index).
 First accesses the index, then jumps directly to the required block.
🔹 Example:
 Similar to Table of Contents in books:
o Index tells you which page (block) to go to.

Q. Explain about directory structure?


Link: https://www.youtube.com/watch?v=BW_ff_mTa40
Directory Structure in Operating Systems

What is a Directory?
 A directory is a container that holds files and sometimes other directories.
 File = Collection of related data
 Directory = Collection of related files
Efficient file access and organization require a well-defined directory structure.

Types of Directory Structures


There are 4 main types:
No. Structure Name Description

1️⃣ Single-level Directory One root directory, all files stored in the same place
No. Structure Name Description

2️⃣ Two-level Directory Separate directory for each user

3️⃣ Tree (Hierarchical) Directory can contain subdirectories

4️⃣ Acyclic Graph Directory Allows shared subdirectories/files across users

1️⃣ Single-level Directory


Structure:
 Only one directory for all users.
 All files stored together.
[ Directory ]
├── file1
├── file2
└── file3
Advantages:
 Easy to implement
 Simple searching (small size)
Disadvantages:
 Naming collisions (no duplicate file names)
 Poor scalability: Searching becomes inefficient with many files

2️⃣ Two-level Directory


Structure:
 A root (master) directory
 Each user gets their own directory
[ Root ]
├── User1
│ ├── file1
│ └── file2
├── User2
│ ├── file1
│ └── file2
Advantages:
 No naming collisions (same file names allowed under different users)
 Better organization by user
Disadvantages:
 No subdirectories inside user directories
 Grouping files (e.g. by project/type) is not possible

3️⃣ Tree (Hierarchical) Structure


Structure:
 Users can create subdirectories inside their directory
 Resembles actual file system used in Windows, Linux, etc.
[ Root ]
├── User1
│ ├── file1
│ └── Subdir1
│ └── fileA
├── User2
├── file2
└── Subdir2
└── fileB
Advantages:
 Grouping of files is possible
 Flexible and scalable
 Reflects modern OS file systems (like Windows Explorer)
Disadvantages:
 Files cannot be shared across user directories

Acyclic Graph Directory


Structure:
 Like a tree structure but allows file sharing across users
 A file or subdirectory can appear in multiple locations
[ Root ]
├── User1
│ ├── file1
│ └── SharedDir → [ points to User2's Subdir ]
├── User2
└── Subdir
└── fileX
Advantages:
 Files and directories can be shared among users
 Efficient use of memory and storage
Disadvantages:
 Complex to implement
 Requires mechanisms to avoid cycles and manage reference counts (for deletion)
Q. Explain about file system mounting in operating system?
Link: https://www.youtube.com/watch?v=4bjVoWUP0uQ
File Mounting & Sharing in Operating Systems

Part 1: File Mounting


🔹 What is Mounting?
 Mounting is the process of making a file system accessible to the operating system.
 Just like a file must be opened before it’s used, a file system must be mounted before
access.
 It is done by attaching a file system to a directory — called the mount point.
Key Concepts:
 Mount Point: An empty directory in the existing file system where the new file system
is attached.
 Once mounted, files in the new file system become accessible through the mount
point.
Example:
Before Mounting:
[ Computer System ]
└── /users
Mounting:
[ Mounted Volume ] = User: Jane with files
After Mounting:
[ Computer System ]
└── /users
└── Jane
├── file1
└── file2
Q. Explain about file sharing in operating system?
Link: https://www.youtube.com/watch?v=4bjVoWUP0uQ
File Sharing
Why Share Files?
 In multi-user systems, multiple users may want to access the same file.
 File sharing allows collaboration and efficient use of storage.

File Ownership & Permissions


Modern OS uses User and Group-based access control.
Component Description

Owner (User ID) The user who owns the file and sets access permissions

Group (Group ID) A set of users who are granted access by the owner

Permissions Define who can read, write, or execute the file


 Owner and group IDs are stored with file metadata.
 System checks user/group ID during access to match permissions.

File Sharing Methods


1️⃣ FTP (File Transfer Protocol)
 A client-server model.
 Client requests file; Server fulfills the request.
 Used for transferring files across networks.

2️⃣ DFS (Distributed File System)


 Files are stored across multiple computers in a network.
 A computer (client) requests a file → the network locates it.
 DNS (Domain Name System) helps find which machine has the file.
How It Works:
1. Client requests a file.
2. DNS finds which system has the file.
3. Remote system sends the file to the client.

3️⃣ World Wide Web (WWW)


 Web browsers request files (HTML, PDFs, images) over the Internet.
 HTTP/HTTPS protocols are used to fetch and display files.

File Sharing Failures


🔧 Local File Failures:
 Disk corruption
 OS crashes
Remote File Failures:
 Network failure
 Server crashes
 Poor hardware configuration

Q. Explain about file protection in operating system?


Link: https://www.youtube.com/watch?v=yzWQ3_5ttmE
File Protection in Unix/Linux
1. Types of File Operations
Users can perform different operations on files:
 Read (r) → View contents of a file / list directory contents
 Write (w) → Modify or delete contents
 Execute (x) → Run the file (if it’s a program/script) or enter a directory
 Append (a) → Add data at the end of the file
 Delete (d) → Remove the file
 List (l) → Display directory entries

2. User Classes
Unix/Linux classifies users into three categories:
1. Owner (User) → The creator of the file (has full control by default).
2. Group → Other users in the same group as the file owner.
3. Others → All remaining users in the system.

3. Permission Representation
 Read = 4, Write = 2, Execute = 1
 Permissions are added together for each user class.
Example:
 rwx = 4+2+1 = 7
 rw- = 4+2 = 6
 r-- = 4 = 4
So a common permission set is 761:
 Owner → 7 (rwx)
 Group → 6 (rw-)
 Others → 1 (--x)

4. Commands for File Protection


 chmod → Change permissions (mode) of a file
 chmod 761 file.txt
 chown → Change ownership of a file
 chown user1 file.txt
 chgrp → Change the group ownership
 chgrp developers file.txt
 umask → Set default permissions for newly created files

5. Directory Listing (ls -l)


Example:
-rw-rw-r-- 1 user group 512 Sep 25 10:00 file.txt
drwx------ 2 user group 4096 Sep 25 10:05 mydir
 First character → - for file, d for directory, l for link
 Next 9 characters → Permissions for owner, group, others
 Links, owner, group, size, date, filename follow

6. Why Protection is Needed


Without protection:
 Anyone could read, modify, or delete sensitive data.
With protection:
 Access is restricted, ensuring confidentiality, integrity, and security.
Q. Explain about file system implementation in operating systems?
Link: https://www.youtube.com/watch?v=t8Rs9AbqHUc
File System Implementation in OS
A file system is implemented using two kinds of data structures:
1. On-Disk Structures (stored in secondary storage like HDD/SSD)
These structures persist on disk even after shutdown.
 Boot Control Block (Boot Block)
o Located in the first block of a partition.
o Contains info needed to boot the OS.
o Each partition may have its own boot block.
 Volume Control Block (Superblock / Partition Control Block)
o Stores details about the volume/partition:
 Total number of blocks
 Block size
 Number of free blocks/inodes
 Volume name, etc.
 Directory Structure
o Organizes files within directories.
o Provides mapping from file names → corresponding File Control Block
(FCB).
 File Control Block (FCB / inode in Unix)
o Contains metadata about a file:
 File name, size, type
 Owner, group, permissions (ACLs)
 Timestamps (created, modified, last accessed)
 File location (pointers to data blocks)

2. In-Memory Structures (stored in RAM, kernel memory)


These exist only while the system is running to speed up file operations.
 Mount Table
o Holds info about all mounted file systems (mount points, device location,
etc.).
 In-Memory Directory Cache
o Caches recently accessed directories for faster lookup.
o Avoids repeatedly scanning the entire disk directory structure.
 System-Wide Open File Table
o Stores entries for all open files in the system.
o Each entry contains a pointer to the file’s FCB (in-memory copy).
 Per-Process Open File Table
o Each process has its own table.
o Contains references (file descriptors) pointing to entries in the system-wide
open file table.

3. How File Operations Work


(a) Open System Call
1. User calls open("filename").
2. OS checks directory structure (on-disk or cached in memory).
3. Retrieves the file’s FCB from disk.
4. Loads FCB info into system-wide open file table.
5. Creates an entry in the per-process open file table, pointing to the system-wide entry.
6. Returns a file descriptor (FD) (integer identifier) to the process.
(b) Read System Call
1. Process calls read(fd, buffer, size).
2. Using the FD, OS looks up the per-process open file table.
3. That entry points to the correct system-wide open file table entry.
4. From there, OS gets the FCB and identifies the file’s data block addresses.
5. Reads the corresponding blocks from secondary storage into memory buffer.
6. Returns data to the process.

4. Why Two Levels of Tables?


 System-wide table avoids duplicating FCBs when multiple processes open the same
file.
 Per-process table allows each process to have its own access mode (e.g., one process
read-only, another read-write).
Q. What is file system structure in operating system?
Link: https://www.youtube.com/watch?v=Otm2vQKCdz0

File System Structure and Functionality (Layered Approach)

The file system uses a **layered architecture** that enables efficient data storage and
retrieval on a hard disk.
Each layer performs a specific task, and its output becomes the input for the next layer.
Layers of the File System
1. Application Program
- Represents **user-written files and requests**.
- Initiates file operations to be processed by the OS.
2. Logical File System
- **Verifies** the file’s presence in the directory structure.
- Manages **file metadata** (name, type, permissions, size).
- Determines the **logical block number** (which part of the file is accessed).
3. File Organization Module
- Converts **logical block numbers → physical block numbers** on disk.
- Uses:
- **Directory structures** → locating files.
- **Free space management** → efficient allocation.
- Ensures correct mapping of file data to storage blocks.
4. Basic File System
- Accepts **physical block information** from the File Organization Module.
- Issues **low-level read/write commands** to I/O Control.
5. I/O Control
- Manages **hardware interaction** through device drivers.
- Device drivers handle:
- **Disk read/write operations**.
- **Peripheral communication** (e.g., printing).
- **Interrupt handling**.
Application Layer

Logical File System

File Organization Module

Basic File System

I/O Control

Devices (Disk/SSD)

Q. Explain about file allocation methods?


Link: https://www.youtube.com/watch?v=gK6L3v1b8AM
File Allocation Methods in Operating Systems

File allocation methods define **how disk space is assigned to files**.


The three primary methods are **Contiguous, Linked, and Indexed allocation**.
1. Contiguous Allocation
- Stores file blocks in **adjacent disk locations**.
- **Advantages:**
- Fast **sequential and direct access**.
- **Disadvantages:**
- Causes **external fragmentation**.
- Difficult to grow files dynamically.
2. Linked Allocation
- Each file block contains a **pointer** to the next block.
- Blocks can be scattered anywhere on disk.
- **Advantages:**
- No external fragmentation.
- Easy file growth.
- **Disadvantages:**
- **Sequential access only** (slow random access).
- Extra space needed for pointers.
- Reliability issues if a pointer is lost/damaged.
3. Indexed Allocation
- Maintains an **index block** containing addresses of all file blocks.
- **Advantages:**
- Supports **sequential and random access**.
- Eliminates external fragmentation.
- **Disadvantages:**
- Index block must be stored (extra overhead).
- For very large files, multiple index blocks may be required.
**File Allocation Methods:** Contiguous, Linked, Indexed.
- **Contiguous:** Fast, but suffers from fragmentation.
- **Linked:** Flexible, but only sequential access.
- **Indexed:** Supports both sequential + random access, minimizes fragmentation.
Contiguous → [Block1][Block2][Block3][Block4] (all adjacent)
Linked → [Block1] → [Block7] → [Block3] → [Block9] (pointers connect scattered blocks)
Indexed → [IndexBlock] → {Block5, Block12, Block18, Block20} (all addresses stored in
index)

Q. Explain about free space management?


Link: https://www.youtube.com/watch?v=hDBFSQRHPAU
Free Space Management

A file system is responsible to allocate the free blocks to the file therefore it has to keep track
of all the free blocks present in the disk. There are mainly two approaches by using which,
the free blocks in the disk are managed.
1. Bit Vector

In this approach, the free space list is implemented as a bit map vector. It contains the number
of bits where each bit represents each block.

If the block is empty then the bit is 1 otherwise it is 0. Initially all the blocks are empty
therefore each bit in the bit map vector contains 1.
LAs the space allocation proceeds, the file system starts allocating blocks to the files and
setting the respective bit to 0.
2. Linked List

It is another approach for free space management. This approach suggests linking together all
the free blocks and keeping a pointer in the cache which points to the first free block.

Therefore, all the free blocks on the disks will be linked together with a pointer. Whenever a
block gets allocated, its previous free block will be linked to its next free block.

Q. Explain about overview of mass storage structure?


Link: https://www.youtube.com/watch?v=Z0LPIEcGMXo
Mass Storage Structures
Mass storage structures include **magnetic disks** and **magnetic tapes**, both of which
are **secondary storage devices**.
They are **non-volatile**, meaning data is retained even when the system is powered off.
1. Magnetic Disks (Hard Disks)
- Store **large amounts of data permanently**.
- Provide **random access** to data.
- Constructed with **multiple platters** stacked like CDs.
- Each platter has:
- **Tracks** → concentric circles for storing data.
- **Sectors** → smallest storage units.
- **Read/Write Head**: Accesses sectors for reading/writing.
Performance Parameters
- **Transfer Rate**: Speed of moving data from disk to computer.
- **Seek Time**: Time taken for the head to locate the correct track.
- **Rotational Latency**: Time waiting for the sector to rotate into position.
2. Magnetic Tapes
- Also **non-volatile** but slower than disks.
- Provide **sequential access** (data must be read in order).
- Storage capacity: **20 GB – 200 GB** (smaller than disks).
- Transfer rate is **comparable** to disks, but retrieval is slower.
- Still used for **backups and archival storage**.
3. Primary vs Secondary Memory
- **Primary Memory (RAM)**: Directly accessed by CPU, volatile.
- **Secondary Storage (Disks/Tapes)**: Indirectly accessed, non-volatile.
- Crucial for understanding **computer architecture** and **data management**.

Q. Explain about disk scheduling in operating system?


Link: https://www.youtube.com/watch?v=Ft5o11WJ2Bc
SCAN Disk Scheduling Algorithm
The **SCAN scheduling algorithm** (also known as the **Elevator Algorithm**) moves the
read/write head across the disk cylinders in one direction, servicing all requests along the way
until it reaches an end.
Then, the head reverses its direction and continues servicing pending requests, ensuring
efficient disk access.
Working of SCAN
1. The head moves in one chosen direction (towards one end of the disk).
2. All requests in its path are serviced sequentially.
3. Once the head reaches the end, it reverses direction.
4. Requests in the opposite direction are then serviced.
5. This continues until all requests are completed.
Example
- Disk size: **200 cylinders (0–199)**.
- Head starts at **cylinder 53**.
- Direction: initially moves left (towards 0).
- Requests are served along the path (e.g., 37, 14).
- At the end (0), the head reverses and services remaining requests (e.g., 65, 67, 98, etc.).
## Head Movement Calculation
- **Total head movement = sum of absolute differences between serviced cylinders**.
- Only **positive values** are considered for movement (no negatives).
- This avoids errors and ensures accurate performance measurement.
Q. Explain about device drivers in operating system?
Link: https://www.youtube.com/watch?v=qTMzIF2Qnlk
Device Drivers
A **device driver** is system software that enables **hardware devices** (like printers,
scanners, cameras, sound cards) to communicate with a computer system.
It acts as a bridge between the **operating system, applications, and hardware**.
Functions of a Device Driver
- **Initialize devices** when connected or powered on.
- **Manage power requirements** to optimize performance and energy use.
- **Validate input parameters** to ensure proper operation.
- **Control device operations**, handling commands from applications and the OS.
## Examples of Device Drivers
- Printers
- Scanners
- Cameras
- Sound cards
These drivers ensure that the devices function correctly and interact seamlessly with software
applications.
- Device drivers enable communication between hardware and the computer system.
- Ensure **applications and OS** can send commands to hardware seamlessly.
- Key functions: **initialization, power management, input validation, device control**.
- Examples: **printers, scanners, cameras, sound cards**.

You might also like