Files (5 Unit)
Files (5 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.
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
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
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
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.
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
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.
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.
**************