Basic File Operations in OS
File Operations in OS:
There are mainly nine basic file operations in os:
1. Creating a file: Two steps are needed to create a file. First, one is checking whether the space is available, or not. If the space is available then made an entry for the new file must be made in the directory. The entry includes the name of the file, the path of the file etc.
2. Writing file: To write a file, we have to know two things one is the name of the file and the second is the information or data to be written on the file.
3. Reading a file: To read a file, first of all, we search the directories for the file. If the file is found, the system needs to keep a ‘read’ pointer to the location in the file where the next read is to take place once the reader has taken place, the read pointer is updated.
4. Opening a file: It is the common operation performed on the file. Once the file is created, it must be opened before performing the file processing operations. When the user wants to open a file, it tells the operating system to invoke the open system call and passes the file name to the file system.
5. Renaming a file: This operation is used to rename the existing file.
6. Deleting files: To delete a file, first of all, search the directory for the named file, then release the file space and erase the directory entry.
7. Truncating a file: To truncate a file, remove the file contents only, but the attributes areas it.
8. Appending a file: This operation adds data to the end of the file.
9. Closing a file: When the processing of the file is complete, it should be closed so that all the changes made permanent and all the resources occupied should be released. In closing, it deallocates all the internal descriptors that were created when the file was opened.