FILE OPERATIONS


In order to store and retrieve the content of a file, the user manipulates it using various operations.

These operations vary from system to system.

Some of the commonly used operations are:

  • Create

  • Delete

  • Open

  • Close

  • Read

  • Write

  • Append

  • Rename

  • Copy

  • Seek

  • Truncate

Create:

Create Command creates a file with no data. Two steps are involved in creating a file:

  • First space is allocated to a file in a file system.

  • Second, an entry for the new file is made in the directory. Thus, a directory entry records the name of the file and its location in the file system.

Delete:

  • When a file is no longer needed, it has to be deleted to free up disk space.

  • There is always a system call for this purpose.

  • In addition, some operating systems automatically delete any file that has not been used for long days.

Open:

  • A process must open a file before using it.

  • Operating System opens a file from its location and loads it into memory for access by the user.

  • File can be opened implicitly by the system or explicitly by users.

Close:

  • When all the accesses are finished, file must be closed in order to store the changes made by different processes permanently.

Read:

  • To read from a file, a system call can be issued specifying the name of file and the address of memory block where the reading has to take place.

  • Files can be read sequentially or randomly.

  • Once the read has taken place, the read pointer is updated.

Write:

  • To write into a file, a system call can be issued specifying both the name of the file and the information to be written to the file.

  • The write operation starts from the current location of file pointer.

  • If the current position is the end of the file, the size of file increases.

  • If the current position is the middle of the file, existing data are overwritten and lost forever.

Append:

  • This call is restricted form of Write. It can only add data to the end of the file.

Rename:

  • It can be used to change the name of any existing file.

Copy:

  • It is used to copy the contents of the file into some other file or create another version of file with new name.

Seek:

  • For random access file, a method is needed to specify from where to take the data.

  • For this purpose Seek system call can be used.

  • It repositions the pointer from the current position to a specific place in the file.

  • After this call has completed, data can be read from or written to that position.

Truncate:

  • The user can erase the contents of a file. But can keep its attributes.

  • This operation allows all the attributes to remain unchanged except for file length.

  • Thus the length of file is reset to 0 and its space is released.

Advertisements

Give A message for us

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s