0% found this document useful (0 votes)
3 views

OS 5TH.pptx

The document provides an overview of file systems, detailing file concepts, attributes, operations, access methods, and storage management. It explains different file allocation methods, free-space management, and mass-storage structures including magnetic disks, solid-state disks, and magnetic tapes. Additionally, it covers disk scheduling algorithms such as FCFS and SSTF, highlighting their operational mechanics and efficiency.

Uploaded by

sakshamdubey022
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)
3 views

OS 5TH.pptx

The document provides an overview of file systems, detailing file concepts, attributes, operations, access methods, and storage management. It explains different file allocation methods, free-space management, and mass-storage structures including magnetic disks, solid-state disks, and magnetic tapes. Additionally, it covers disk scheduling algorithms such as FCFS and SSTF, highlighting their operational mechanics and efficiency.

Uploaded by

sakshamdubey022
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

File System Interface

Aditi Samadhiya
Assistant Professor, MITS Gwalior
PhD Scholar, ABV IIITM Gwalior
FILE CONCEPT

A file is a named collection of related information that is recorded on secondary storage.


∙ A file is the smallest allotment of logical secondary storage (i.e.) data cannot be written to
secondary storage unless they are within a file.
∙ Files represent programs and data. Data files may be numeric, alphanumeric or binary.
∙ The information in a file is defined by its creator.
∙ Different types of information may be stored in a file such as source or executable
programs, numeric or text data, photos, music, video and so on.
A file structure depends on its type:
∙ Text file is a sequence of characters organized into lines.
∙ Source file is a sequence of functions, each of which is further organized as declarations
followed by executable statements.
∙ Executable file is a series of code sections that the loader can bring into memory and
execute.
File Attributes

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

There are 6 basic operations performed on file and corresponding


System call are:
1. Creating a file: create( ) system call is used to create a file. To create
a file Operating system checks whether there is enough space in the
system. If yes, then a new entry will be made in the directory
structure.
2. 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.
File Operations
3. Deleting a file: delete( ) system call is used to delete a file. To delete a file, we
search the directory for the named file. If we found the associated directory
entry, we release all file space and erase the directory entry.
4. Truncating a file. The user erases all the contents of a file but keep its attributes.
The length of the file will be reset to zero.
5. Writing a file. write( ) system call is used to write a file. It specifies both the
name of the file and the information to be written to the file. The system
searches the filename in the directory to find the file’s location.
6. Reading a file. read( ) system call is used to read from a file. It specifies the
name of the file and where the next block of the file should be put. The directory
is searched for the associated entry.
ACCESS METHODS

Files store information. When a file is used, this information must be


accessed and read into computer memory. The information in the file
can be accessed in several ways:
1. Sequential Access
2. Direct Access
3. Indexed Access
Sequential Access

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

• Three major methods of allocating disk space are in wide use:


1. Contiguous Allocation
2. Linked Allocation
3. Indexed Allocation
Contiguous Allocation
•Contiguous allocation requires that each file occupy a set of contiguous blocks on the disk.
∙ Disk addresses define a linear ordering on the disk. With this ordering, assuming that
only one job is accessing the disk, accessing block b + 1 after block b normally requires
no head movement.
∙ When head movement is needed the head need only move from one track to the next.
∙ Contiguous allocation of a file is defined by the disk address and length (in block units)
of the first block.
∙ If the file is n blocks long and starts at location b, then it occupies blocks b, b + 1, b + 2,
• ..., b + n − 1.
∙ The directory entry for each file indicates the address of the starting block and the length
of the area allocated for this file.
Linked Allocation

∙ 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)

∙ SSD is nonvolatile memory that is used like a hard drive.


∙ SSDs are more reliable because they have no moving parts.
∙ SSDs are faster because they have no seek time or latency.
∙ SSDs can be much faster than magnetic disk drives.
∙ By comparing Hard disk, SSDs consumes less power but SSDs are
more expensive per megabyte, have less capacity and may have
shorter life spans than hard disks.
MAGNETIC TAPES

∙ Magnetic tape was used as an early secondary-storage medium.


∙ Tapes relatively permanent and can hold large quantities of data.
∙ Magnetic Tape access time is slow compared with that of main memory and
magnetic disk. Random access to magnetic tape is about a thousand times slower
than random access to magnetic disk, so tapes are not very useful for secondary
storage.
∙ Tapes are used mainly for backup, for storage of infrequently used information and
as a medium for transferring information from one system to another system.
∙ A tape is kept in a spool and it is wound or rewound past a read–write head.
∙ Moving to the correct spot on a tape can take minutes, but once positioned, tape
drives can write data at speeds comparable to disk drives.
∙ Tape capacity is up to several terabytes.
DISK STRUCTURE
• Magnetic disk drives are addressed as large one-dimensional arrays of logical blocks.
∙ The Logical block is the smallest unit of transfer.
∙ Size of the Logical block is 512 Bytes or 1024 Bytes.
∙ The one-dimensional array of logical blocks is mapped onto the sectors of the disk sequentially. Sector 0 is the
first sector of the first track on the outermost cylinder.
∙ The mapping proceeds in order through that track, then through the rest of the tracks in that cylinder and then
through the rest of the cylinders from outermost to innermost.
∙ By using this mapping, we can—at least in theory—convert a logical block number into an old-style disk
address that consists of a cylinder number, a track number within that cylinder and a sector number within that
track.
∙ The track which is far from the center of the disk, the length of the track is more and this track can hold more
sector than the track that is nearer to the center of disk,
∙ Tracks in the outermost zone typically hold 40 percent more sectors than do tracks in the innermost zone.
∙ The drive increases its rotation speed as the head moves from the outer to the inner tracks to keep the same
rate of data moving under the head.
∙ This method is used in CD-ROM and DVD-ROM drives.
DISK SCHEDULING ALGORITHMS

•Different Disk Scheduling algorithms are:


1. FCFS Scheduling
2. SSTF Scheduling
3. SCAN Scheduling
4. C- SCAN Scheduling
5. LOOK Scheduling
First-Come-First-Serve Algorithm

•FCFS does not provide the fastest service.


•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. By using FCFS algorithm:
First-Come-First-Serve Algorithm
First-Come-First-Serve Algorithm
∙ It will first move from 53 to 98 the head movement of 45 cylinders
∙ Then 98 to 183 the head movement of 85 cylinders
∙ Then 183 to 37 the head movement of 146 cylinders
∙ Then 37 to 122 the head movement of 85 cylinders
∙ Then 122 to 14 the head movement of 108 cylinders
∙ Then 14 to 124 the head movement of 110 cylinders
∙ Then 124 to 65 the head movement of 59 cylinders
∙ Then 65 to 67 the head movement of 2 cylinders
∙ The total head movement of 640 cylinders.
SSTF Scheduling

•Shortest-Seek-Time-First (SSTF) algorithm service all the requests


close to the current head position before moving the head far away to
service other requests.
•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.
SSTF Scheduling
•Closest request to the initial head position 53 is at cylinder 65 takes 12
cylinders movements.
∙ Once we are at cylinder 65, the next closest request is at cylinder 67 (2
moves).
∙ From 67, the request at cylinder 37 is closer than the one at 98, so 37
is served next.
∙ Similarly we service the request at cylinder 14, then 98, 122, 124 and
finally 183.
∙ This scheduling method results in a total head movement of only 236
cylinders.
SSTF Scheduling
SCAN algorithm

• 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

Circular SCAN (C-SCAN) scheduling is a variant of SCAN designed to


provide a more uniform wait time.
•Like SCAN, C-SCAN moves the head from one end of the disk to the other,
servicing requests along the way.
•When the head reaches the other end, it immediately returns to the beginning
of the disk without servicing any requests on the return trip.
•The C-SCAN scheduling algorithm essentially treats the cylinders as a
circular list that wraps around from the final cylinder to the first one.
•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.
C-SCAN Scheduling
LOOK 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

You might also like