Operating Systems
Prof. Navneet Goyal
Department of Computer Science & Information Systems
BITS, Pilani
Topics
• Files
• Access Methods
• Directory Structure
• File System mounting
• File sharing
• Protection
Files
• Most visible aspect of an OS
• Files provide mechanism for online
storage of and access to both data and
programs of the OS and all the users
• A typical file system consists of:
▫ Files (each storing related data)
▫ Metadata (directory structure)
Files
• Information can be stored on various
storage media
• OS provides a uniform logical view of
information storage
• OS abstracts from the physical properties
of its storage devices to define a logical
storage unit, FILE!
• Files are mapped by the OS onto physical
devices
Files
• File is a named collection of related
information that is recorded on a
secondary storage
• Smallest allotment of logical secondary
storage
• Data cannot be written on secondary
storage unless it is written on a file
• File is a very general concept
File System
• Collection of Files
File contains related data
• Directory Structure
Organizes & provides information about all files in the
system
• Partitions
Separates physically or logically large collections of
directories
Typical File System
File Attributes
• Name
• Identifier (generally a number)
• Type
• Location (device: location)
• Size (bytes, words or blocks)
• Protection (rwx)
• Time, date, & user identification
(creation, last modification, last
use)
File Operations
• File is an ADT
• Must define operations on files
• File Operations
▫ Creating
▫ Writing
▫ Reading
▫ Repositioning within file (file seek)
▫ Deleting
▫ Truncating
• OS provides system calls for each operation
File Operations
• Creating
▫ Space in the file system must be found for the
file
▫ Entry for the new file must be made in the
directory
• Writing a file
▫ System call specifying the name of the file and
the information to be written. System keeps a
pointer to the location where the next write is
to take place
File Operations
• Reading
▫ System call specifying the name of the file and
where the next block of the file should be put.
▫ A process is either reading from a file or writing to a
file, the current operation location can be kept as
per process “current-file-position” pointer
▫ Both read and write ops. Use this same pointer to
save space & system complexity
• Repositioning within a file
▫ Current file position pointer is repositioned to a
given value. Need not involve an actual I/O. Also
called as file seek
File Operations
• Deleting a file
▫ Search the directory for the names file,
release all file space, and erase the directory
entry
• Truncating a file
▫ Erases the content of a file but keeps its
attributes
File Operations
• Other Operations
▫ Appending
▫ Renaming
▫ Copy
▫ Move
• open() system call
▫ Must be invoked before a file is used
▫ Open file table is maintained by OS
• Create & Delete work with closed files
File Types
Access Methods
• Files contain information
• Information must be accessed and read
into memory for processing
• Information in files can be accessed in
several ways
• Most systems provide only one method
• Some systems provide many
Access Methods
• Choosing the right one for a particular
application is a typical design issue
• Sequential Access
• Direct Access
• Indexes (IBMs ISAM)
Directory Structure
• Stores information about all files
• Resides on secondary storage
• Contains file’s name & Identifier
• Identifier in turn locates other file attributes
• More than 1KB of information for each file
• Directory structure size in MBs
• Backups of files and directory structure kept
on tapes
Directory Structure
• Disks are split into one or more partitions
• Minidisks or Volumes
• Each disk contains atleast one partition
• Partitions can be larger than a disk
• Partitions are “virtual disks”
• Partition maintains information about files
in “Device Directory”
Directory Structure
A collection of nodes containing information about all files.
Both the directory structure and the files reside on disk
Backups of these two structures are kept on tapes
Information in a Directory
• Name
• Type
• Address
• Current length
• Maximum length
• Date last accessed
• Date last updated
• Owner ID
• Protection information
Directory Operations
• Search for a file
• Create a file
• Delete a file
• List a directory
• Rename a file
• Traverse the file system
How to Organize a Directory?
Issues
• Efficiency – locating a file quickly
• Naming – convenient to users
• 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, …)
Schemes for defining the logical structure of a directory:
• Single level directory
• Two level directory
• Tree structured directory
• Acyclic graph directory
• General graph directory
Single-Level Directory
Single directory for all users: easy to support & understand
• All files in a single directory
• Naming problem (unique names)
• Grouping Problem
Two-Level Directory
Separate directory for each user
• each user has its own UFD (user file dir)
• UFDs have similar structure
• When a user logs in, the MFD (master file dir) is searched
• MFD is indexed by user name or accnt no.
• Each entry in MFD points to a UFD
• User name & a file name define a path name
Two-Level Directory
Separate directory for each user
• When a user refers to a file, only his own UFD is searched
• File names can be shared among users
• Solves the name-collision problem
• Disadvantages?
• System files?
Two-Level Directory
Separate directory for each user
• File name would be searched in the current UFD only
• Copy system files to each UFD!!
• Standard solution: special user directory is defined to
contain system files: say user 0
• Search procedure?
Tree-Structured Directory
Tree-Structured Directory
• Generalization of two-level directory (with arbitrary height)
• Each user has a current directory (working directory)
▫ Can change current directory via cd command or system call
• Path names can be absolute or relative
Operations
• Creating a new file is done in current directory
• Delete a file
▫ rm <file-name>
• Creating a new subdirectory is done in current directory
▫ mkdir <dir-name>
Advantages
• Efficient searching
• Grouping Capability
Acyclic-Graph Directory
• 2 programmers working on a joint project
• File pertaining to project stored in a
subdirectory of each user
• Shared subdirectory!
• Tree structure prohibits the sharing of files
or directories!
• A shared file or dir will exist in the file
system in two or more places at once
• AGD allows files & dirs to be shared
Acyclic-Graph Directory
• Shared file is not the same as two copies of
the file
• With a shared file, only one actual file exists
• Shared subdirectories
• Files created in this SD will auto. appear in
all the shared SDs
• LINKS!!
Acyclic-Graph Directory
• A link is a pointer to another file or subdirectory
• Link may be implemented as an absolute or a
relative path
• When a reference to a file is made
▫ directory is searched
▫ If directory entry is marked as a link, name of the
real file is included in the link information
▫ Link is resolved using the path name to locate
the real file
• Tree traversal is used to traverse directories
Acyclic-Graph Directory
Duplication
• Duplicate all information in both the sharing
directories
• Original & copy indistinguishable
• Maintaining consistency when a file is modified is a
problem
Acyclic-Graph Directory
Problems
• AGD is more flexible but more complex
• File may have multiple absolute path names.
Different file names refer to the same file!!
Acyclic-Graph Directory
Have shared subdirectories
and files using acyclic graph
Two different names exist
(aliasing problem)
If ‘dict’ deletes list ⇒
dangling pointer (UNIX case)
Solutions:
Preserve file until all references
to it are deleted
Reference count solution
General-Graph Directory
Add links to an existing tree
structured directory, resulting in a
simple graph structure
Want to avoid searching any
shared components twice
Reference count solution does
not hold due to self-reference
=> use garbage collection
Acyclic structure is much easier
to work with
How do we guarantee no cycle?
Allow links only to file not
subdirectories
Every time a new link is
added use a cycle detection
algorithm
General Graph Directory
• Problem with AGD: ensuring no cycles
• Allowing users to create files & directories to an existing
tree structure preserves the tree-structured nature
• But, when we allow links to be added to an existing tree
structure, the tree structure is destroyed, resulting in a
simple graph structure
File System Mounting
• Just as a file must be opened before it is
used, a file system must be mounted before
it can be accessed
• Procedure?
File System Mounting
Procedure
▫ The OS is given the name of the device, and the
location within the file structure at which to attach
the file system (or mount point)
▫ Typically, a mount point is an empty directory
▫ The OS verifies that the device contains a valid file
system by asking the device driver to read the
directory
▫ Finally, the OS notes in its directory structure that a
file system is mounted at the specified mount point;
This scheme enables the OS to traverse its directory
structure, switching among file systems as
appropriate
File System Mounting
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 common distributed
file-sharing method
File Sharing: Multiple Users
• User IDs identify users, allowing permissions and
protections to be per-user
• Group IDs allow users to be in groups, permitting
group access rights
File Sharing: Remote File Systems
Uses networking to allow file system access between systems
Manually via programs like FTP
Automatically, seamlessly using distributed file systems
Semi automatically via the world wide web
Client-server model allows clients to mount remote file systems
from servers
Server can serve multiple clients
Client and user-on-client identification is insecure or complicated
NFS is standard UNIX client-server file sharing protocol
CIFS is standard Windows protocol
Standard operating system file calls are translated into remote calls
Distributed Information Systems (distributed naming services)
such as LDAP, DNS, NIS, Active Directory implement unified
access to information needed for remote computing
Protection
File owner/creator should be able to control:
what can be done
by whom
Types of access
Read
Write
Execute
Append
Delete
List
Access Control List (ACL)
Various users may need different types of access to a file or
directory
The most general scheme is to associate with each file &
directory an access-control list (ACL) specifying the user name
& the types of access allowed for each user
Advantages
Enable complex access methodology
Disadvantages
Constructing such a list may be a tedious and unrewarding task,
especially if we do not know in advance the list of users in the
system
The directory entry, previously of fixed size, now needs to be of
variable size, resulting in more complicated space
management
Access Lists & Groups (UNIX)
Various users may need different types of access to a file or
directory
The most general scheme is to associate with each file &
directory an access-control list (ACL) specifying the user name
& the types of access allowed for each user
Advantages
Enable complex access methodology
Disadvantages
Constructing such a list may be a tedious and unrewarding task,
especially if we do not know in advance the list of users in the
system
The directory entry, previously of fixed size, now needs to be of
variable size, resulting in more complicated space
management
Access Lists & Groups (UNIX)
Sample Directory Listing (UNIX)
Windows XP Access-control List
Management
UNIX File System
Working Directory
Home Directory
UNIX File Hierarchy
Some Standard Directories
Output of ls - lF
Types of Files
Special Files
Creating Links
File Ownership
File Permissions
File Modification Date
Disk partition
B S
inode list data blocks
• Boot area
▫ Code required to bootstrap the operating system
• Superblock
▫ Attributes and metadata of the file system itself
• inode list
▫ a linear array of inodes
• data blocks
▫ data blocks for files and directories
Superblock
• It contains
▫ Size in blocks of the file system
▫ Size in blocks of the inode list
▫ Number of free blocks and inodes
▫ Free block list(Partial)
▫ Free inode list(Partial)
• The kernel reads the superblock and
stores it in memory when mounting the
file system
Inode
• Each file has an inode associated with it
• Inode contains metadata for file
• on-disk inode refers to inode stored in
disk within the inode list
• in-core inode refers to inode stored in
memory when a file is open
INODES
Kernel maintains file information in a
structure called inode.
Creation, modification time stamps
Ownership, file size etc.
Commonly used INODE information
can be found by using ls command
On-disk inode
• The size of on-disk inode is 64 bytes
Field Size Description
di_mode 2 File type, permissions
di_uid 2 Owner UID
di_gid 2 Owner GID
di_size 4 Size in bytes
di_addr 39 Array of block addresses
: : :
In-core Inode
• It contains all the fields of on-disk inode,
and some additional fields, such as
▫ The status of the in-core inode (whether the inode is
locked, which process is waiting, etc.)
▫ The logical device number containing the file
▫ The inode number of the file
▫ Pointers to keep the inode on a free list
▫ Pointers to keep the inode on a hash queue.
▫ Block number of last block read.