file mgt 3
file mgt 3
The operating system implements the abstract concept of a file by managing mass
storage media and the devices which control them. Also files are normally
organized into directories to ease their use. Finally, when multiple users have
access to files, it may be desirable to control by whom and in what ways files may
be accessed. File management is software processes concern with the overall
management of files.
Typically, the only way that a user or application may access files is through the
file management system. This relieves the user or programmer of the necessity of
developing special-purpose software for each application and provides the system
with a consistent, well-defined
Device Drivers
At the lowest level, device drivers communicate directly with peripheral devices
or their controllers or channels. A device driver is responsible for starting I/O
operations on a device and processing the completion of an I/O request. For file
operations, the typical devices controlled are disk and tape drives. Device drivers
are usually considered to be part of the operating system.
The basic I/O supervisor is responsible for all file I/O initiation and termination.
At this level, control structures are maintained that deal with device I/O,
scheduling, and file status. The basic I/O supervisor selects the device on which
file I/O is to be performed, based on the particular file selected. It is also concerned
with scheduling disk and tape accesses to optimize performance. I/O buffers are
assigned andsecondary memory is allocated at this level. The basic I/O supervisor
is part of the operating system
Logical I/O
Logical I/O enables users and applications to access records. Thus, whereas the
basic file system deals with blocks of data, the logical I/O module deals with file
records. Logical I/O provides a general-purpose record I/O capability and
maintains basic data about files. The level of the file system closest to the user is
often termed the access method. It provides a standard interface between
applications and the file systems and devices that hold the data. Different access
methods reflect different file structures and different ways of accessing and
processing the data. Some of the most common access methods are shown in
Figure 01, and they have been described in the previous unit.
Retrieve _All
Retrieve all the records of a file. This will be required for an application that must
process all of the information in the file at one time. For example, an application
that produces a summary of the information in the file would need to retrieve all
records. This operation is often equated with the term sequential processing,
because all of the records
are accessed in sequence.
Retrieve _One
This requires the retrieval of just a single record. Interactive, transaction-oriented
applications need this operation.
Retrieve _Next
This requires the retrieval of the record that is “next” in some logical sequence to
the most recently retrieved record. Some interactive applications, such as filling in
forms, may require such an operation. A program that is performing a search may
also use this operation.
Retrieve _Previous
Similar to Retrieve_Next, but in this case the record that is “previous” to the
currently accessed record is retrieved.
Insert _One
Insert a new record into the file. It may be necessary that the new record fit into a
particular position to preserve a sequencing of the file.
Delete_One
Delete an existing record. Certain linkages or other data structures may need to be
updated to preserve the sequencing of the file.
Update_One
Retrieve a record, update one or more of its fields, and rewrite the updated record
back into the file. Again, it may be necessary to preserve sequencing with this
operation. If the length of the record has changed, the update operation is generally
more difficult than if the length is preserved.
Retrieve_Few
Retrieve a number of records. For example, an application or user may wish to
retrieve all records that satisfy a certain set of criteria.
Operations on Files and Directories
The operating system provides systems calls to create, write, read, reposition,
truncate and delete files. The following sub-units discuss the specific duties a file
system must do for each of the following basic file operations.
File Operations
The following are various operations that can take place on file:
a. Creating a File
When creating a file, a space in the file system must be found for the file and then
an entry for the new file must be made in the directory. The directory entry records
the name of the file and the location in the file system.
b. Opening a File
Before using a file, a process must open it. The purpose of the OPEN call is to
allow the system to fetch the attributes and list of secondary storage disk addresses
into main memory for rapid access on subsequent calls.
c. Closing a File
When all the accesses are finished, the attributes and secondary storage addresses
are no longer needed, so the file should be closed to free up internal table space.
Many systems encourage this by imposing a maximum number of open files on
processes.
d. Writing a File
To write a file, a system call is made specifying both the name of the file and the
information to be written to the file. Given the name of the file, the system
searches the directory to find the location of the file. The directory entry will need
to store a pointer to the current block of the file (usually the beginning of the file).
Using this pointer, the address of the next block can be computed where the
information will be written. The write pointer must be updated ensuring successive
writes that can be used to write a sequence of blocks to the file. It is also important
to make sure that the file is not overwritten in case of an append operation, i.e.
when we are adding a block of data at the end of an already existing file.
e. Reading a File
To read a file, a system call is made that specifies the name of the file and where
(in memory) the next block of the file should be put. Again, the directory is
searched for the associated directory entry, and the directory will need a pointer to
the next block to be read. Once the block is read, the pointer is updated.
Repositioning a File
When repositioning a file, the directory is searched for the appropriate entry, and
the current file position is set to a given value. This file operation is also called file
seek.
a. Truncating a File
The user may erase some contents of a file but keep its attributes. Rather than
forcing the user to delete the file and then recreate it, this operation allows all the
attributes to remain unchanged, except the file size.
b. Deleting a File
To delete a file, the directory is searched for the named file. Having found the
associated directory entry, the space allocated to the file is released (so it can be
reused by other files) and invalidates the directory entry.
c. Renaming a File
It frequently happens that user needs to change the name of an existing file. This
system call makes that possible. It is not always strictly necessary, because the file
can always be copied to a new file with the new name, and the old file then
deleted.
d. Appending a File
This call is a restricted form of WRITE call. It can only add data to the end of the
file. System that provide a minima set of system calls do not generally have
APPEND, but many systems provide multiple ways of doing the same thing, and
these systems sometimes have APPEND. The ten operations described comprise
only the minimal set of required file operations. Others may include copying, and
executing a file. Also of use are facilities to lock sections of an open file for
multiprogramming access, to share sections, and even to map sections into memory
or virtual-memory systems. This last function allows a part of the virtual address to
be logically associated with section of a file. Reads and writes to that memory
region are then treated as reads and
writes to the file.
File Sharing
In a multiuser system, there is almost always a requirement for allowing files to be
shared among a number of users. Two issues arise: access rights and the
management of simultaneous access.
Access Right
The file system should provide a flexible tool for allowing extensive file sharing
among users. The file system should provide a number of options so that the way
in which a particular file is accessed can be controlled. Typically, users or groups
of users are granted certain access rights to a file. A wide range of access rights
are in use. The following list is representative of access rights that can be assigned
to a particular user for a particular file:
None: The user may not even know of the existence of the file, not to talk of
accessing it. To enforce this restriction, the user would not be allowed to read the
user directory that contains this file.
Knowledge: The user can determine that the file exists and who its owner is.
The user is then able to petition the owner for additional access rights.
Execution: The user can load and execute a program but cannot copy it.
Proprietary programs are often made accessible with this restriction.
Reading: The user can read the file for any purpose, including copying and
execution. Some systems are able to enforce a distinction between viewing and
copying. In the former case, the contents of the file can be displayed to the user,
but the user has no means for making a copy.
Appending: The user can add data to the file, often only at the end, but cannot
modify or delete any of the file’s contents. This right is useful in collecting data
from a number of sources.
Updating: The user can modify, delete, and add to the file’s data. This normally
includes writing the file initially, rewriting it
File Sharing
In a multiuser system, there is almost always a requirement for allowing files to be
shared among a number of users. Two issues arise: access rights and the
management of simultaneous access.
Access Right
The file system should provide a flexible tool for allowing extensive file sharing
among users. The file system should provide a number of options so that the way
in which a particular file is accessed can be controlled. Typically, users or groups
of users are granted certain access rights to a file. A wide range of access rights are
in use. The following list is representative of access rights that can be assigned to a
particular user for a particular file:
None: The user may not even know of the existence of the file, not to talk of
accessing it. To enforce this restriction, the user would not be allowed to read the
user directory that contains this file.
Knowledge: The user can determine that the file exists and who its owner is.
The user is then able to petition the owner for additional access rights.
Execution: The user can load and execute a program but cannot copy it.
Proprietary programs are often made accessible with this restriction.
Reading: The user can read the file for any purpose, including copying and
execution. Some systems are able to enforce a distinction between viewing and
copying. In the former case, the contents of the file can be displayed to the user,
but the user has no means for making a copy.
Appending: The user can add data to the file, often only at the end, but cannot
modify or delete any of the file’s contents. This right is useful in collecting data
from a number of sources.
Updating: The user can modify, delete, and add to the file’s data. This normally
includes writing the file initially, rewriting it