sparse files
Conor P. Cahill
cpcahil at virtech.uucp
Fri Dec 1 04:52:06 AEST 1989
In article <21581 at adm.BRL.MIL>, JAZBO at brownvm.brown.edu (James H. Coombs) writes:
> "Sparse files" have been mentioned in several recent postings. For example:
[ example deleted.. ]
> Can someone explain exactly what a sparse file is? How does one get created?
A sparse file is a file that has "holes" in it. A hole is a portion of
the file that does not exist on the disk. Reading data from a hole will
always get null bytes for the portion of the read that was a hole. Writing
data to the holw (even if it is all nulls) will cause the hole to become
a non-hole (in other words it will take up space on the file system).
Holes usually occur in binary database files and can also occur in
core files on some systems.
An easy way to create a sparse file is as follows:
fd = open(newfile,...);
lseek(fd,1meg,0);
write(fd,"at one meg",count);
If you ls the file it will appear as if it takes up 1meg of space.
If you read the file, you will see 1meg of nulls followed by the "at one meg".
However, if you do a df and compare it to the value before the file
was created you will find that the system space has gone down by just
a few blocks.
I have seen 80 meg files on 40 meg file systems. This can be a problem if
you try to restore the file from a backup, since most backup utilities, like
cpio or tar, do not know about sparse files, the restore will faile when
you run the filesystem out of space.
--
+-----------------------------------------------------------------------+
| Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 !
| Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 |
+-----------------------------------------------------------------------+
More information about the Comp.unix.questions
mailing list