Unit V – File management
5.1 Files
Concepts:
A file is a named collection of related information that is recorded on
secondary storage such as magnetic disks, magnetic tapes and optical disks.
In general, a file is a sequence of bits, bytes, lines or records whose meaning is
defined by the files creator and user.
Attributes of a File
Following are some of the attributes of a file:
Name . It is the only information which is in human-readable form.
Identifier. The file is identified by a unique tag(number) within file system.
Type. It is needed for systems that support different types of files.
Location. Pointer to file location on device.
Size. The current size of the file.
Protection. This controls and assigns the power of reading, writing, executing.
Time, date, and user identification. This is the data for protection, security,
and usage monitoring.
File Operations
The operating system must do to perform basic file operations given below.
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.
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 file's location. The system
must keep a write pointer to the location in the file where the next write is to
take place. The write pointer must be updated whenever a write occurs.
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 entry, and the system needs
to keep a 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.
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.
Deleting a file. To delete a file, we search the directory for the named file.
Having found the associated directory entry, we release all file space, so that it
can be reused bv other files, and erase the directory entry.
Page 1 of 10
Prof. S. C.Bhabad
CO
, Operating System-315319
Protection: Access-control information determines who can do reading,
writing, executing, and so on.
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 it, this
function allows all attributes to remain unchanged—except for file length—but
lets the tile be reset to length zero and its file space released.
In brief
File Types
Page 2 of 10
Prof. S. C.Bhabad
CO