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

Chapter 4 System File

Chapter 4 discusses the file system in operating systems, defining a file as a named collection of data and outlining various file structures and types. It explains file access techniques such as sequential, direct, and indexed access, along with file space allocation methods including contiguous, linked, and indexed allocation. The chapter also covers operating system security, detailing authentication methods and potential program and system threats.

Uploaded by

mahdiware
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)
15 views19 pages

Chapter 4 System File

Chapter 4 discusses the file system in operating systems, defining a file as a named collection of data and outlining various file structures and types. It explains file access techniques such as sequential, direct, and indexed access, along with file space allocation methods including contiguous, linked, and indexed allocation. The chapter also covers operating system security, detailing authentication methods and potential program and system threats.

Uploaded by

mahdiware
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
You are on page 1/ 19

CHAPTER 4 Operating System - File System

1. What is a File?
• A file is a named collection of related data stored on
secondary storage (e.g., disk, tape, or optical storage).
• A file can be a sequence of bits, bytes, lines, or records.
• Its meaning depends on how it is created and used.
2. File Structure
• A file must have a structure the operating system (OS) understands.
• Different types of file structures include:
• Text File: Contains characters organized into lines.
• Source File: Contains programming instructions.
• Object File: Contains machine-readable code.
• Some OSs like MS-DOS and UNIX support only a few file structures.
3. Types of Files
Operating systems classify files into different types:
(a) Ordinary Files
• Contain user data such as text, databases, or executable programs.
• Users can perform operations like add, modify, delete, and remove.
(b) Directory Files
• Contain lists of filenames and related information.
• Help in organizing files into folders.
(c) Special Files (Device Files)
• Represent physical devices like disks, terminals, printers, and networks.
• Two types:
• Character Special Files: Handle data character by character (e.g., keyboards,
printers).
• Block Special Files: Handle data in blocks (e.g., disks, tapes).
4. File Access Techniques
File access techniques determine how data is retrieved from a file. The three main
techniques are:
(a) Sequential Access
• Data is read in order, one record after another.
• Used in compilers and log files.
Example of Sequential Access
Scenario 1: Reading a Log File
A web server stores log files that record every visitor's activity. The system reads
this file line by line, from start to end.
Example:
[10:00] User A logged in
[10:05] User B visited the homepage
[10:10] User A logged out
he log file is read sequentially, meaning records must be accessed one after
another.
Scenario 2: Processing a Payroll System
A company has an employee payroll file stored in sequential order. When
processing salaries, the system reads each employee's record one by one.
Example File Content (Stored Sequentially)
1001, John, $5000
1002, Mary, $4500
1003, Ahmed, $5500
• The system reads the first record, processes it, then moves to the next.
• If you want to find Ahmed’s salary, you must read John’s and Mary’s
records first.
Key Points:
✅ Easy to implement
✅ Good for simple data processing
❌ Slow for searching specific records (you must read all previous records)
(b) Direct (Random) Access
• Each record has a unique address, allowing immediate access.
• Suitable for databases where records are accessed individually.
Example of Direct (Random) Access
Scenario 1: Accessing a Student Record in a Database
A university stores student records in a database. Each student has a unique
student ID. If a professor wants to retrieve a specific student's record, the system
directly accesses that record using its ID without scanning other records.
Example Table:

If the system needs Ahmed’s record (ID: 1003), it jumps directly to it instead of
reading John’s and Mary’s records first.
Scenario 2: Retrieving an Item from a Hard Disk
A hard disk drive (HDD) or solid-state drive (SSD) allows direct access to data
blocks.
• If a file is stored at block #500, the OS can directly retrieve it without reading
blocks 1-499.
• This is why SSDs are much faster than sequential storage devices like magnetic
tapes.
Scenario 3: ATM Transactions
• When you insert an ATM card, the system retrieves your account details
immediately, not by searching through all customers.
• This is possible because each account is stored with a unique account number.
Key Points:
✅ Fast and efficient for large databases
✅ Allows quick searching and updating
❌ More complex to implement
(c) Indexed Sequential Access
• A combination of sequential and direct access.
• An index is created, allowing direct access through pointers.
• Used in large databases.
Example of Indexed Sequential Access
Indexed Sequential Access combines sequential and direct access by using an index that helps in locating records
quickly. This method is commonly used in large databases where records need to be accessed efficiently.
Scenario 1: Library Book Catalog
A university library has thousands of books stored in a database.
Instead of searching through all records sequentially, an index is created.
The system first searches the index, which contains pointers to the actual book records.
Example Index Table (Sorted by Book ID)

• If we want to find Book ID 1005, we first check the index.


• The index points to Location B, where the full record is stored.
• This is faster than scanning all books sequentially.
Scenario 2: Employee Payroll System
A company has 10,000 employee records stored sequentially.
• Instead of scanning every record, the system first checks the index, which
contains key employee IDs.
• The index helps in jumping directly to the correct section of the file.
Example Index (Sorted by Employee ID)

• If we search for Employee 2005, we check the index first.


• The index directs us to Block 12, where we can fetch the full employee
details.
Scenario 3: Airline Ticket Booking System
Airlines store millions of passenger records.
Instead of searching for a passenger's booking sequentially, the system uses an
index of ticket numbers.
The index points to the actual data storage, making searches and updates faster.

Key Points:

✅ Faster than sequential access


✅ Less storage overhead than full direct access
✅ Good for large databases with sorted records
❌ Slower than direct access for individual record retrieval
❌ Indexing requires additional storage
5. File Space Allocation Methods
The OS manages how files are stored on disk using three main allocation
techniques:
(a) Contiguous Allocation
• Each file is in a permanent storage location.
• Advantages:
• Simple and efficient for reading performance.
• Supports random access.
• Disadvantages:
• Causes external fragmentation (wasted space).
• Hard to extend file size.

Example of Contiguous Allocation


Contiguous allocation means that each file is stored in a single continuous block on
the disk. This makes reading fast but can cause wasted space when files are
deleted or resized.
Scenario 1: Video File Storage on a Hard Disk
A 4GB video file is saved on a hard disk in one continuous block.
• When the video is played, the system can quickly read all data without searching.
• This makes playback smooth, as the file is stored in one location.
However, if a new 5GB video is saved, but only 2GB of free space is available next to the old video, the system
cannot store the file continuously. This leads to fragmentation.

Scenario 2: CD/DVD Storage


When burning a CD or DVD, files are stored contiguously.
If a movie is split into different locations, it can cause playback issues.
That's why CDs/DVDs do not allow files to be randomly placed like a hard drive.

Scenario 3: Storing a Large Software Program


A 500MB software program is installed on a system.
If the OS uses contiguous allocation, the program is stored in a single block for faster access.
However, if updates increase the size, the OS might not find enough space to extend the file.

Key Points:
✅ Simple and fast read performance (no extra searching needed).
✅ Supports random access (directly jump to any part of the file).
❌ External fragmentation (unused spaces between files).
❌ File resizing is difficult (if no continuous space is available).
(b) Linked Allocation
• Each file is stored as interconnected blocks scattered across the disk.
• Each block contains a pointer to the next block.
• Advantages:
• No external fragmentation.
• Allows file growth.
• Disadvantages:
• Slow for direct access.
• A broken pointer can corrupt the file.

Example of Linked Allocation


Scenario: Storing a Large Document in a Hard Drive
Imagine you are saving a 10-page Word document on your computer. Instead of storing it in one
continuous block (like in contiguous allocation), the OS saves each page separately in different
locations on the disk.
Each page (block) contains a pointer to the next page's location.
How It Works (Linked Allocation Example)
Let’s say your document is stored in three blocks (scattered across the disk):

• he first block (5) contains Page 1 and a pointer to the next block (12).
• Block 12 contains Page 2 and a pointer to the next block (8).
• Block 8 contains Page 3 and marks the end of the file.
When you open the document, the OS follows the pointers to read each page in order.
Advantages of Linked Allocation:
✅ No External Fragmentation – Any available block can be used.
✅ File Can Grow Easily – Just add a new block and update the pointer.
Disadvantages of Linked Allocation:
❌ Slow for Direct Access – To read Page 3, you must start from Page 1 and follow the pointers.
❌ Pointer Corruption – If the pointer in Block 12 is lost or damaged, the rest of the file is
unreadable.
(c) Indexed Allocation
• Uses an index block to store pointers to file blocks.
• Advantages:
• Supports direct access.
• A bad data block affects only that block.
• Disadvantages:
• Overhead of index blocks.
• A corrupted index block loses the entire file.
Example of Indexed Allocation
Scenario: Storing a Book in a Computer
Imagine you are saving a digital book (PDF file) on your computer. Instead of storing the file in
one continuous block (contiguous allocation) or using pointers inside each block (linked
allocation), the OS creates a separate index block that keeps track of where each part of the file
is stored.
How It Works (Indexed Allocation Example)
📖 Book File: "Computer Science.pdf"
The OS creates an index block for this file.
The index block stores all the locations of the book’s pages (data blocks).

• When you open the book, the OS looks at the index block first and then jumps to the correct data
block.
• If you want Page 3, the OS directly jumps to Block 42, without scanning other pages.
Advantages of Indexed Allocation:
✅ Supports Direct Access – You can jump directly to any part of the file.
✅ A Bad Data Block Affects Only That Block – If Block 42 is corrupted, only Page
3 is lost.
Disadvantages of Indexed Allocation:
❌ Extra Overhead – The index block takes up additional space.
❌ A Corrupted Index Block Loses the Entire File – If the index block is damaged,
the OS cannot find any pages of the book.
Real-Life Example of Indexed Allocation:
📁 File Allocation Table (FAT) – Used in older Windows file systems.
📀 DVDs & Blu-ray Discs – Use index tables to locate files instantly.
📚 Table of Contents in Books – Similar to how an index block works.
6. Operating System Security
Security in operating systems protects system resources from unauthorized access
and threats.
(a) Authentication Methods
• Username & Password: Traditional method.
• User Card/Key: Uses a physical card or key generator.
• Biometric Authentication: Uses fingerprints, retina scans, etc.
(b) One-Time Passwords (OTP)
• A new password is generated every time the user logs in.
• Types:
• Random Numbers (printed cards with numbers).
• Secret Key (generated by a hardware device).
• Network Password (sent via email/SMS).
(c) Program Threats
Malicious programs can harm the system:
• Trojan Horse: Fake programs that steal credentials.
• Trap Door: A hidden vulnerability in software.
• Logic Bomb: Activates when certain conditions are met.
• Virus: Spreads by modifying files, causing system damage.
(d) System Threats
Threats that affect system resources and networks:
• Worms: Replicate themselves and slow down systems.
• Port Scanning: Used by hackers to find weaknesses.
• Denial of Service (DoS): Overloads a system to prevent legitimate
use.
######################END##########################

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy