Thursday, April 21, 2011

Why it take longer time to copy a file than deleting it?


An Operating System (OS) is a program that acts as an intermediary between a user of a computer and the computer hardware.
Depending on the storage device being used, computers can store information in several physical forms. Each device has its own characteristics and physical organization, and hence different views of information are created. To unify all these views of information, a uniform logical view called a file is created.
A file is a contiguous set of data. It is the job of the OS to map this sequence of data into physical devices. The part of the OS responsible for this is the file system.
So the main task of the file system is to free the users of the details of storing of information in the physical devices. That is, when the storage device is changed, from disk to CD for example, the user still sees the same information.
In the most basic form, a file system consists of two distinct parts: a collection of files and a directory structure. The directory structure organizes and provides information about all the files in the system.
Every file has certain attributes like its name, location (its address in the file system), size, access control information (whether the file can be read or written to or only executed etc), type (whether it is just a collection of data or has other special instructions) , time, date and user identification.
If file A is to be copied to file B, then first a new file called B is created, next the contents of A are read and finally, this is written to B.
For this to happen, three steps are necessary. First, space must be found for B in the file system. Second, an entry for B must be made in the directory. The directory records the name of B and the location of B in the file system. Third, a request is sent to the OS to read the contents of A.
The OS finds the location information of A from the directory and reads the contents. Now to write to B, the OS again searches the directory for the address of B. Finally the content of A is written onto the space provided for B.


On the other hand if a file deletion is to take place, the process is much simpler. If file A is to be deleted, the OS just searches the directory for the named file.
Having found the entry, the space occupied by A is released so that it can be used by other files and the directory entry is erased.
As can be seen, the operations involved while copying a file are much more than those involved while deleting a file.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger