Q1. What all operations are performed on a file?
Ans. A file is an abstract data type.
Following are the operations performed by on a file:
- Creating a file
Two steps are necessary to create a file. First, space in thefile 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 thename 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 thename of the file and where (in memory) the next block of the file shouldbe put. Again, the directory is searched for the associated entry, and thesystem 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 appropriateentry, 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 by other files, and erase the directory entry.
- Truncating a file
The user may want to erase the contents of a file butkeep 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.