Tải bản đầy đủ (.pdf) (66 trang)

Lecture Operating systems: A concept-based approach (2/e): Chapter 7 - Dhananjay M. Dhamdhere

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (718.15 KB, 66 trang )

PROPRIETARY MATERIAL. ©  2007 The McGraw­Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide  may be displayed, reproduced or distributed 
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw­Hill 
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission. 

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 1
 Copyright © 2008


Goals of a File system



Convenient and fast access to files
– Different file organizations to suit different user requirements



Reliable storage of files
– Prevents damage due to crashes, etc.



Controlled sharing of files
– Unauthorized persons should not be able to access files




…. also ensure efficient use of I/O devices
– We discuss this aspect in Chapter 12

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 2
 Copyright © 2008


Structure of a File system



A file system is structured into a hierarchy of layers
– File system layer
* Deals with files as objects
 Creates files, allocates disk space to them
 Implements file sharing and prevents unauthorized access
 Prevents damage due to crashes

– Input-Output Control System (IOCS) layer
* Implements file system operations, ensuring
 Efficient access to records in files
 Efficient operation of I/O devices


Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 3
 Copyright © 2008


File system and IOCS layers

• Each layer contains policy and mechanism modules
• A mechanism module invokes modules of the lower layer
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 4
 Copyright © 2008


File system



A Directory

– Groups a set of files
* It contains an entry for each of these files
* The entry contains information useful for accessing the file

– Users have different directories
* Helps to separate files of different users
* Provides file naming freedom

– Directories are organized in a hierarchical structure
* Permits a user to organize her files logically, e.g., according to
activities

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 5
 Copyright © 2008


Logical organization in file systems

• Two files named beta exist. The file system must open the correct
one when a process executes open (beta, .. )
• Records may be organized differently in different files
Chapter 7:
File Systems


Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 6
 Copyright © 2008


Logical organization in file systems



Comments on the previous slide
– Two files named beta exist in the file system
* Thus users enjoy file naming freedom

– Processes Pi and Pj share one of these files
* The rules of sharing are determined by file sharing semantics

– Files beta and phi have different organizations and are accessed
differently
* File beta is a sequential file; its records are read in a sequence
* File phi is a direct file; its records can be read in random order

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 7

 Copyright © 2008


Overview of file processing



Implementation of file processing activities
– File processing activities are implemented through combined
actions of a compiler, modules of the file system and IOCS, and
the kernel
* The compiler replaces open and read/write statements in a program
with calls on file system and IOCS modules
 These modules implement the desired file operations
 These file system and IOCS modules are linked to the program
* A process executing the program invokes these modules during its
operation to perform file operations
 The modules may make system calls to invoke functionalities of
the kernel

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 8
 Copyright © 2008



File processing in a program
Source program

compiled program

linked program

• The program invokes file system modules during execution
• File system modules invoke the IOCS modules
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 9
 Copyright © 2008


File Types



Files can be of two types
– Structured files
* A File contains records
* Each record contains a key field
 Key fields of records in a file contain unique values
* Records in a file can be accessed in different ways
 Sequential access

 Random access by specifying the key value of a record

– Byte-stream files
* A file is merely a stream of bytes

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 10
 Copyright © 2008


Records and fields in a file

• File employee_info contains records for employees
• A record contains fields for employee no, name, etc.
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 11
 Copyright © 2008


File operations performed by processes




File operations
– Opening a file
* FS opens the file only if user possesses necessary privileges

– Reading or writing a record
* FS considers organization of the file and performs the operation
accordingly

– Closing a file
* FS updates information concerning file size in its directory entry

– File creation, deletion and renaming
– Specifying who can access a file
* The information is entered in the file’s directory entry

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 12
 Copyright © 2008


File organizations




Record access pattern
– Definition
* The order in which a process accesses records in a file

– Two fundamental record access patterns in applications
* Sequential access
 A process always performs an operation on the next record
 Suits batched operations; e.g., payroll
* Random access
 A process may access any record in a file

– File system should effectively support the record access pattern
of an application

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 13
 Copyright © 2008


File organizations




File organization
– Method of organizing and accessing data in a file
– Sequential file organization
* Records in the file are accessed sequentially
 This file organization is independent of characteristics of I/O
devices

– Direct file organization
* Records are accessed randomly—a record is found using an
address calculation formula applied to the value in its key field
 Files tend to be device dependent; may contain dummy records

– Index sequential file organization
* File has a hierarchical organization. To locate a record, a region in
the file is first located and then searched sequentially
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 14
 Copyright © 2008


Sequential and direct files

• In sequential files, an operation is always performed on the
next record
• In direct files, an address calculation formula computes

location of a record from its key value
• Dummy records have to exist for the formula to work

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 15
 Copyright © 2008


An Index Sequential file

• The higher level index is searched to find a group of tracks
where a record may exist
• The track index is searched to find the track which may
contain the record
• The track is searched to check whether the record exists
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 16
 Copyright © 2008



A typical directory entry

• Location info indicates where records of the file are located
• Protection info indicates who can access the file and in
what manner
• Flags indicate whether the file is itself a directory, etc.

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 17
 Copyright © 2008


Two-level directories: Master and user directories

• A separate user directory exists for each user. This arrangement
provides file naming freedom
• A user can access files of other users by going to that
user’s directory through the master directory
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 18

 Copyright © 2008


Generalizations of the two-level directory structure



Generalization provides several benefits
– Directory as a file
* A directory can exist in another directory
* It leads to a directory hierarchy
* User can form groups and subgroups of files

– Generalized syntax for accessing files
* A path name permits any file in the directory hierarchy to be
accessed (subject to access privileges); e.g., ../projects/alpha



Accessing a file
– Each user has a home directory and a current directory
– A file is accessed using absolute or relative path names

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 19

 Copyright © 2008


Sample directory hierarchy

• A rectangle represents a directory, a circle represents a file
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 20
 Copyright © 2008


Directory graphs



Links
– A link provides an alternative method of naming a file
* It associates a name in a specified directory with a file that may
exist anywhere in the directory hierarchy
* It can be used to provide a shortcut to access the file

– Use of links makes a directory hierarchy into a graph
* Alternative path names exist for the same file

Chapter 7:

File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 21
 Copyright © 2008


Links

• link (~B, ~A/projects/beta, showcase) creates a link named
‘showcase’ from directory B to file ~A/projects/beta
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 22
 Copyright © 2008


Mounting of a file system



An OS may have several file systems
– Each file system has a separate directory hierarchy
– Directory hierarchy of two file systems can be combined through

mounting
– A mount operation ‘attaches’ a file system to a directory in
another file system
* Mounting is typically a privileged operation
* It has a temporary effect that lasts until an unmount operation is
performed

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 23
 Copyright © 2008


Mounting of a file system

(a) Directory hierarchies of two file systems
(b) Command mount (meeting, ~A/admin) combines them as shown
Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 24
 Copyright © 2008



Interface between the file system and IOCS



The file system and the IOCS jointly implement
operations on files
– A file system creates, deletes and protects files
* It allocates disk space to a file
* It permits a user to specify protection information

– The file system also performs opening and closing of files
* It performs path name resolution at open; it also checks whether the
user is authorized to access the file

– File operations are performed by the IOCS



The file control block (FCB) is the interface between the
file system and the IOCS

Chapter 7:
File Systems

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2ed 

Slide No: 25
 Copyright © 2008



×