Unit - 4
Unit - 4
23CSE2010-Operating System
Unit-IV Syllabus
File-System Interface
• A File System Interface in an Operating System (OS) defines how
users, applications, and the OS interact with files stored on a storage
device.
• It provides a structured way to organize, access, read, write, and
manage files and directories. PLD
• Key Components of the File System Interface:
File Concept
Access Methods
Directory Structure
File-System Mounting
File Sharing
Protection
MIT School of Computing
Department of Computer Science & Engineering
File Concept
• A file in an Operating System (OS) is a logical storage unit that stores
data, information, or program instructions on a storage device such as a
hard disk, SSD, or flash drive.
• The OS manages files using a file system, which organizes, retrieves,
and controls access to files efficiently. PLD
• Characteristics of a File:
Persistent – Retains data even after a program terminates.
Named – Identified by a unique name within a directory.
Structured – Contains data in a specific format (text, binary, etc.).
Managed by the OS – The OS controls access, security, and
organization.
MIT School of Computing
Department of Computer Science & Engineering
File-System Structure
File structure:
• Logical storage unit
• Collection of related information
File system resides on secondary storage (disks):
• Provided user interface to storage, mapping
PLD logical to physical.
• Provides efficient and convenient access to disk by allowing data to
be stored, located retrieved easily.
Disk provides in-place rewrite and random access:
• I/O transfers performed in blocks of sectors (usually 512 bytes).
• File control block – storage structure consisting of information
about a file.
• Device driver controls the physical device.
• File system organized into layers.
MIT School of Computing
Department of Computer Science & Engineering
File-System Architecture
PLD
MIT School of Computing
Department of Computer Science & Engineering
File Attributes
Name – only information kept in human-readable form
Identifier – unique tag (number) identifies file within file system
Type – needed for systems that support different types
Location – pointer to file location on device
Size – current file size PLD
Protection – controls who can do reading, writing, executing
Time, date, and user identification – data for protection, security, and
usage monitoring
Information about files are kept in the directory structure, which is
maintained on the disk
Many variations, including extended file attributes such as file
checksum
Information kept in the directory structure
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
Key a
MIT School of Computing
Department of Computer Science & Engineering
File Operations:
File is an abstract data type
Create
Write – at write pointer location
Read – at read pointer location
Reposition within file - seek PLD
Delete
Truncate
Open(Fi) – search the directory structure on disk for entry Fi, and move
the content of entry to memory
Close (Fi) – move the content of entry Fi in memory to directory
structure on disk
MIT School of Computing
Department of Computer Science & Engineering
Access Methods
In operating systems, file management involves various access methods
that determine how data is read from and written to a file. The most
common access methods include:
1. Sequential Access
Data is accessed in a linear order, one record PLD
after another.
Suitable for text files and log files.
MIT School of Computing
Department of Computer Science & Engineering
Access Methods
2.Direct (Random) Access
Allows access to data at any position without
reading sequentially.
Useful for databases and binary files.
Uses seek() to move to a specific location PLD
MIT School of Computing
Department of Computer Science & Engineering
Access Methods
3. Indexed Access and Relative File
Uses an index table to locate data
efficiently.
Common in database management systems
(DBMS). PLD
Example: An index file storing byte offsets
for quick lookup.
MIT School of Computing
Department of Computer Science & Engineering
Access Methods
3. Indexed Access and Relative File
Uses an index table to locate data
efficiently.
Common in database management systems
(DBMS). PLD
Example: An index file storing byte offsets
for quick lookup.
MIT School of Computing
Department of Computer Science & Engineering
Directory Structure
A collection of nodes containing information about all files
PLD
Disk Structure
PLD
MIT School of Computing
Department of Computer Science & Engineering
Directory Structure
The directory is organized logically to obtain
Efficiency – locating a file quickly
Naming – convenient to users
PLD
Two users can have same name for different files
The same file can have several different names
Grouping – logical grouping of files by properties, (e.g., all Java programs,
all games, …)
MIT School of Computing
Department of Computer Science & Engineering
Single-Level Directory
PLD
MIT School of Computing
Department of Computer Science & Engineering
Two-Level Directory
PLD
MIT School of Computing
Department of Computer Science & Engineering
Tree-Structured Directories
PLD
MIT School of Computing
Department of Computer Science & Engineering
Grouping Capability
PLD
Current directory (working directory)
cd /spell/mail/prog
type list
MIT School of Computing
Department of Computer Science & Engineering
Acyclic-Graph Directories
Have shared subdirectories and files
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
File-System Mounting
• A file system must be mounted before it can be accessed
• A unmounted file system (i.e., Fig. a-(b)) is mounted at a mount point
PLD
MIT School of Computing
Department of Computer Science & Engineering
Mount Point
PLD
MIT School of Computing
Department of Computer Science & Engineering
File Sharing
Sharing of files on multi-user systems is desirable
Sharing may be done through a protection scheme
On distributed systems, files may be shared across a network
Network File System (NFS) is a commonPLD
distributed file-sharing method
If multi-user system
User IDs identify users, allowing permissions and protections to be per-
user
Group IDs allow users to be in groups, permitting group access rights
Owner of a file / directory
Group of a file / directory
MIT School of Computing
Department of Computer Science & Engineering
Protection
File owner/creator should be able to control:
what can be done
by whom
Types of access PLD
Read
Write
Execute
Append
Delete
List
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
File-System Implementation
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 (a) refers to opening a file
Figure (b) refers to reading a file PLD
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 mem
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
Directory Implementation
Linear listof file names with pointer to the data blocks
• Simple to program
• Time-consuming to execute
Linear search time
Could keep ordered alphabetically via PLD
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
MIT School of Computing
Department of Computer Science & Engineering
Allocation Methods
An allocation method refers to how disk blocks are allocated for
files:
Linked allocation
Indexed allocation
MIT School of Computing
Department of Computer Science & Engineering
Contiguous Allocation
Each file occupies a set of contiguous blocks on the disk
Simple –only starting location (block #) and length (number of blocks) are
PLD
required
Random access
Contiguous Allocation
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
Extent-Based Systems
Many newer file systems (i.e., Veritas File System) use a modified contiguous
allocation scheme
Extent-based file systems allocate disk blocks
PLDin extents
Linked Allocation
Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
Linked Allocation
PLD
MIT School of Computing
Department of Computer Science & Engineering
File-Allocation Table
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
Q1= block of index table
R1is used as follows:
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
Directory Implementation
Linear list of file names with pointer to the data blocks
• simple to program
• time-consuming to execute
PLD
Hash Table –linear list with hash data structure
• decreases directory search time
• collisions–situations where two file names hash to the same location
• fixed size
MIT School of Computing
Department of Computer Science & Engineering
Recovery
Consistency checking–compares data in directory structure with data blocks on disk, and tries
to fix inconsistencies
• Can be slow and sometimes fails PLD
Use system programs to back updata from disk to another storage device (magnetic tape, other
Mass-Storage Structure
Magnetic disks provide bulk of secondary storage of modern computers
Drives rotate at 60 to 200 times per second
Transfer rate is rate at which data flow between drive and computer
Positioning time (random-access time)
PLD is time to move disk arm to desired
cylinder (seek time) and time for desired sector to rotate under the disk head
(rotational latency)
Head crash results from disk head making contact with the disk surface.
Disks can be removable
Drive attached to computer via I/O bus
Busses vary, including EIDE, ATA, SATA, USB, Fibre Channel, SCSI
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
Disk Structure
Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the
logical block is the smallest unit of transfer.
The 1-dimensional array of logical blocks is mapped into the sectors of the disk
sequentially. PLD
Sector 0 is the first sector of the first track on the outermost cylinder.
Mapping proceeds in order through that track, then the rest of the tracks in that
cylinder, and then through the rest of the cylinders from outermost to innermost.
MIT School of Computing
Department of Computer Science & Engineering
Disk Scheduling …
The operating system is responsible for using hardware efficiently — for the
disk drives, this means having a fast access time and disk bandwidth.
Access time has two major components
Seek time is the time for the disk are to move the heads to the cylinder
Swap-Space Management
Swap-space — Virtual memory uses disk space as an extension of main memory.
Swap-space can be carved out of the normal file system,or, more commonly, it can be
in a separate disk partition.
Swap-space management
PLD
4.3BSD allocates swap space when process starts; holds text segment (the
program) and data segment.
Kernel uses swap maps to track swap-space use.
Solaris 2 allocates swap space only when a page is forced out of physical memory,
not when the virtual memory page is first created.
MIT School of Computing
Department of Computer Science & Engineering
For example, consider a disk queue with requests arriving for the following tracks (in order):
98, 183, 37, 122, 14, 124, 65, 67
• The read/write head is currently at 53.
• The goal is to determine which algorithm performs best in minimizing seek time.
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD
MIT School of Computing
Department of Computer Science & Engineering
PLD