Explain the various operations performed on files

In this post we are discussing about Explain the various operations performed on files

  1. Creating a file. Two steps are necessary to create a file. First, space in the file system must be found for the file. We discuss how to allocate space for the file in Chapter 11. Second, an entry for the new file must be made in the directory.
  2. 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 111ust 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.
  3. 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. Because a process is usually either reading from or writing to a file, the current operation location can. be kept as a per-process current file- position pointer. Both the read and write operations use this same pointer, saving space and reducing system complexity.
  4. 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.
  5. 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.
  6. 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 a11o”vs all attributes to remain unchanged-except for file length-but lets the file be reset to length zero and its file space released.

Leave a Reply

Your email address will not be published. Required fields are marked *