storage management€¦ · chapter 6: file-system interface ... may be numeric, alphabetic,...
TRANSCRIPT
11.1
Chapter 6
Storage Management
File-System Interface
11.2
Chapter 6: File-System Interface
File Concept
Access Methods
Disk and Directory Structure
File-System Mounting
File Sharing
Protection
11.3
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
11.4
File Concept
Computers can store information on various storage
media, such as magnetic disks, magnetic tapes, and
optical disks.
So that the computer system will be convenient to use,
the operating system provides a uniform logical view of
information storage.
The operating system abstracts from the physical
properties of its storage devices to define a logical
storage unit, the file.
Files are mapped by the operating system onto physical
devices.
These storage devices are usually nonvolatile, so the
contents are persistent through power failures and
system reboots.
11.5
File Concept (Cont.)
A file is a named collection of related information that is recorded on secondary storage.
From a user's perspective, a file is the smallest allotment of logical secondary storage; that
is, data cannot be written to secondary storage unless they are within a file.
Commonly, files represent programs (both source and object forms) and data. Data files
may be numeric, alphabetic, alphanumeric, or binary. Files may be free form, such as text
files, or may be formatted rigidly.
In general, a file is a sequence of bits, bytes, lines, or records, the meaning of which is
defined by the file's creator and user. The concept of a file is thus extremely general.
Many different types of information may be stored in a file—source programs, object
programs, executable programs, numeric data, text, payroll records, graphic images, sound
recordings, and so on.
A file has a certain defined structure, which depends on its type:
o A text file is a sequence of characters organized into lines (and possibly pages).
o A source file is a sequence of subroutines and functions, each of which is further organized
as declarations followed by executable statements.
o An object file is a sequence of bytes organized into blocks understandable by the system's
linker.
o An executable file is a series of code sections that the loader can bring into memory and
execute
11.6
File Attributes
A file's attributes vary from one operating system to another but
typically consist of these
o Name – only information kept in human-readable form
o Identifier – unique tag (number) identifies file within file system
o Type – needed for systems that support different types
o Location – pointer to file location on device
o Size – current file size
o Protection – controls who can do reading, writing, executing
o 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
11.7
File info Window on Mac OS X
11.8
File Operations
To define a file properly, we need to consider the operations that can be
performed on files. The operating system can provide system calls to create,
write, read, reposition, delete, and truncate files.
Creating a file. Two steps are necessary to create a file. First, space in the
file system must be found for the file. Second, an entry for the new file must be
made in the directory.
Writing a file. To write a file, we make a system call specifying both the name
of the file and the information to be written to the file. Given the name of the file,
the system searches the directory to find the file's location. The system must
keep a write pointer to the location in the file where the next write is to take
place. The write pointer must be updated whenever a write occurs.
Repositioning within a file. The directory is searched for the appropriate
entry, and the current-file-position pointer is repositioned to a given value.
Repositioning within a file need not involve any actual I/O. This file operation is
also known as a file seek.
11.9
File Operations (Cont.)
Reading a file. To read from a file, we use a system call that specifies the
name of the file and where (in memory) the next block of the file should be put.
Again, the directory is searched for the associated entry, and the system
needs to keep a read pointer to the location in the file where the next read is to
take place. Once the read has taken place, the read pointer is updated.
Because a process is usually either reading from or writing to a file, the current
operation location can be kept as a per-process currentfile- position pointer.
Both the read and write operations use this same pointer, saving space and
reducing system complexity.
Deleting a file. To delete a file, we search the directory for the named file.
Having found the associated directory entry, we release all file space, so that it
can be reused bv other files, and erase the directory entry.
Truncating a file. The user may want to erase the contents of a file but keep
its attributes. Rather than forcing the user to delete the file and then recreate it,
this function allows all attributes to remain unchanged—except for file length—
but lets the tile be reset to length zero and its file space released.
11.10
File Types – Name, Extension
11.11
Access Methods
Files store information. When it is used, this information must be accessed and read into computer memory.
The information in the file can be accessed in several ways. Some systems provide only one access method for files. Other systems, such as those of IBM, support many access methods, and choosing the right one for a particular application is a major design problem. o Sequential Access o Direct Access
11.12
Sequential Access
The simplest access method is sequential access.
Information in the file is processed in order, one record after the other.
This mode of access is by far the most common; for example, editors and
compilers usually access files in this fashion.
Reads and writes make up the bulk of the operations on a file.
A read operation—read next—reads the next portion of the file and
automatically advances a file pointer, which tracks the I/O location.
The write operation—write next—appends to the end of the file and
advances to the end of the newly written material (the new end of file).
Such a file can be reset to the beginning; and on some systems, a program
may be able to skip forward or backward n records for some integer n—
perhaps only for n = 1.
Sequential access, which is depicted in the following figure, is based on a
tape model of a file and works as well on sequential-access devices as it
does on random-access ones.
11.13
Sequential-access File
11.14
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.
The direct-access method is based on a disk model of a file, since disks allow
random access to any file block.
For direct access, the file is viewed as a numbered sequence of blocks or records.
Thus, we may read block 14, then read block 53, and then write block 7.
There are no restrictions on the order of reading or writing for a direct-access file.
Direct-access files are of great use for immediate access to large amounts of
information.
Databases are often of this type. When a query concerning a particular subject
arrives, we compute which block contains the answer and then read that block
directly to provide the desired information.
The file operations must be modified to include the block number as a parameter.
Thus, we have read n, where n is the block number, rather than read next, and
write n rather than write next. An alternative approach is to retain read next and write next, as with sequential
access, and to add an operation position file to n, where n is the block number.
Then, to effect a read n, we would, position to n and then read next.
11.15
Direct Access (Cont.)
The block number provided by the user to the operating system is
normally a relative block number.
A relative block number is an index relative to the beginning of the
file.
Thus, the first relative block of the file is 0, the next is 1, and so on,
even though the actual absolute disk address of the block may be
14703 for the first block and 3192 for the second.
The use of relative block numbers allows the operating system to
decide where the file should be placed and helps to prevent the user
from accessing portions of the file system that may not be part of her
file.
Some systems start their relative block numbers at 0; others start at 1.
11.16
Access Methods
Sequential Access read next
write next
reset
no read after last write
(rewrite)
Direct Access – file is fixed length logical records read n
write n
position to n
read next
write next
rewrite n
n = relative block number
Relative block numbers allow OS to decide where file should be placed
11.17
Simulation of Sequential Access on Direct-access File
11.18
Chapter 6
File-System Interface
(Cont.)
Directories
11.19
Chapter 11: File-System Interface
Disk and Directory Structure
Objectives
o Explain some basic features of storage structure. o Explore the topic of directory structure.
11.20
Introduction
The file systems of computers, then, can be extensive. Some systems store
millions of files on terabytes of disk.
To manage all these data, we need to organize them. This organization
involves the use of directories.
11.21
Disk Structure
Disk can be subdivided into partitions
Disk or partition can be used raw (without a file
system, or formatted with a file system)
Partitions also known as minidisks, slices
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
11.22
A Typical File-system Organization
11.23
Directory Structure
A collection of nodes containing information about all files
F 1 F 2 F 3
F 4
F n
Directory
Files
Both the directory structure and the files reside on disk
11.24
Operations Performed on Directory
Search for a file: We need to be able to search a directory structure to find
the entry for a particular file. Since files have symbolic names and similar
names may indicate a relationship between files, we may want to be able to
find all files whose names match a particular pattern.
Create a file: New files need to be created and added to the directory
Delete a file from a directory: When a file is no longer needed, we want to
be able to remove it from the directory.
List a directory: We need to be able to list the files in a directory and the contents of the directory entry for each file in the list.
Rename a file: Because the name of a file represents its contents to its users, we must be able to change the name when the contents or use of the file changes. Renaming a file may also allow its position within the directory structure to be changed.
Traverse the file system: We may wish to access every directory and every
file within a directory structure.
11.25
Directory Organization
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, …)
The directory is organized logically to obtain
11.26
Single-Level Directory
A single directory for all users
Naming problem
Grouping problem
11.27
Two-Level Directory
Separate directory for each user
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
11.28
Tree-Structured Directories
11.29
Tree-Structured Directories (Cont.)
Efficient searching
Grouping Capability
Current directory (working directory)
cd /spell/mail/prog
type list
11.30
Tree-Structured Directories (Cont)
Absolute or relative path name
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>
Example: if in current directory /mail
mkdir count
Deleting “mail” deleting the entire subtree rooted by “mail”
11.31
Acyclic-Graph Directories
Have shared subdirectories and files
11.32
Acyclic-Graph Directories (Cont.)
Two different names (aliasing)
If dict deletes list dangling pointer
Solutions:
Backpointers, so we can delete all pointers
Variable size records a problem
Backpointers using a daisy chain organization
Entry-hold-count solution
New directory entry type
Link – another name (pointer) to an existing file
Resolve the link – follow pointer to locate the file
11.33
General Graph Directory
11.34
Chapter 6
File-System Interface
Protection
Operating System Concepts – 9th Edition
11.35
Protection
File owner/creator should be able to control:
what can be done
by whom
Types of access
Read
Write
Execute
Append
Delete
List
11.36
Access Lists and Groups
Mode of access: read, write, execute
Three classes of users on Unix / Linux RWX
a) owner access 7 1 1 1 RWX
b) group access 6 1 1 0
RWX
c) public access 1 0 0 1
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.
Attach a group to a file chgrp G game
11.37
Windows 7 Access-Control List Management
11.38
A Sample UNIX Directory Listing