Search

Friday, 7 March 2014

Explain The File Operations In OS


The OS provides systems calls to create, write, read, reset, and delete files. The following discusses the specific duties an OS must do for each of the five basic file operations.

Creating a file :- 

First, a space in the file system must be found for the file. Second, an entry for the new file must be made in the directory. The directory entry records the name of the file and the location in the file system.

Writing a file :-

To write a file, a system call is made specifying both the name and 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 location of the file. The directory entry will need to store a pointer to the current block of the file (usually the beginning of the file). Using this pointer, the address of the next block can be computed where the information will be written. The write pointer must be updated – in this way, successive writes can be used to write a sequence of blocks to the file.


Reading a file :-

To read a file, a system call is made that specifies 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 directory entry, and the directory will need a pointer to the next block to be read. Once the block is read, the pointer is updated.

Resetting a file :-

The directory is searched for the appropriate entry, and the current file position is reset to the beginning of the file.

Deleting a file :-

To delete a file, the directory is searched for the named file. Having found the associated directory entry, the space allocated to the file is released (so it can be reused by other files) and invalidates the directory entry

No comments:

Post a Comment