Operating System Unit - 5
Operating System Unit - 5
such as a hard drive, solid-state drive (SSD), or external media. Files are used to organize and
store data in a structured format, making it easy to retrieve, modify, or manipulate the
information as needed.
Key Characteristics of a File:
1. Name: A file has a unique name within its directory that is used to identify and access it.
2. Data: A file contains data in different formats (text, binary, multimedia, etc.).
3. Storage Location: Files are stored in a specific location within a storage medium (hard
drive, cloud storage, etc.), often organized in directories or folders.
4. Extension: Files typically have extensions (e.g., .txt, .jpg, .mp4) to indicate the file type
and how it should be handled or interpreted by software.
5. Size: The amount of data a file holds, measured in bytes (kilobytes, megabytes,
gigabytes, etc.).
6. Permissions: Files may have access permissions that control who can read, modify, or
execute the file.
File Structure:
Files are typically structured in a hierarchical system using directories (folders). For example:
/home/user/Documents/file.txt
In this path, file.txt is the file, and /home/user/Documents/ is the directory where it's located.
In an operating system (OS), files are classified into different types based on their content,
format, and intended use. Each file type serves a specific purpose and may be associated with
certain programs or system functionalities. The file type is often indicated by the file extension
(the suffix after the dot in the file name, such as .txt, .exe, .jpg).
Here are the common file types in an operating system:
1. Regular Files (or Ordinary Files)
These files contain user or system data. They can be either text or binary files.
Text Files: Contain readable characters in human languages (e.g., .txt, .csv). They store
plain text or structured data (e.g., .xml, .json).
Binary Files: Contain data in binary form (0s and 1s) that is not human-readable. This
can include compiled programs (e.g., .exe, .bin) or any other binary-encoded data.
2. Directory Files
A directory (also called a folder) is a special type of file that stores references (pointers) to other
files or directories. It organizes the file system in a hierarchical structure, allowing for efficient
storage and retrieval of files.
Example:
/home/user/Documents/ is a directory that contains files and possibly other directories.
3. Executable Files
Executable files contain machine code that can be executed directly by the operating system.
These files are used to launch applications or scripts.
Windows: .exe, .bat, .com
Linux/Unix: Files without extensions (but marked as executable), shell scripts (.sh)
4. Device Files (or Special Files)
Device files are interfaces to hardware devices (e.g., printers, disk drives) in Unix/Linux-like
operating systems. They allow applications and users to interact with hardware as if they were
files.
There are two main types:
Character Device Files: Handle data one character at a time (e.g., keyboards, serial
ports).
Block Device Files: Handle data in large blocks (e.g., hard drives, USB drives).
Examples:
/dev/sda (for a hard disk in Linux)
/dev/tty0 (for a terminal)
5. Pipe Files (or Named Pipes)
Pipes are used for inter-process communication (IPC), allowing data to be passed between
processes. Pipes appear as files, but they serve as a communication channel rather than storing
data persistently.
Example:
A named pipe in Unix/Linux might be created with the command mkfifo.
6. Socket Files
Socket files are used for network communication between processes, both local and remote.
They allow for data exchange over network protocols like TCP or UDP.
Example:
/var/run/docker.sock is a socket used for Docker communication on Unix-based systems.
7. Symbolic Links (Symlinks)
A symbolic link is a special file that points to another file or directory. It acts as a shortcut or
reference to the target file, without duplicating its content. Changes made to the target file are
reflected when accessing the symbolic link.
Example:
A symbolic link might look like link_to_file -> /path/to/original_file.
8. Archive Files
Archive files are used to bundle multiple files into a single file, often for backup or transfer.
They may also be compressed to save storage space.
Examples:
.zip, .tar, .rar, .gz
9. Multimedia Files
These are files that store media content such as audio, video, and images.
Examples:
Image files: .jpg, .png, .gif, .bmp
Audio files: .mp3, .wav, .aac
Video files: .mp4, .avi, .mkv
10. System Files
System files are critical for the operation of the OS. These files include configuration files,
libraries, drivers, and system executables.
Examples:
Configuration files: .conf, .ini, .sys (in Windows)
Library files: .dll (in Windows), .so (in Linux)
System executables: Kernel files (vmlinuz in Linux), boot files (bootmgr in Windows)
11. Temporary Files
Temporary files are created by applications or the OS to hold intermediate data. These are
typically deleted once they are no longer needed.
Examples:
Windows: Files with .tmp extension
Linux/Unix: Stored in /tmp directory
12. Log Files
Log files contain records of system or application events. They are useful for troubleshooting
and monitoring system activity.
Examples:
.log files, typically found in /var/log/ in Linux or C:\Windows\Logs\ in Windows.
A file system is a method used by an operating system (OS) to organize, store, retrieve, and
manage data on storage devices, such as hard drives, SSDs, or removable media. It defines how
data is stored, how files are named, how they are organized in directories, and how the operating
system keeps track of which blocks of storage belong to which files.
In simpler terms, a file system provides a structured way to store and access data so that users
and applications can read, write, and manage files efficiently.
Key Functions of a File System:
1. File Organization: Determines how files are arranged on the disk, including the
hierarchical structure of directories and subdirectories.
2. Storage Allocation: Manages how disk space is allocated to files, ensuring efficient use
of storage.
3. File Naming: Controls how files are named, including support for extensions, case
sensitivity, and allowed characters.
4. File Access: Provides a way to read, write, and modify files, while enforcing permissions
and access control.
5. Metadata: Keeps track of file attributes such as file size, creation date, modification date,
owner, and permissions.
6. Data Integrity: Ensures that the file system maintains the accuracy and consistency of
stored data, even in the event of a crash or hardware failure.
Types of File Systems:
Different operating systems use different file systems, each with its own advantages,
disadvantages, and special features. Here are some of the most common types of file systems:
9. XFS
Developed by: Silicon Graphics
Used in: Linux, especially in large-scale servers and data centers
Key Features:
High performance: XFS is designed for scalability and high-performance workloads,
making it ideal for large servers.
Journaling: Ensures data integrity and quick recovery after crashes.
Support for large files: XFS supports files and volumes up to 8 EB in size.
Limitations:
Less flexible resizing: XFS is not as easy to shrink once it’s allocated, compared to file
systems like ext4 or Btrfs.
Summary Table:
File Used In Key Features Limitations
System
FAT32 USB drives, old Simple, widely compatible 4 GB file size limit, no
Windows journaling
NTFS Windows Large files, security Limited compatibility with non-
features, journaling Windows OS
ext4 Linux Journaling, supports large Limited support on non-Linux
files OS
HFS+ Older macOS Journaling, optimized for Replaced by APFS
systems macOS
APFS Modern macOS, Designed for SSDs, fast, Limited compatibility with
iOS snapshots older systems
exFAT Flash drives, SD Cross-platform, no 4 GB file No journaling, less resilient
cards limit
ReFS Windows Server Data integrity, large volume Limited adoption outside
support enterprise use
Btrfs Linux Copy-on-write, snapshots, Still maturing, evolving
self-healing
XFS Linux servers High performance, large file Harder to resize compared to
support others
In older versions of Windows (like XP), the user data was stored in C:\Documents and
Settings, but in modern Windows versions, it's found in C:\Users.
Protection in an operating system (OS) refers to the mechanisms and policies that control the
access and usage of resources like memory, files, devices, and CPU by users and processes. The
main goal of protection is to ensure that resources are used correctly, preventing accidental or
malicious interference from other processes or users. Proper protection mechanisms safeguard
data integrity, privacy, and system stability.
1. Domain of Protection
A protection domain defines the scope in which an entity (user or process) operates and what
resources it can access. Each domain includes:
Objects: The resources like files, devices, or memory regions.
Rights (Permissions): The operations that can be performed on the objects (e.g., read,
write, execute, delete).
A process operates within a certain domain and can access only the resources allowed by the
rights defined for that domain. Domains can be associated with users, processes, or programs.
2. Access Control
Access control mechanisms define which users or processes can access specific resources and
perform particular actions. Access control policies enforce security by restricting access based on
the permissions associated with resources. There are several types of access control mechanisms:
3. Protection Mechanisms
a) Authentication
a. Authentication ensures that the entity requesting access is the one it claims to be.
This is the first step in protection. Common authentication methods include:
b. Passwords: The most basic form of authentication.
c. Biometrics: Fingerprints, facial recognition, or retinal scans.
d. Two-factor authentication: Using a combination of methods, like passwords and
mobile verification codes.
b) Authorization
a. Once a user or process is authenticated, authorization determines what resources
they are allowed to access. Authorization checks are typically based on access
control policies and permissions associated with each resource.
c) Encryption
a. Encryption protects sensitive data by encoding it in such a way that only
authorized entities can decode it. This ensures that even if data is accessed
illegally, it cannot be read or tampered with.
8. Protection Rings
Operating systems often use protection rings to define different privilege levels for code
execution. A common model is the ring model, with Ring 0 being the most privileged (kernel
mode) and Ring 3 the least privileged (user mode). This ensures that:
User applications in Ring 3 cannot directly access the hardware or critical system
resources.
The operating system kernel, in Ring 0, has unrestricted access to system resources.