Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Designed and Presented by
Dr. Ayman Elshenawy Elsefy
Dept. of Systems & Computer Eng..
AL-AZHAR University
Website : eaymanelshenawy.wordpress.com
Email : [email protected]
Reference
Operating System Concepts, ABRAHAM SILBERSCHATZ
Operating Systems
1. Mass Storage Structure
2. File System Interface
3. I/O Systems
Part 4Storage Management
1. Mass Storage System
A file is logically organised as:
- Stream of bytes
- Set of records
Logical organization of files
- A record is a collection of data that belongs together, e.g. All the data about
an individual person.
- A data item is an individual field of a record and usually contains one piece of
data, e.g. a date, first name, age.
- These fields are collected together to form records.
Primary storage and Secondary storagePrimary Storage is …
- Limited, Volatile , Expensive
- Fast (accessed directly from the CPU)
- Access time in nanoseconds.
Secondary Storage is …
- Extendible , Persistent, Cheap
- Slow (data must be copied to main memory)
- Access time in msec.
Direct Access Storage Devices
(DASDs)
- Offer high storage capacity and low
cost
- Store data as magnetized areas on
magnetic platters surfaces
- Examples:
- Magnetic Disks , Hard Disks , Optical
Disks
- CD-ROM, DVD-ROM
Serial Devices
- Magnetic Tapes
Secondary storage Types
Magnetic Disk Structure
• Magnetic disks support direct access
• It consisted of :
• Disk blocks
• Tracks
• Platters
• Cylinder
• Sectors
• Disk heads
• Disk Controller
• Seek Time and Rotational delay
• How to calculate disk capacity?
• Drive capacity = number of cylinders × cylinder capacity
• Number of cylinders = number of tracks in a surface
• Cylinder capacity = number of surfaces × track capacity
• Track capacity = number of sector per track × bytes per sector
• How many cylinders to store a file with 20,000 fixed length records of 256bytes each on a disk with 512 bytes per sector, 40 sectors per disk and 11tracks per cylinder?
• Answer:
- The file is 20,000 * 256 = 5,120,000 bytes
- 5,120,000 / 512 = 10,000 sectors
- 10,000 / 40 = 250 tracks
- 250 / 11 = 22.72 cylinders
- If 22.72 physically contiguous cylinders are not available then the file will have
to be spread out over the disk (fragmentation)
• Data can be organized on disk in two different ways:
• Sectors
• User defined blocks.
Organization of data on Disks
1. Physically Placement of sectors
Organizing Data on Disks as Sectors
A. Adjacent Sectors
• fixed size segments of a track used to hold a file
B. Interleaving sectors:
• leave an interval of several fixed sectors between adjacent logical sectors.
• Disadvantage
• After reading the data it takes time to transfer the data
• the start of the next sector will be lost ( able to read only one sector / revolution)
2. Clusters (fixed number of contiguous sectors)
Organizing Data on Disks as Sectors
• OS File manager Used it to improve performance.
• The file is viewed as a set of clusters of sectors.
• All sectors in clusters can be read without requiring additional seeks.
• The file manager maps the logical sectors to the physical clusters they belong to by a FAT ( File allocation table)
• FAT: contains a list of all the clusters in a file. Each cluster entry in the FAT giving the physical location of the cluster.
3. Extent
Organizing Data on Disks as Sectors
• The file consists of contiguous clusters
• The file consists of one extent (all of its sectors, tracks, cylinders form one contiguous whole.
• The whole file can be accessed with minimum amount of seeking.
• If there is not enough contiguous space available.
• The file is divided on one or more non-contiguous parts, each part is an extent.
Internal Fragmentation of a disk
• Example: if the size of a sector = 512 bytes and the size of all records in file is 300 bytes. There are two ways:
Organizing Data on Disks as Blocks
• Disk tracks are divided into user defined blocks with variable size.
• Blocks may be fixed length or variable length.
• Each block is usually accompanied by one or more subblock containing extra information about the data blocks.
• Count subblock: counting the number bytes in the accompanied data block.
• Key subblock: containing the key for the last record in the data block.
Overhead
• Sector organization
Sector address at the beginning of each sector.
Sector is usable or defective.
• Block organization
Sub blocks and inter block gaps
Size and number of blocks.
Storage Area Network
• Common in large storage environments
• Multiple hosts attached to multiple storage arrays – flexible
• SAN is one or more storage arrays Connected to one or more Fiber Channel switches
• Hosts also attach to the switches
• Easy to add or remove storage, add new host and allocate it storage
Disk Scheduling
• The operating system is responsible for using hardware efficiently — for the disk drives, this means having a fast access time and disk bandwidth
• Minimize seek time ( Seek time seek distance)
• Maximize Disk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer
1- First Come First Served
Illustration shows total head movement of 640 cylinders
2- Shortest Seek Time First (SSTF)
Disk Scheduling (Cont.)
• Shortest Seek Time First selects the request
with the minimum seek time from the
current head position
• Like SJF scheduling; may cause starvation
of some requests• Illustration shows total head movement of 236 cylinders
3- SCAN (elevator algorithm)
• The disk arm starts at one end of the disk,and moves toward the other end, servicingrequests until it gets to the other end of thedisk, where the head movement is reversedand servicing continues.
• Illustration shows total head movement of208 cylinders
Disk Scheduling (Cont.)
4- CCAN
• The head moves from one end of the diskto the other, servicing requests as it goes
• When it reaches the other end, however, itimmediately returns to the beginning of thedisk, without servicing any requests on thereturn trip
• LOOK a version of SCAN, C-LOOK a version of C-SCAN• Arm only goes as far as the last request in each direction, then reverses
direction immediately, without first going all the way to the end of the disk• Total number of cylinders?
5- C-LOOK
Disk Scheduling (Cont.)
2. File System Interface
File Concept
• Computers can store information on various non-volatile storage media withdifferent physical properties, such as:
Magnetic disks and Magnetic tapes
Optical disks and CD-ROMs & DVD’s.
• The OS provides a uniform logical view (a logical storage unit) that used for allstorage media.
• A file is a named collection of related information that is recorded on secondarystorage (a file is a sequence of bits, bytes, lines, or records).
• Files represent:
programs (both source and object forms)
Data.
• Data files may be:
Numeric
Alphabetic,
Alphanumeric,
Binary.
File Concept
• The information in a file is defined by its creator.
• Many different types of information may be stored in a file:
Source programs: sequence of subroutines, functions, declaration and exec statements.
object programs: a sequence of bytes organized into blocks understandable by thesystem’s linker.
executable programs, a series of code sections that the loader can bring into memory andexecute.
numeric data,
Text - a sequence of characters organized into lines (and possibly pages).
payroll records,
graphic images,
sound recordings, and so on.
• A file has a certain defined structure, which depends on its type.
• File Structure may be:
Free form, such as text files
formatted rigidly.
File Concept
Network File System (NAS)Single OS File Systems
File Attribute
• A file’s attributes vary from one operating system to another but typically consist of these:
• Name – 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 – 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
File Operations
• File is an abstract data type
Create file
Space in the file system must be found for the.
An entry for the new file must be made in the directory.
Write to a file
Send both the file name and the information to be written to the file to a system call.
Searches the directory to find the file’s location.
Update a write pointer to the location in the file where the next write is to take place.
Read
Send both the file name and next block to be read to the file to a system call.
Searches the directory to find the file’s location.
Update a read pointer to the location in the file where the next read is to take place.
Current Position Pointer: keep the current operation location for read and write.
Reposition within file (File Seek)
The directory is searched for the appropriate entry
Current-file-position pointer is repositioned to a given value
File Operations Delete
Search the directory for the named file and release all file space, so
Erase the directory entry.
Truncate a file
erase the contents of a file but keep its attributes.
The file be reset to length zero and its file space released.
Open(Fi) –
Search the directory structure on disk for entry Fi,
move the content of entry to memory
Close (Fi) –
move the content of entry Fi in memory to directory structure on disk.
Other common operations:
Appending new information to the end of an existing file.
Renaming an existing file.
Create a copy of a file to another location (I/O device, such as a printer or a display),by creating a new file and then reading from the old and writing to the new. We alsowant to have operations that allow a user to
Get and set file attributes. For example, the file’s length, the file’s owner.
Enhancing file operations
• Most of the file operations involve searching the directory for the entry
associated with the named file.
• To avoid this:
open-file table
Contains information about all open files, Any file operation can search for the file inthis table.
After closing the file the entry of this file is deleted from the table.
per-process table
tracks all files that a process has open
current file pointer for each file , access rights to the file and accounting information.
system-wide table
contains process-independent information
the location of the file on disk, access dates, and file size
File pointer: pointer to last read/write location, per process that has the file open
File-open count: counter of number of times a file is open
Disk location of the file: cache of data access information
Access rights: per-process access mode information
File Types – Name, Extension
A Typical File Control Block
Access methods
Serial Access
Each record is stored, one after the other, with no logical order.
It is the simplest form of file organization.
Easy to implement on magnetic tape
Suitable for batch search not suitable for online access.
Very Slow
Sequential Access
Records are kept in some pre-defined order
Such a method is reasonable for tape
rapid access to sets of the nearest record.
Suited to magnetic tape
Addition and deletion of records must preserve the order.
Random Access or direct access
Records are accessed directly
.Suitable for magnetic disks
Access methods
Indexed Sequential
like an index in the back of abook, contains pointers to thevarious blocks. To
find a record in the file, we firstsearch the index and then use thepointer to
access the file directly and to findthe desired record.
Allows records to be accesseddirectly or sequentially.
Direct access ability providesvastly superior (average) accesstimes.
The fact that several tables mustbe stored for the index makes for aconsiderable storage overhead.
• Directories maintain information about files:
• For a large number of files, may want a directory structure - directories under
directories.
Directory Structure
• Both the directory structure and the files reside on disk
Directory Operations
• List directory contents
• Search for a file
• Create a file
• Delete a file
• Rename a file
• Traverse the file system
Directory Structure
• Single-Level DirectoryA single directory for all usersCalled the root directory
• Two-Level Directory
• Separate directory for each user
• Introduces the notion of a path name
• Can have the same file name for
different user
• Efficient searching
• Tree Structured Directory
• Efficient searchingGrouping CapabilityCurrent directory (working directory)
• cd /spell/mail/prog
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 Lists and Groups
• Mode of access: read, write, execute
• Three classes of users
RWX
a) owner access 7 1 1 1RWX
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.
owner group public
chmod 761 game
Attach a group to a file
chgrp G game
Windows 7 Access-Control List Management
3. I/O systems
?????
A Typical PC Bus Structure
Device I/O Port Locations on PCs (partial)