Enlist and describe file operations.Ripunjay Tiwari
Ans. Files exist to store information and allow it to be retrieved later. Each operating system has system calls to make basic operations on files like creation of file, reading from file, writing to file, etc. following are some basic operations on file –
- Creating a File – This operation is used to create a file. It requires two basic steps. First is to find space for file in file system and next is to make entry in the directory for this file. This entry includes name, size, location of file.
- Reading From File – The system call that performs read operation requires two attributes – one is file name and other is block, where information is kept after reading.
- Writing to File – The system call that performs write operation into file, requires two attributes – one is file name in which data is to be written and other is information that is to be written.
- Repositioning within a File – A file is repositioned from one location to new location by just reading file entry in directory and modifying location attribute with new value. This operation does not require actual I/O.
- Deleting a File – In this operation, file entry is erased from directory and all the space allocated to file is also released.
- Truncating a File – In this operation, only the contents of files are erased and all other attributes of file remain unchanged except file size.
- Open a File – Before performing operation on file, a process must open it. The purpose to open a file is a permit the system to read the attributes and list of disk addresses into main memory for rapid access on later calls.
- Close a File – To free the internal table space, when all the accesses have finished, the file should be closed.
- Append a File – This operation is used to add data to the end of the file. Some systems that provide a minimal set of system call do not generally have append, but some other systems provide multiple ways of doing the same thing, and these systems sometimes have append.
- Seek – Seek file operation is used to locate a location where to take the data. One common approach is a system call, is used to seek the file pointer from a specific place in the file.
- Rename – Rename operation is used to change the name of existing file.
- Set Attributes – Some attributes of files are used to settable and can be change, after the file has been created. This system call makes that possible.
- Get Attributes – Get attributes operations are used to return the current value of attributes to caller program or user.