0% found this document useful (0 votes)
25 views12 pages

Files (5 Unit)

operating system

Uploaded by

mbkmail2
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)
25 views12 pages

Files (5 Unit)

operating system

Uploaded by

mbkmail2
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/ 12

File-System Interface ( 5th UNIT)

File Concept: Computers can store information on different storage media, such as magnetic
disks, magnetic tapes and optical disks. Files are mapped, by the operating system on to physical
devices. These storage devices are usually nonvolatile.
a) File Structure
A file is a named collection of related information that is recorded on secondary storage.
• File represent programs ( both source and object forms)and data.
• A file has a certain defined structure according to its type.
1) Text file: It is a sequence of characters organized into lines.
2) Source file: It is a sequence of subroutines and functions.
3) Executable file: It is a series of code sections that the loader can bring into memory
and execute.
b) File Attributes
A file is named, for the convenience of its human users , and is referred by its name.
• Name –The symbolic file name is the only information kept in human-readable form.
• Type – This information is needed for systems that support different types.
• Location –A pointer to file location on device.
• Size – The current file size.
• Protection – It controls who can do reading, writing, executing.
• Time, date, and user identification –This information may be kept for creation, last
modification , last use, protection, security, and usage monitoring.
• Information about files are kept in the directory structure, which is maintained on the
disk.
c) File Operations
• A file is an abstract data type.
• The Operating system provides System calls to Create:, Write, read, reposition ,delete,
and truncate files.
• Create 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 I the directory,
• Writing a file: To Write a file, we make a System call specifying both the name of a file
and the information to be written to the file. The system searches the directory to find the
location of the file
• Reading a file: The directory is searched for the associated directory entry, and the
system needs to keep a read pointer to the location in the file where the next read to take
place, the read pointer is updated
• Reposition within file :Repositioning with in a file does not need to involve any actual
I/O. This file operation is also called as file seek .
• Deleting a file:To delete a file, we search the directory for the named file. We release all
file space and erase the directory entry.
• Truncating a file: There are occasions when the user wants the attributes of a file to
remain the same, but wants to erase the contents of the file.
• File pointer: The system must track the last read/write location as a current file position
pointer. This pointer is unique to each process operating on the file.
• File open count: This count tracks the number of open and closes, and reaches zero on
the last close.

II BSc OS: UNIT V Page 1


d) File Types
File types is to be include the type as part of the file name. The name is split into two parts
1) Name
2) Extension

Directory Structure
Some systems store thousand s of files and hundred s of gigabytes of disk. To manage all these
data, we need to organize them. This organization is usually done in two parts
1) The file system is broken into partitions, also known as mini disks. Each disk on a system
contains at least one partition, which is low level structure in which files and directories
reside.
2) Each partition contains information about files with in it. This information is kept in
entries in a device directory. This information such as name, location, size and type for
all files on that partition shows in the figure.
A Typical File-system Organization

Operations Performed on Directory


1. Search for a file:To search a directory structure to find the entry of a particular file
2. Create a file: New files need to be created and added to the directory.
3. Delete a file: When a file is no longer needed, we want to remove it from the directory
4. List a directory: List the files in a directory and the contents of the directory entry for
each file in the list.
5. Rename a file: The name of the file represents its contents to its users, the name must be
changeable when the contents or use of the file changes
6. Traverse the file system: It is useful to be able to access every directory and every file
with in a directory structure.
Organize a directory (logically) based on the following criteria
1. Efficiency – locating a file quickly
2. Naming – convenient to users

II BSc OS: UNIT V Page 2


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, …)

Four Possible Approaches


1. Single-level Directory
2. Two-level Directory
3. Tree-structured Directories
4. Acyclic Graph Directories
1) Single-Level Directory
All files are contained in the same directory, which is easy to support and understand.
All files are in the same directory, they must have unique names. If we have two users who
call their data file test then the unique name rule is violated.
A single directory maintained for all users
Advantages
Efficiency
Disadvantages
Naming - collisions
Grouping – not possible

2) Two-Level Directory
The major disadvantage to a single directory is the confusion of file names between different
users. The standard solution is to create separate directory for each user.
➢ In the two – level Directory structure, each user has her own user file directory
(UFD) .
➢ Each UFD has a similar structure, but lists only the files of a single user.
➢ When a user jobs starts or a user login, the system’s master file directory
searched.
➢ When a user refers to a particular file, only his own UFD is searched. Thus
different users may have files with the same name, as long as all the file names
within each UFD are unique.
Advantages
Efficient searching
Naming - same file name in a different directory; path name
Disadvantages
Naming - collisions
Grouping capability – not possible except by user

II BSc OS: UNIT V Page 3


3) Tree-Structured Directories
• Allows users to create their own sub directories and to organize the files
accordingly.
• A directory contains a set of files or subdirectories.
• One bit in each directory entry defines the entry as a file(0) or a subdirectory(1).
• Special system calls are used to create and delete directories.
Eg: MS- DOS system, for instance, is structured a tree.

➢ The tree has a root directory.


➢ Every file in the system has a unique path name.
➢ A path name is the path of the root.
➢ Each user has a current directory.
➢ Path names can be of two types 1) Absolute path 2) Relative path
1) Absolute path: This path name begins at the root and follows a path down to the
specified file
2) Relative path: This path name defines a path from the current directory
Eg: The current directory is root / spell / mail then the relative path name ptr / first refers
to the same file . The absolute path name root / spell / mail / prt / first .
Advantages
Efficient searching – current working directory
Naming - same file name in a different directory
Grouping capability
Disadvantages
Structural complexity
4) Acyclic -Graph Directories
Consider two programs who are working on a joint project. The files associated with that
project can be stored in a sub directory. The common subdirectory should be shared, with

II BSc OS: UNIT V Page 4


a shared file, there is only one actual file, so any changes made by one person would be
immediately visible to the other. This form of sharing is particularly important for shared
subdirectories.
➢ An Acyclic graph allows directories to have shared subdirectories and files.
➢ The same file or subdirectory may be in two different directories.
➢ An acyclic graph is a natural generalization of the tree structured directory
scheme.

1) Same advantages as tree-structured directory


In addition, the same file or directory may have a reference that appears in two or
more directories
2) Disadvantage is that its structure is more complex
The same file or directory may be referred to by many names
Need to be cautious of dangling pointers when files are deleted
3) Solutions to deletion
Just delete the link
Preserve the file until all links (i.e., references) are deleted
4) This requires a new directory entry type called a link
Keep a count of the number of references
5) General Graph Directory
When we add links to an existing tree structured directory, the tree structure is destroyed,
resulting in a simple graph structure.

• How do we guarantee no cycles?


– Allow only links to file not subdirectories.
– Garbage collection.

II BSc OS: UNIT V Page 5


– Every time a new link is added use a cycle detection
algorithm to determine whether it is OK.

Allocation Methods
Many files will be stored on the same disk. The main problem is how to allocate space to these
files so that the disk space is utilized effectively and files can be accessed quickly.
An allocation method refers to how disk blocks are allocated for files:
1. Contiguous allocation
2. Linked allocation
3. Indexed allocation
1. Contiguous Allocation
➢ Each file occupies a set of contiguous blocks on the disk.
➢ Disk addresses define a linear ordering on the disk.
➢ Simple – only starting location (block #) and length (number of blocks) are
required.
Advantages:
Accessing the file that has been allocated contiguously is easy
Random access
Disadvantages:
➢ One difficulty with contiguous allocation is finding space for a new file
➢ The contiguous disk space allocation problem can be seen to be a
particular application of the general dynamical storage allocation
problem
➢ External fragmentation problem
➢ Wasteful of space (dynamic storage-allocation problem)
➢ Files cannot grow
Contiguous Allocation of Disk Space

2.Linked Allocation
Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk.

The directory contains a pointer to the first and last blocks of the file.
For example: A file of five blocks might start at block 9, continue at bock 16, then block 1, block
10, and finally block 25 as shown in figure. Each block contains a pointer to the next block. Thus

II BSc OS: UNIT V Page 6


if each block is 512 bytes and a disk address requires 4 bytes, then the user sees blocks of 508
bytes.
Advantages: There is no external fragmentation with liked allocation, and any free block on the
free space list can be used to satisfy a request
1) Simple – need only starting address
2) Free-space management system – no waste of space
3) No random access
Disadvantages:
➢ It can be used effectively for only sequential access file.
➢ Linked allocation is space required for the pointers. If a pointer requires 4 bytes out of a
512 byte block, then 0.78 percent of the disk is being used for pointers, rather than for
information.
➢ The usual solution to this problem is to collect blocks into multiples called “clusters”
rather than blocks. The cost of this approach is an increase “internal fragmentation”.
➢ Reliability: Since the files are linked together by pointers ,if a pointer were lost or
damaged.

Linked Allocation of disk space

An important variation on the linked allocation method is the use of a file allocation method
(FAT): A file consists of a disk blocks 217, 618 and 339.
File-Allocation Table

3.Indexed Allocation
➢ Indexed allocation solves this problem by Brings all pointers together into the index
block.

II BSc OS: UNIT V Page 7


➢ Each file has its own index block, which is an array of disk block addresses. The i th entry
in the index block points to the ith block of the file.
➢ The directory contains the address of the index block.
➢ When the file is created all pointers in the index block are set to nil(-1).
➢ Index allocation supports direct access, without suffering from external fragmentation.
➢ Index allocation does suffer from wasted space.
Example of Indexed Allocation

Device Management
Device management is responsible for managing all the hardware devices of the computer
system.
• It is the responsibility of the operating system to keep track of the status of all the devices
in the computer system.
• The status of any computing devices, internal or external may be either free or busy.
• If a device requested by a process is free at a specific instant of time, the operating
system allocates it to the process.
• An operating system manages the devices in a computer system with the help of device
controllers and device drivers. Each device in the computer system is equipped with the
help of device controller.
• For example, the various devices controllers in a computer system may be disk controller,
printer controller, tape-drive controller and memory controller. All these devices
controllers are connected with each other through a system bus.
• The device controllers are actually the hardware components that contains some buffers
registers to store the data temporarily.
Buffer:The buffer is an area in the main memory used to store or hold the data temporarily.
In other words, buffer temporarily stores data transmitted from one place to another,either
between two devices or an application. The act of storing data temporarily in the buffer is called
buffering.
Pipes: We can treat the set of message buffers as a ``traditional bounded buffer'' that
blocks the sending process when there are no more buffers available. That is exactly the kind of
message passing supported by Unix pipes. Pipes also allow the output of one process to become
the input of another.
• A pipe is like a file opened for reading and writing. Pipes are constructed by the
service call pipe, which opens a new pipe and returns two descriptors for it, one
for reading and another for writing.
• Reading a pipe advances the read buffer, and writing it advances the write buffer.
Disk Scheduling

II BSc OS: UNIT V Page 8


• The operating system is responsible for using hardware efficiently — for the disk drives,
this means having a fast access time and disk bandwidth.
• Access time has two major components
o Seek time is the time for the disk are to move the heads to the cylinder containing
the desired sector.
o Rotational latency is the additional time waiting for the disk to rotate the desired
sector to the disk head.
• Minimize seek time
• Seek time  seek distance
• 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) FCFS
The simplest form of disk scheduling is first come first served.
Consider a disk queue with requests for I/O to blocks on cylinders
98,183,37,122,14,124,65,67
• Illustration shows total head movement of 640 cylinders.

2) SSTF
• The shortest seek time first(SSTF) algorithm.
• Selects the request with the minimum seek time from the current head position.
• SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests.
• Illustration shows total head movement of 236 cylinders.

II BSc OS: UNIT V Page 9


3) SCAN
• The disk arm starts at one end of the disk, and moves toward the other end, servicing
requests until it gets to the other end of the disk, where the head movement is reversed
and servicing continues.
• Sometimes called the elevator algorithm. Since the disk arm behaves like an elevator in a
building, first servicing all the requests going up and then reversing to service requests
the other way.
• Illustration shows total head movement of 208 cylinders.

4) C-SCAN
• Provides a more uniform wait time than SCAN.
• The head moves from one end of the disk to the other. Servicing requests as it goes.
When it reaches the other end, however, it immediately returns to the beginning of the
disk, without servicing any requests on the return trip.
• Treats the cylinders as a circular list that wraps around from the last cylinder to the first
one.

5) C-LOOK
• 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.

II BSc OS: UNIT V Page 10


6) Selecting a Disk-Scheduling Algorithm

• SSTF is common and has a natural appeal


• SCAN and C-SCAN perform better for systems that place a heavy load on the
disk.
• Performance depends on the number and types of requests.
• Requests for disk service can be influenced by the file-allocation method.
• The disk-scheduling algorithm should be written as a separate module of the
operating system, allowing it to be replaced with a different algorithm if
necessary.
• Either SSTF or LOOK is a reasonable choice for the default algorithm.

**************

II BSc OS: UNIT V Page 11


II BSc OS: UNIT V Page 12

You might also like