A mechanism for replicating and maintaining files in a space-efficient
manner is disclosed. In one embodiment, a current file is replicated by
associating the data blocks of the current file with both the current
file and a new file. The new file and the current files are separate and
distinct from each other. Data blocks remain shared until the content of
one file is modified. Only the data blocks affected by the modification
are duplicated. The two files share the unchanged data blocks, but both
files are each associated with additional data blocks that reflect the
modification. Reference values are used to track how many files are
associated with each data block. In another embodiment, a file descriptor
is linked to a filename at the request of a user or application. The
present invention avoids needless duplication of the same data blocks
among copies of a file.