0% found this document useful (0 votes)
3 views9 pages

Chapter 9 - File System

Chapter 9 discusses the file system, which is essential for organizing, storing, and managing data on storage devices. It covers file concepts, access methods, directory structures, and protection mechanisms to ensure data integrity and security. The chapter emphasizes the importance of efficient data retrieval, organization, and access control in a computer system.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Chapter 9 - File System

Chapter 9 discusses the file system, which is essential for organizing, storing, and managing data on storage devices. It covers file concepts, access methods, directory structures, and protection mechanisms to ensure data integrity and security. The chapter emphasizes the importance of efficient data retrieval, organization, and access control in a computer system.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER 9: FILE SYSTEM

CONTENTS

1. Introduction
2. File Concepts
 Definition of a File
 File Attributes
 File Operations
 File Types
 File Structure
 Internal File Structure
3. File Access Methods
 Sequential Access Method
 Direct Access Method (or) Random Access Method
 Indexed Access Method
 Indexed Sequential Access Method
4. Directory Structure
 Single-Level Directory Structure
 Two-Level Directory
 Tree-Structured Directory
 Acyclic Graph Directory Structure
 General Graph Directory Structure
5. Protection
 Types of Access
 Access Control
 Other Protection Approaches

MEGHARAJ, BCA Dept.


9.1 INTRODUCTION
Meaning of File System
The File System is the most visible and important part of an Operating System. It is a method used by the
operating system to organize, store, manage, and retrieve data on storage devices such as a Hard Disk or Solid-
State Drive (SSD).
The data stored using a file system may include documents, images, audio files, videos, and programs. The file
system provides a structured way for users and applications to create, access, modify, and delete files.

Components of File System


A file system has two main components:
1) Files
Files are collections of related data treated as a single unit. They may be text files, images, programs, audio, or
video files.
Each file has attributes such as: Name, Size, Type, Permissions
2) Directories
Directories are special files that organize and store information about other files. They provide a hierarchical
structure that helps users locate, manage, and navigate files easily.

Objectives of File System


The main objective of a file system is to provide an efficient and organized way to store, manage, and retrieve
data.
1. Data Organization: Organizes data into files and directories for easy management.
2. Data Storage: Ensures efficient use of storage space and reduces fragmentation.
3. Data Access: Provides methods to read, write, and modify files.
4. Data Retrieval: Enables fast searching and locating of files.
5. Data Security: Protects data using permissions and access control.
6. Data Backup and Recovery: Supports recovery of data in case of deletion or system failure.
7. Concurrency and Sharing: Allows multiple users and programs to access files safely.
8. File Metadata Management: Maintains information such as file size, owner, and timestamps.
9. File Naming and Organization: Defines naming rules and directory structures.
10. Optimized Performance: Improves access speed using caching and efficient storage techniques.

9.2 FILE CONCEPTS

1. DEFINITION OF A FILE
A file is a named collection of related information stored on secondary storage such as:
 Hard disk, Solid-state drive, Other persistent storage devices
A file is the smallest unit of logical storage in a computer system.
Data cannot be written to secondary storage unless it is inside a file.

Characteristics of a File
 A file is a sequence of bytes or records
 Records may vary in: Length, Format
 Files can differ in: Size, Type, Structure

MEGHARAJ, BCA Dept.


2. FILE ATTRIBUTES

Attribute Description Example


Name Human-readable file identifier, unique in a directory [Link]
Identifier Unique internal number used by OS Internal ID like 12345
Type Determined by file extension .mp3 → audio file
Location Path and drive where file is stored C:\Pictures\[Link]
Size Current file size movie.mp4 → 700 MB
Protection Access permissions [Link] set to read-only
Time, Date, User ID Creation, modification, access details Created: June 1, 2023

3. FILE OPERATIONS

1. Create Operation: Create operation is used to create a new file in the file system.
Example: Saving a document as [Link] creates a new file in the selected folder.
2. Write Operation: Write operation is used to write data into an existing file.
Example: Adding “Tomorrow class at 11 AM” to [Link] writes data into the file.
3. Read Operation: Read operation is used to read data from a file into memory.
Example: Opening [Link] in a text editor reads its contents into memory.
4. Reposition (Seek) Operation: Reposition operation moves the file pointer to a specific location in a file.
Example: Fast-forwarding a video to the 30-minute mark in movie.mp4.
5. Delete Operation: Delete operation removes a file from the file system and frees its storage space.
Example: Deleting [Link] removes the file permanently.
6. Truncate Operation: Truncate operation deletes the contents of a file without removing the file itself.
Example: Clearing application_log.txt while keeping the file.
7. Close Operation: Close operation saves all changes and releases resources used by a file.
Example: Closing [Link] after editing.
8. Append Operation: Append operation adds data to the end of an existing file.
Example: Adding new log entries to [Link].
9. Rename Operation: Rename operation changes the name of a file without changing its contents.
Example: Renaming [Link] to final_version.txt.

4. FILE TYPES

 File type indicates the format or content of a file.


 Different file types require different applications.
 File Naming and Extensions
 File name and extension are separated by a dot (.)
 Extension helps identify file type
Example:
[Link] → text file
Example:
 Java compiler → .java
 MS Word → .doc, .docx

Common File Types


Category Extensions Description
Executable exe, com, bin Ready-to-run programs
Object obj, o Compiled but not linked
Source Code c, cpp, java, perl Human-readable code
MEGHARAJ, BCA Dept.
Batch bat, sh Command scripts
Markup xml, html, tex Structured documents
Word Processor doc, docx, rtf Formatted documents
Library lib, so, dll Reusable code
Print/View pdf, jpg, gif Viewable documents
Archive zip, rar, tar Compressed files
Multimedia mp3, mp4, avi Audio & video
Database sqlite, mdb, json Structured data
Configuration ini, conf, yaml System settings
Text txt, log Plain text files

5. FILE STRUCTURE

TYPES OF FILE STRUCTURES


1. Stream of Bytes
In this file structure, data is stored as a continuous sequence of bytes with no structure imposed by the operating
system.
Example: Image or binary files.
2. Record Structure
In record structure, data is organized into records, and each record may contain multiple fields.
Example: Database or spreadsheet files.
3. Line Structure
In line structure, data is stored as a sequence of text lines separated by newline characters.
Example: Source code or configuration files.
4. Executable Structure
Executable structure is a special file format that allows the operating system to load and execute programs.
Example: .exe files in Windows.

6. INTERNAL FILE STRUCTURE

Files are stored on disks in blocks, not individual bytes.


 Logical Record: Small unit viewed by application (e.g., 1 byte)
 Physical Block: Disk read/write unit (e.g., 512 bytes)

9.3 FILE ACCESS METHODS


File access methods define how data is read from and written to a file.
Choosing the correct access method improves efficiency and speed of data retrieval.
The main file access methods are:
 Sequential Access Method
 Direct (Random) Access Method
 Indexed Access Method
 Indexed Sequential Access Method

1. Sequential Access Method


In the sequential access method, records are accessed one after another in order, starting from the beginning
of the file.
Read Operation: Reads the next record and automatically moves the file pointer forward.
Write Operation: Writes data at the end of the file and moves the pointer to the new end.
Example:
Reading a file containing names and ages one record at a time until the end of the file.

MEGHARAJ, BCA Dept.


Advantages
 Simple to implement
 Suitable for processing large files in order
Disadvantages
 Slow for accessing a specific record
 Not suitable for random or interactive access

2. Direct Access Method (Random Access Method)


In the direct access method, records can be read or written directly at any location without reading previous
records.
Each record has a fixed position or block number, allowing fast access.
Read Operation: read(n) reads the record at block number n.
Write Operation: write(n) updates the record at block number n.
Example:
Accessing employee record number 123 directly using its block number.
Advantages
 Fast access to individual records
 No need to traverse earlier records
 Ideal for databases
Disadvantages
 More complex to manage
 Can cause fragmentation and wasted space

3. Indexed Access Method


In indexed access, a separate index is maintained that contains pointers to file blocks, enabling quick record
lookup.
The program first searches the index, then accesses the required block directly.
Example:
Using an index to quickly locate the block containing the 55th employee record.
Advantages
 Fast searching
 Efficient for large files
 Reduces disk I/O operations
Disadvantages
 Requires extra storage for index
 Index needs frequent updates

4. Indexed Sequential Access Method (ISAM)


ISAM combines sequential access and direct access by maintaining an index while keeping records in sorted
order.
Records can be accessed sequentially or directly using the index.
Example:
Customer records stored in order of customer ID with an index pointing to file blocks.
Advantages
 Supports both sequential and random access
 Faster searching using index
 Consistent retrieval time
Disadvantages
 Index maintenance is complex
 Wasted space due to unused block areas

MEGHARAJ, BCA Dept.


9.4 DIRECTORY STRUCTURE

A directory (also called a folder) is a container used to store files and other directories.
It helps users and applications organize, manage, and locate files easily.
A directory works like a symbol table, which converts human-readable file names into file control blocks
(addresses) understood by the computer.
Directories can be placed inside other directories, forming a hierarchical structure.

Directory Structure
Directory structure refers to the organization of directories and subdirectories in a file system.
It defines the hierarchy, relationship, and access path for files and folders.
Directory structures can be:
 Simple (single level)
 Complex (hierarchical or graph-based)

Directory Operations
The important operations in a directory structure are:
 Search for a file – Locate a specific file or group of files
 Create a file – Add a new file to the directory
 Delete a file – Remove a file from the directory
 List a directory – Display contents of a directory
 Rename a file – Change file name or location
 Traverse file system – Access all files and directories (used for backup)

Types of Directory Structures


The commonly used directory structures are:
1. Single-Level Directory
2. Two-Level Directory
3. Tree-Structured Directory
4. Acyclic Graph Directory
5. General Graph Directory

1. Single-Level Directory Structure


In a single-level directory structure, all files are stored in one directory, and each file must have a unique
name.
Example: All files like [Link], [Link], and [Link] are stored in one directory.
Advantages
 Easy to implement and understand
 Faster search when number of files is small
 File operations are simple
Disadvantages
 File name collision may occur
 Searching becomes slow if files are many
 Grouping of related files is not possible

2. Two-Level Directory Structure


A two-level directory structure has two layers:
 Master File Directory (MFD) – Contains entries for each user
 User File Directory (UFD) – Contains files of a specific user
Each user can have files with the same name, but file names must be unique within a UFD.

MEGHARAJ, BCA Dept.


Example: Each user has a separate folder, and files with the same name can exist in different user directories.
Advantages
 Solves file name collision
 Better organization by user or department
 Improves privacy and access control
Disadvantages
 Limited to only two levels
 Difficult to share files across users
 Requires full path name to access files

3. Tree-Structured Directory
A tree-structured directory is a hierarchical structure with a root directory, subdirectories, and files.
Each file has a unique path name.
Structure
 Root directory
 Subdirectories (nodes)
 Files (leaves)
Example: Files are organized in folders and subfolders like Users → Student → Documents.
Advantages
 Clear hierarchical organization
 Users can create subdirectories
 Unique path for every file
 Flexible and efficient
Disadvantages
 Complex when hierarchy becomes deep
 Deleting parent directory removes all subdirectories
 Searching can be difficult

4. Acyclic Graph Directory Structure


An acyclic graph directory allows sharing of files or directories by allowing multiple parents, but no cycles
are permitted.
This is achieved using links or shortcuts.
Example: One file is shared between two folders using links without forming a cycle.
Advantages
 Allows file sharing without duplication
 Saves storage space
 Flexible organization
Disadvantages
 Link management is complex
 Deletion of shared files is difficult
 Access control becomes complicated

5. General Graph Directory Structure


A general graph directory structure allows multiple parents and cycles within the directory structure.
It offers maximum flexibility but is hard to manage.
Example: Two folders contain links to each other, forming a cycle in the directory structure.
Advantages
 Supports complex sharing and collaboration
 Avoids file duplication
 Highly flexible

MEGHARAJ, BCA Dept.


Disadvantages
 Difficult to navigate and maintain
 Cycles can cause infinite loops
 File deletion and permission handling are complex

9.5 PROTECTION

In a computer system, protection means safeguarding data from unauthorized access, while reliability means
protecting data from accidental damage or loss.
Both are essential to maintain data integrity, confidentiality, and availability.

1. Reliability
Reliability focuses on protecting data from physical damage and accidental loss.
Methods to Ensure Reliability
 Regular backups (daily, weekly, or monthly) to recover data after failures
 Monitoring hardware issues like power failures, disk crashes, temperature, and dust
 Proper testing and maintenance of the file system to avoid software errors

2. Protection
Protection deals with preventing unauthorized or improper access to data and system resources.
Protection Mechanisms
 Physical security such as locking systems in secure locations
 Access control using permissions in multiuser systems
 Encryption to make data unreadable without a key
 Authentication and authorization using passwords, biometrics, or multi-factor authentication

TYPES OF ACCESS
Common Types of Access
1. Read Access – Allows viewing file contents without modifying them
2. Write Access – Allows modifying or adding data to a file
3. Execute Access – Allows running executable programs
4. Delete Access – Allows removing files from the system
5. Modify Access – Allows reading, writing, and changing file attributes
6. Append Access – Allows adding data only at the end of a file
7. Permission Access – Allows changing access rights for other users
8. Full (Superuser) Access – Grants complete control over system resources

ACCESS CONTROL
Access control links file access to user identity.
Different users are given different permissions using an Access Control List (ACL).
An ACL contains:
 User names
 Allowed access types
When a user requests access, the OS checks the ACL:
 If allowed → access granted
 If not allowed → protection violation

Simplified Access Control (Owner–Group–Others)


To reduce complexity, users are grouped into:
1. Owner – Creator of the file with full control
2. Group – Users with similar access needs
MEGHARAJ, BCA Dept.
3. Others (Universe) – All remaining users
This makes permission management easier and efficient.

Example: Setting Access Control in Windows


1. Right-click the file or folder
2. Select Properties
3. Open the Security tab
4. Click Edit
5. Select user or group
6. Allow or deny permissions (Read, Write, etc.)
7. Click OK to save changes

OTHER PROTECTION APPROACHES


1. File Password Protection
Each file can be protected using a password.
However, managing many passwords is difficult, and using the same password for all files is risky.

2. Encryption
Encryption converts data into an unreadable form without a key.
It provides stronger protection but requires secure key management.

3. Directory Protection in Multilevel Structures


Protection is applied at directory level to control:
 Creation and deletion of files
 Visibility of file names (existence of files)
 Access paths, where different paths may provide different access rights

MEGHARAJ, BCA Dept.

You might also like