File Management
o Computer
can store information on several different storage media such as magnetic disk,
magnetic tapes and optical disks.
o So
that the computer system will be convenient to use OS provides a uniform
logical view of information storage.
o The
OS abstracts from the physical properties of its storage devices to define a
logical storage unit that is the file.
o Files
are mapped by the OS on to physical devices. These storage devices are usually non-volatile
so the contents are persistent through power failures and system reboots.
o A
file is a named collection of related information that is recorded on secondary
storage.
o From
user’s perspective, a file is the smallest allotment of logical secondary
storage that is data cannot be written to secondary storage unless they are
within a file.
o Commonly
files represent programs (both source and object forms) and data. Data files
may be numeric, alphabetic, alphanumeric or binary. Files may be free form such
as text files or maybe formatted rigidly.
o In
general a file is a sequence of bits, bytes, lines or records, the meaning of
which is defined by the file’s creator and user.
o The
information in a file is defined by its creator. Many different types of
information may be stored in a file-
source programs and object programs, executable programs, numeric data,
text, payroll records, graphic images, sound recordings and so on.
o A
file has a certain defined structure according to its type. A text file is a sequence of characters organized
into lines. A source file is a sequence
of subroutines and functions each of which is further organized as declarations
followed by executable statements. An executable
file is a series of code sections that the loader can bring into memory and
execute.
v FILE ATTRIBUTES:
A
file has certain attributes which vary from one operating system to another but
typically consists of these:
o Name: the symbolic filename is the only information
kept in human readable form.
o Identifier: this unique tag usually a number identifies
the file within the file system. It is
the non-human readable name for the file.
o Type: this information is needed for those systems
that support different types.
o Location: this information is a pointer to a device and
to the location of the file on the device.
o Size: the current in bytes, words or blocks are and
possibly the maximum allowed size are included in this attribute.
o Protection: message control information determines who
can do reading, writing, executing and so on.
o Time, date & user
identification: this information may be kept for creation, last
modification, and last use. The data can
be useful for protection, security and usage monitoring.
o The
information about all files is kept in the directory structure that also
resides on secondary storage. Typically
the directory entry consists of the file’s name and its unique identifier. The identifier in turn locates the other file
attributes.
v FILE OPERATIONS:
o A
file is an abstract data type. To define
a file properly, we need to consider the operations that can be performed on
files.
o The
OS can provide system calls to create, write, read, reposition, delete and
truncate files. Let us also consider
what the OS must do for each of the six basic file operations.
Creating 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 in the directory. The directory and records the name of the file and the location in the file system and possibly other information.
1.
Writing
a file: To write a file we make a system call 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 system must keep a write pointer to the
location in the file where the next write operation is to take place. The write pointer must be updated whenever a
write occurs.
2.
Reading
a file: To read from a file, we use a system call 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 system needs to keep read pointer to the location in the file
where the next read is to take place. Once the read has taken place, the read
pointer is updated.
3.
Repositioning
within a file: The directory search for the appropriate entry and
the current file position is set to given value. Repositioning within a file does not need to
involve any actual IO. This file
operation is also known as file seek.
4.
Deleting
a file: To delete a file, we search the directory for the
named file. Having found the associated
directory entry we release all files space so that it can be reused by other
files and erase the directory entry.
5.
Truncating
a file: The user may want to erase the contents of a file but
keep its attributes. Rather than forcing
the user to delete the file and then recreate this function allows all
attributes to remain unchanged except for file length.
o Other
common operations include appending new information to the end of an existing
file and renaming an existing file.
o Most
of the file operations mentioned involve searching the directory for the entry
associated with the name file. To avoid
this constant searching, many systems require that an open system call be used
before that file is first used actively.
o The
OS keeps a small table containing information about all open files (the open -
file table). When a file operation is
requested, the file is specified via an index into this table, so no searching
is required.
o When
the file is no longer actively used, it is closed by the process and operating
system removes its entry in the open file table.
o Typically
the open file table also has an open account associated with each file
indicating the number of processes that have the file open.
o Each
close decreases the count and when the open count reaches zero the file is no
longer in use, the file’s entry is removed from the open file table.
o Several
pieces of information associated with an open file. They are as follows:
1.
File pointer
2.
File open count
3.
Disk location of the file
4. Access rights
No comments:
Post a Comment