You are on page 1of 29

Lecture 10: File System

Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009
Chapter 10: File System Interface
File Concept
Access Methods
Directory Structure
Protection

Operating System Concepts – 8th Edition 10.2 Silberschatz, Galvin and Gagne ©2009
Objectives
To explain the function of file systems

To describe the interfaces to file systems

To discuss file-system design tradeoffs, including access methods, file


sharing, file locking, and directory structures

To explore file-system protection

Operating System Concepts – 8th Edition 10.3 Silberschatz, Galvin and Gagne ©2009
File Concept
File is a logical storage unit. File are mapped by the operating system onto
physical devices.

Types:
Data
numeric
character
binary
Program
Source form
Object form

Operating System Concepts – 8th Edition 10.4 Silberschatz, Galvin and Gagne ©2009
File Attributes
Name – the 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
Protection – access-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

Operating System Concepts – 8th Edition 10.5 Silberschatz, Galvin and Gagne ©2009
File Operations
File is an abstract data type
Create
Write
Read
Reposition within file – also known as seek
Delete
Truncate – erase the contents of a file but keep its attributes
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

Operating System Concepts – 8th Edition 10.6 Silberschatz, Galvin and Gagne ©2009
Open Files
Several pieces of data are needed to manage open files:
File pointer: pointer to last read/write location, unique to each
process operating on the file
File-open count: count tracks the number of opens and closes –
to allow removal of data from open-file table when last processes
closes it
Disk location of the file: the information needed to locate the file
on disk
Access rights: per-process access mode information

Operating System Concepts – 8th Edition 10.7 Silberschatz, Galvin and Gagne ©2009
Open File Locking
Provided by some operating systems and file systems

File locks allow one process to lock a file and prevent other processes
from gaining access to it.

File locks are useful for files that are shared by several processes—for
example, a system log

Shared or exclusive:
Shared – several processes can acquire the lock concurrently
Exclusive – only one process at a time can acquire such a lock

Operating System Concepts – 8th Edition 10.8 Silberschatz, Galvin and Gagne ©2009
File Types – Name, Extension
Included as part of the file
name - name.extension

The system uses the


extension to indicate the
type of the file and the
type of operations that
can be done on that file.

Operating System Concepts – 8th Edition 10.9 Silberschatz, Galvin and Gagne ©2009
Access Methods
Sequential Access
Information in the file is processed in order, one record after the
other.
Usage: editors and compilers

Direct Access (or Relative Access)


A file is made up of fixed-length logical records
Allow programs to read and write records rapidly in no
particular order
Usage: database

Index
Build on top of a direct-access method
The index, like an index in the back of a book, contains pointers
to the various blocks
To find a record in the file, first search the index and then use
the pointer to access the file directly and to find the desired
record.

Operating System Concepts – 8th Edition 10.10 Silberschatz, Galvin and Gagne ©2009
Sequential-access File

Operating System Concepts – 8th Edition 10.11 Silberschatz, Galvin and Gagne ©2009
Example of Index and Relative Files

Operating System Concepts – 8th Edition 10.12 Silberschatz, Galvin and Gagne ©2009
Directory Structure
A collection of nodes containing information about all files - such as
name, location, size, and type

Directory

Files
F1 F2 F4
F3
Fn

Both the directory structure and the files reside on disk.


Backups of these two structures are kept on tapes.

Operating System Concepts – 8th Edition 10.13 Silberschatz, Galvin and Gagne ©2009
Disk Structure
Disk can be subdivided into partitions
Disks or partitions can be RAID (Redundant Array of
Independent Disks) protected against failure of a single disk
Disk or partition can be used raw – without a file system, or
formatted with a file system
Entity containing file system known as a volume
Each volume containing file system also tracks that file
system’s info in device directory or volume table of contents
As well as general-purpose file systems there are many
special-purpose file systems, frequently all within the same
operating system or computer

Operating System Concepts – 8th Edition 10.14 Silberschatz, Galvin and Gagne ©2009
A Typical File-system Organization

Operating System Concepts – 8th Edition 10.15 Silberschatz, Galvin and Gagne ©2009
Operations Performed on Directory
Search for a file

Create a file

Delete a file

List a directory

Rename a file

Traverse the file system


access every directory and every file within a directory structure.

Operating System Concepts – 8th Edition 10.16 Silberschatz, Galvin and Gagne ©2009
Single-Level Directory
All files are contained in the same directory.
All files must have unique names.

Limitations:
when the number of files increases
when the system has more than one user

Operating System Concepts – 8th Edition 10.17 Silberschatz, Galvin and Gagne ©2009
Two-Level Directory
Separate directory for each user.

Define path name


Can have the same file name for different user
Efficient searching

Operating System Concepts – 8th Edition 10.18 Silberschatz, Galvin and Gagne ©2009
Tree-Structured Directories

Operating System Concepts – 8th Edition 10.19 Silberschatz, Galvin and Gagne ©2009
Tree-Structured Directories (Cont.)
Most common directory structure.

The tree has a root directory, and every file in the system has a unique path
name.

Efficient searching

Current directory (working directory) - should contain most of the files that
are of current interest to the process.

Path names:
Absolute - begins at the root and follows a path down to the specified
file (e.g. /home/user)
Relative - defines a path from the current directory (e.g. user/dir)

Operating System Concepts – 8th Edition 10.20 Silberschatz, Galvin and Gagne ©2009
Acyclic-Graph Directories

Have shared subdirectories and files

Operating System Concepts – 8th Edition 10.21 Silberschatz, Galvin and Gagne ©2009
Acyclic-Graph Directories (Cont.)
Two different names (aliasing)

If dict deletes count ⇒ dangling pointer


Solutions:
Backpointers, so we can delete all pointers
Variable size records a problem
Backpointers using a daisy chain organization

New directory entry type


Link – another name (pointer) to an existing file
Resolve the link – follow pointer to locate the file

Operating System Concepts – 8th Edition 10.22 Silberschatz, Galvin and Gagne ©2009
General Graph Directory

Operating System Concepts – 8th Edition 10.23 Silberschatz, Galvin and Gagne ©2009
General Graph Directory (Cont.)
How do we guarantee no cycles?
Allow only links to file not subdirectories
Garbage collection - determine when the last reference has been
deleted and the disk space can be reallocated.
Every time a new link is added use a cycle detection algorithm to
determine whether it is OK

Operating System Concepts – 8th Edition 10.24 Silberschatz, Galvin and Gagne ©2009
Protection
File owner/creator should be able to control:
what can be done
by whom

Types of access
Read - Read from the file.
Write - Write or rewrite the file.
Execute - Load the file into memory and execute it.
Append - Write new information at the end of the file.
Delete - Delete the file and free its space for possible reuse.
List - List the name and attributes of the file.

Operating System Concepts – 8th Edition 10.25 Silberschatz, Galvin and Gagne ©2009
Access Lists and Groups
Mode of access: read, write, execute
Three classes of users
RWX
a) owner access 7 ⇒ 111
RWX
b) group access 6 ⇒ 110
RWX
c) public access 1 ⇒ 001
Ask manager to create a group (unique name), say G, and add
some users to the group.
For a particular file (say game) or subdirectory, define an
appropriate access.

owner group public

chmod 761 game

Attach a group to a file


chgrp G game

Operating System Concepts – 8th Edition 10.26 Silberschatz, Galvin and Gagne ©2009
Windows XP Access-Control
List Management

Operating System Concepts – 8th Edition 10.27 Silberschatz, Galvin and Gagne ©2009
A Sample UNIX Directory Listing

Operating System Concepts – 8th Edition 10.28 Silberschatz, Galvin and Gagne ©2009
End of Chapter 10

Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009

You might also like