Jump to content

Sparse file

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Chekholko (talk | contribs) at 02:17, 28 November 2007 (that PDF is not about the same kind of sparse files). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer science, a sparse file is a type of computer file that attempts to use file system space more efficiently. When space has been allocated to a file but not actually filled with data it is not written to the file system. Instead, brief information about these empty regions is stored, which takes up much less disk space. These regions are only written to disk at their actual size when data is written to them; the file system transparently converts reads from empty sections into blocks filled with zero bytes at runtime. Most modern Unix file systems support sparse files. Sparse files are commonly used for disk images, database snapshots and log files.

If executed manually, the Unix command:

dd if=/dev/zero of=sparse-file bs=1 count=1 seek=1m

Will create a file of one megabyte in size, but with only one byte actually stored on disk. The advantage of sparse files is that storage is only allocated when actually needed: disk space is saved, and large files can be created even if there is insufficient free space on the file system. Disadvantages are that sparse files may become fragmented; file system free space reports may be misleading; filling up file systems containing sparse files can have unexpected effects; and copying a sparse file with a program that does not explicitly support them may copy the entire size of the file, even those sparse sections which are not on disk—losing the sparse property of the file.

See also

References