Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views38 pages

ch9 OS

The document is a lecture on the file-system interface in operating systems, covering key concepts such as file structures, attributes, operations, and access methods. It discusses the organization of directories and disk structures, including different directory types and file sharing mechanisms. The lecture also highlights the importance of file protection and consistency semantics in multi-user environments.

Uploaded by

salaramirwork
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)
16 views38 pages

ch9 OS

The document is a lecture on the file-system interface in operating systems, covering key concepts such as file structures, attributes, operations, and access methods. It discusses the organization of directories and disk structures, including different directory types and file sharing mechanisms. The lecture also highlights the importance of file protection and consistency semantics in multi-user environments.

Uploaded by

salaramirwork
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/ 38

CNG334: Introduction to Operating Systems

Dr. Mariem Hmila


Email: [email protected]

Middle East Technical University


North Cyprus Campus

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 1 / 35


LECTURE 9: File -System Interface

An Overview
File Concept
Access Methods
Directory and Disk Structure
File-System Mounting
File Sharing
Protection
Conclusion

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 2 / 35


File -System Interface
An overview 1/2

Files:
It is a collection of related information defined by its creator
Mapped by OS on a physical device
The smallest allotment of logical secondary storage
A file has a certain defined structure
Organized into directories for ease of use
File systems:
Provides a mechanism for on-line storage and access to both programs and
data residing on disk of the operating system and all the users of the
computer system
Composed of: a collection of files and a directory structure

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 3 / 35


File -System Interface
An overview 2/2

Files Structures:
Text file: a sequence of characters organized into lines (and possible
pages).
Source file: is a sequence of subroutines and functions each is organized as
declarations followed by executable statements.
Object file: sequence of bytes organized into blocks understandable by the
systems’ linker.
Executable file: is a series of code sections that the loader can bring to the
memory and execute.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 4 / 35


File -System Interface
File Concept - Attributes 1/2

A file’s attributes vary from one operating system to another but typically
consist of these:
Name: the symbolic file name is the only information kept in human-
readable form.
Identifier: this unique tag, usually a number, identifies the file within the
file system; it is the non-human-readable name for the file.
Type: this information is needed for systems that support different types of
files.
Location: this information is a pointer to a device and to the location of the
file on that device.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 5 / 35


File -System Interface
File Concept - Attributes 2/2

A file’s attributes vary from one operating system to another but typically
consist of these:
Size: the current size of the file (in bytes, words, or blocks) and possibly
the maximum allowed size are included in this attribute.
Protection: Access-control information determines who can do reading,
writing, executing, and so on.
Time, date, and user identification: This information may be kept for
creation, last modification, and last use. These data can be useful for
protection, security, and usage monitoring
Information about all files → directory structure in the secondary storage
directory entry → file’s name and unique identifier.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 6 / 35


File -System Interface
File Concept - Operations 1/2

A file is an abstract data type (logical unit) → has operations using system calls
Creating a file, for this two steps are needed:
Space in the file system must be found for the file
An entry for the new file must be made in the directory.
Write a file: a system call is made specifying the name of the file and the
information to be written to the file.
Reading a file: a system call that specifies the name of the file and where
(in memory) the next block of the file should be put

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 7 / 35


File -System Interface
File Concept - Operations 2/2

A file is an abstract data type (logical unit) → has operations using system calls
Repositioning within a file (file seek): directory is searched for the
appropriate entry, and the current-file-position pointer is repositioned to a
given value.
Deleting a file: search the directory for the named file, then release all file
space.
Truncating a file: this operation allows to erase the contents of a file but
keep its attributes.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 8 / 35


File System Interface
File Concept - Operations 3/3

To avoid directory search required by most of the file operation:


An open() system call is made before a file is first used actively
An open-file table is kept, containing information about all open files.
Once a file operation is requested, the file is specified via an index into this
table
Once the file is no longer needed, it is closed by the process and removed
from the table

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 9 / 35


File System Interface
File Concept - Operations 3/3

In case that several processes can open the file simultaneously.


Example: Multiple applications open the same file at the same time
In this case, two levels of internal tables are used:
The per-process table tracks all files that a process has open, and points to
a system-wide open-file table.
Once the file is opened by a process, and entry included in system-wide
table. This include:
process-independent information as location of file on disk, access data, file
size.
When another process executes an open() call, a new entry is simply added
to the process’s open-file table pointing to the appropriate entry in the
system- wide table.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 10 / 35


File System Interface
File Concept: operations - open file

Several pieces of information are associated with an open file:


File pointer: pointer is unique to each process operating on the file to keep
tracking the last read-write location as current-file-position pointer.
File-open count: the file-open counter tracks the number of opens and
closes and reaches zero on the last close, then the system can remove the
entry.
Disk location of the file: Most file operations require the system to modify
data within the file. The information needed to locate the file on disk is
kept in memory so that the system does not have to read it from disk for
each operation.
Access rights: Each process opens a file in an access mode.This
information is stored on the per-process table so the operating system can
allow or deny subsequent I/O requests.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 11 / 35


File System Interface
File Concept - Files Types

If an operating system recognizes the type of a file, it can then operate on the file
in reasonable ways. Common file types:

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 12 / 35


File System Interface
Access Methods

To accessed information stored in files and read into computer memory,


access method is required.
Depending on the OS, either one method is available or multiples, the
most common ones are:
Sequential Access: information in the file is processed in order, one record
after the other.
Direct Access (relative access): A file is made up of fixed- length logical
records that allow programs to read and write records rapidly in no
particular order.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 13 / 35


File System Interface
Access Methods: Sequential Access

Figure 1: Sequential-access file.

Read Operation: → read next → reads the next portion of the file +
automatically advances a file pointer (that track I/O location)
Write Operation: → write next → appends to the end of the file and
advances to the end of the newly written material (new end of the file)

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 14 / 35


File System Interface
Access Methods: Direct Access (relative access)

A file is made up of fixed length logical records → numbed sequence of


blocks or records
Benefits: no restrictions on the order of writing or reading as Databases.
Operations:
Reading operation: read n → reads from block number n from the file.
write operation: write n → write to block number n in the file.
Note: The block number n provided by the user to the operating system is
a relative number → is an index to the relative beginning of the file.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 15 / 35


File System Interface
Directory and Disk Structure: Visualization

Systems need to store huge number of files on random-access storage


devices
Question: What are the different areas where a file system can be created?
Answer:
A secondary storage can be used entirely for a file system.
A secondary storage can divided to be used to store multiple file systems,
swapping, raw disk space. The resulted parts named:
Partitions
Slices
Minidisk
Any entity containing a file system is generally known as a Volume +
related information kept in a device directory or volume table of contents.
Example of information: name, location, size, type ..etc

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 16 / 35


File System Interface
Directory and Disk Structure: Visualization

Figure 2: A typical file-system organization.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 17 / 35


File System Interface
Directory and Disk Structure: Directory Overview 1/2

A directory: can be thought of as a symbol table that translates file names


into their directory entries.
The operations that are to be performed on a directory:
Search for a file: to find the entry for a particular file
Create a file: New files need to be created and added to the directory.
Delete a file: remove the no longer needed files from the directory.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 18 / 35


File System Interface
Directory and Disk Structure: Directory Overview 2/2

A directory: can be thought of as a symbol table that translates file names


into their directory entries.
The operations that are to be performed on a directory:
List a directory: list all the files in the directory and directory entry’s
content for each file in the list.
Rename a file
Traverse the file system: move from one file to another on the directory.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 19 / 35


File System Interface
Directory and Disk Structure

we describe the most common schemes for defining the logical structure
of a directory:
Single-Level Directory
Two-Level Directory
Tree-Structured Directories

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 20 / 35


File System Interface
Directory and Disk Structure: Single level Directory

Idea: All files are contained in the same directory, each must have a
unique name
Question: what are the limitations? → naming
Question: what are the advantages?

Figure 3: Single-level directory.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 21 / 35


File System Interface
Directory and Disk Structure: Two Level Directory

There is a user file directory (UFD) per user


The system’s master file directory (MFD) is searched as the user logged in
The MFD is indexed by user name or account number, and each entry points to
the UFD for that user
Question: what are the limitations? → isolation
Question: what are the advantages? → no naming problem

Figure 4: Two-level directory structure.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 22 / 35


File System Interface
Directory and Disk Structure: Tree-Structured Directories 1/2

It is possible to have the directory structure inform of a tree of arbitrary height


Root directory, and every file has a unique path name.
Question: what are the limitations? advantages?

Figure 5: Tree-structured directory structure.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 23 / 35


File System Interface
Directory and Disk Structure: Tree-Structured Directories 2/2

Current directory:
Each process has a current directory, which include most of the files that
are of current interest to the process
The Current directory is searched a reference to a file is made.
Path Names:
Absolute: begins at the root and follows a path to the specific file, giving
the directory name on the path.
Assume current directory is: root/spell/mail
Example: root/spell/mail/ptr/first
Relative: defines a path name from the current directory.
Assume current directory is: root/spell/mail
Example: ptr/first

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 24 / 35


File System Interface
Directory and Disk Structure: Tree-Structured Directories 2/2

Operation delete of a directory:


If the directory is empty its entry in the directory that contains it can
simply be deleted.
Else, two possible options are available based on the system:
All its files and subdirectories must be deleted first.
Delete directories and all included files and subdirectories.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 25 / 35


File System Interface
File-System Mounting

Mounting is a process by which the OS makes the files and directories on a


storage device available for users to access withing the file-system.
How it works:
The OS is given the name of the device and the mount point.
The mount point → the location where the file system is to be attached.
Example: In Unix system we might mount as /home or /users
/users/john or /home/john
The OS, verifies that devices contains a valid file system.
The operating system notes in its directory structure that a file system is
mounted at the specified mount point.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 26 / 35


File System Interface
File-System Mounting: Illustration

Figure 6: File system. (a) Existing system. (b) Unmounted volume, and the change
after mounting.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 27 / 35


File System Interface
File Sharing

Different users may want to collaborate


Issues: coming from having multiuser:
File sharing
File naming
File protection
A directory structure that allows files to be shared between users, the system
must mediate file sharing:
Allow access by a user to the other user’s file by default
OR require a user to grant access to the files
For this, more attributed are needed for file and directory:
Owner: user who can change attributes and grant access and who has most
control over file.
Group: a subset of users who can share access to the file.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 28 / 35


File System Interface
File Sharing: Consistency Semantics

An important criterion for evaluating any file system that supports file sharing
Consistency Semantics: Specify when modifications of data by one user will be
observable by other users.
Example: UNIX Semantics
Write to an open file by a user are visible to other users that have this file
open → Share the pointer of current location

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 29 / 35


File System Interface
Failure Modes

Local file system can fail for various reasons:


Failure of the disk containing the file system
Corruption of the directory structure or other disk management
information
Disk-controller failure
Cable Failure
Host-adapter Failure
Most of these failures will cause a host to crash and an error condition to be
displayed, and human intervention will be required to repair the damage.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 30 / 35


File System Interface
Protection

Question: From what we try to protect our files system?


Answer: Information stored in our computer must be kept safe from:
Physical damage → to provide Reliability
Improper access → Protection
Question: How can a file system be damaged?
Answer: Hardware problems, Power Failure, Head crashes ...etc
Solution: Duplicates (backup version)
Question: How can a system be protect from improper access?
Single - user: pwd, hide removable storages
Multi- user: use types of access

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 31 / 35


File System Interface
Protection: Types of Access

Question: What are the available types of access?


Answer:
Complete Protection: Prohibiting access to everyone except the owner.
Free access: no protection, everyone can access the file.
Question: Any problems?

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 32 / 35


File System Interface
Protection: Types of Access

Question: What are the available types of access?


Answer:
Complete Protection: Prohibiting access to everyone except the owner.
Free access: no protection, everyone can access the file.
Question: Any problems?
Question: Any solutions?

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 32 / 35


File System Interface
Protection: Types of Access

Question: What are the available types of access?


Answer:
Complete Protection: Prohibiting access to everyone except the owner.
Free access: no protection, everyone can access the file.
Question: Any problems?
Question: Any solutions?
Answer: Controlled access, where the type of file access limiting can be made
by different users. AS:
Control Read
Control Write
Control Execute
Control Appending
Control Delete

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 32 / 35


File System Interface
Protection: Types of Access - Controlled Access 2/2

Manage what is allowed per user to do in term operation of the file → Depend
on user ID
Question: How?
Answer: Access Control List (ACL) that specify user names and the types of
access allowed per each.
Question: Any problems? if so, any solutions?

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 33 / 35


File System Interface
Protection: Types of Access - Controlled Access 2/2

Manage what is allowed per user to do in term operation of the file → Depend
on user ID
Question: How?
Answer: Access Control List (ACL) that specify user names and the types of
access allowed per each.
Question: Any problems? if so, any solutions?
Answer: use a condensed version of the access list, via users’ classification:
Owner
Group
universe

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 33 / 35


File System Interface
Protection: Types of Access - Controlled Access Example

A sample directory listing from a UNIX environment is shown. In order we


have:
Permissions, links number, file owner name, group name, file size,
creation date and time, file name

Figure 7: A sample directory listing.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 34 / 35


Conclusion

The major task for the operating system is to map the logical file concept onto
physical storage devices such as magnetic tape or disk
Disks are segmented into one or more volumes, each containing a file system or
left “raw.”
File sharing depends on the semantics provided by the system. Files may have
multiple readers, multiple writers, or limits on sharing
Access to files can be controlled separately for each type of access—read, write,
execute, append, delete, list directory, and so on.

Dr.Mariem Hmila (METU NCC) CNG334: Introduction to Operating Systems 35 / 35

You might also like