Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.questions Subject: Re: sparse files Message-ID: <1989Nov30.175206.13517@virtech.uucp> Date: 30 Nov 89 17:52:06 GMT References: <21581@adm.BRL.MIL> Organization: Virtual Technologies Inc. Lines: 39 In article <21581@adm.BRL.MIL>, JAZBO@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 | +-----------------------------------------------------------------------+