OS 5TH.pptx
OS 5TH.pptx
Aditi Samadhiya
Assistant Professor, MITS Gwalior
PhD Scholar, ABV IIITM Gwalior
FILE CONCEPT
A file is referred to by its name. The following are the list of file attributes:
∙ Name: The symbolic file name is the only information kept in human-readable form.
∙ Identifier: This is a unique number that 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: It is a pointer to a device and to the location of the file on that device.
∙ Size: The current size of the file and the maximum size are included in this attribute.
∙ Protection: It is access-control information determines who can do reading, writing,
executing and so on.
∙ Time, Date and User Identification: This information kept for creation, last modification
and last use. These data can be useful for protection, security and usage monitoring.
File Operations
Information in the file is processed in order, one record after the other
record. Example: editors and compilers usually access files in
sequential order.
•Reads and writes make up the bulk of operations on a file:
∙ read_next( ) operation reads the next portion of the file and
automatically advances a file pointer, which tracks the I/O location.
∙ write_next( ) operation appends to the end of the file and advances
to the end of the newly written material.
Direct Access or Relative Access
∙ In direct access method, the file is viewed as a numbered sequence of blocks or records.
∙ There are no restrictions on the order of reading or writing for a direct-access file.
∙ Thus, we may read block 14, then read block 53 and then write block 7.
∙ 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.
∙ Databases are direct access 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.
•Example: Airline-reservation system
∙ We might store all the information about a particular flight 713 in the block identified by the flight number.
∙ The number of available seats for flight 713 is stored in block 713 of the reservation file.
∙ To store information about a larger set, such as people, we might compute a hash function
• on the people’s names to determine a block to read and search.
Indexed Access
The index is like an index in the back of a book that contains pointers to the various
blocks.
• To find a record in the file, we first search the index and then use the pointer to
access the file directly and to find the desired record.
∙ To find a record we can make a binary search of the index. This search helps us
to know exactly which block contains the desired record and access that block.
∙ This structure allows us to search a large file doing little I/O.
∙ With large files, the index file itself may become too large to be kept in memory.
∙ One solution is to create an index for the index file. The primary index file
contains pointers to secondary index files, which point to the actual data items.
DIRECTORY AND DISK STRUCTURE
• Files are stored on random-access storage devices such as Hard-disks, Optical-disks and Solid-state disks.
∙ A storage device can be used for a file system. It can be subdivided for finer-grained control.
∙ Ex: A disk can be partitioned into quarters. Each quarter can hold a separate file system.
∙ Partitioning is useful for limiting the sizes of individual file systems, putting multiple file- system types on the
same device or leaving part of the device available for other uses, such as swap space or unformatted (raw) disk
space.
∙ A file system can be created on each of these disk partitions. Any entity containing a file system is generally
known as a Volume.
∙ Volume may be a subset of a device, a whole device. Each volume can be thought of as a virtual disk.
∙ Volumes can also store multiple operating systems. Volumes allow a system to boot and run more than one
operating system.
∙ Each volume contains a file system maintains information about the files in the system.
∙ This information is kept in entries in a Device directory or Volume table of contents.
∙ The device directory (directory) records information such as name, location, size and type for all files on that
volume.
DIRECTORY AND DISK STRUCTURE
FILE-SYSTEM STRUCTURE
• File systems are maintained on Secondary Storage Disks. Two reasons for storing file systems on disk are:
∙ I/O control level consists of device drivers and interrupt handlers to transfer information between the main memory and the
disk system.
∙ Basic File System needs only to issue generic commands to the appropriate device driver to read and write physical blocks
on the disk.
∙ Each physical block is identified by its numeric disk address
∙ Example: drive 1, cylinder 73, track 2, sector 10.
∙ Basic file system layer also manages the memory buffers and caches that hold various file-system, directory and data blocks.
∙ File-Organization Module knows about files and their logical blocks, as well as physical blocks.
∙ The file-organization module includes the free-space manager, which tracks unallocated blocks and provides these blocks to
the file-organization module when requested.
∙ Logical File System manages metadata information. Metadata includes all of the file- system structure except the actual data
(or) contents of the files.
∙ Logical File System maintains file structure via File-Control Blocks. A File-Control Block (FCB) contains information
about the file, including ownership, permissions and location of the file contents. In UNIX FCB is called as an inode.
Layered Structured File System
ALLOCATION METHODS
∙ A file of five blocks might start at block 9 and continue at block 16,
then block 1, then block 10 and finally block 25.
∙ Each block contains a pointer to the next block.
∙ These pointers are not made available to the user.
∙ Thus, if each block is 512 bytes in size and a disk address (the
pointer) requires 4 bytes, then the user sees blocks of 508 bytes.
Indexed Allocation
∙ In Indexed allocation, each file has its own index block. An index block is
an array of disk- block addresses.
∙ The ith entry in the index block points to the ith block of the file.
∙ The directory contains the address of the index block.
∙ To find and read the ith block, we use the pointer in the ith index-block entry.
∙ When the file is created, all pointers in the index block are set to null.
∙ When the ith block is first written, a block is obtained from the free-space
manager and its address is put in the ith index-block entry.
∙ Indexed allocation supports direct access, without suffering from external
fragmentation, because any free block on the disk can satisfy a request
for more space.
FREE-SPACE MANAGEMENT
∙ Since disk space is limited, we need to reuse the space from deleted
files for new files.
∙ To keep track of free disk space, the system maintains a Free-Space
List.
∙ Free-space list records all free disk blocks, those not allocated to some
file or directory.
∙ To create a file, we search the free-space list for the required amount
of space and allocate that space to the new file. This space is then
removed from the free-space list.
∙ When a file is deleted, its disk space is added to the free-space list.
Storage Management
MASS-STORAGE STRUCTURE
MAGNETIC DISK
• Magnetic disks provide the bulk of secondary storage for modern computer systems.
∙ Each disk platter has a flat circular shape, like a CD.
∙ Common platter diameters range from 1.8 to 3.5 inches.
∙ The two surfaces of a platter are covered with a magnetic material.
∙ We store information by recording it magnetically on the platters.
∙ A read–write head ―fliesǁ just above each surface of every platter.
∙ The heads are attached to a Disk arm that moves all the heads as a unit.
∙ The surface of a platter is logically divided into circular Tracks.
∙ The tracks are subdivided into Sectors. Each track may contain hundreds of sectors.
∙ The set of tracks that are at one arm position makes up a Cylinder.
∙ There may be thousands of concentric cylinders in a disk drive.
∙ The storage capacity of common disk drives is measured in Giga-bytes.
∙ When the disk is in use, a drive motor spins it at high speed. Common drives spin at 5,400, 7,200,
10,000 and 15,000 RPM.
MAGNETIC DISK
SOLID-STATE DISKS (SSD)
• In the SCAN algorithm, the disk arm starts at one end of the disk and
moves toward the other end, servicing requests as it reaches each
cylinder, until it gets to the other end of the disk. At the other end, the
direction of head movement is reversed and servicing continues.
•Consider a disk queue with requests for I/O to blocks on cylinders in
the order:
• 98, 183, 37, 122, 14, 124, 65, 67
•The disk head is initially at cylinder 53.
SCAN algorithm
∙ Assuming that the disk arm is moving toward 0 and that the initial
head position is again 53 the head will next service 37 and then 14.
∙ At cylinder 0, the arm will reverse and will move toward the other
end of the disk, servicing the requests at 65, 67, 98, 122, 124 and
183.
∙ A request arrives in the queue in front of the head, it will be serviced
almost immediately.
∙ A request arriving just behind the head will have to wait until the arm
moves to the end of the disk, reverses direction and comes back.
SCAN algorithm
C-SCAN Scheduling
• Both SCAN and C-SCAN move the disk arm across the full width of
the disk, neither of these algorithms are implemented.
• In LOOK and C-LOOK scheduling, the arm goes only as far as the
final request in each direction. Then, it reverses direction
immediately, without going all the way to the end of the disk. (i.e.)
they look for a request before continuing to move in a given direction.
LOOK Scheduling