Holey files, Batman!

Bourne-again Superuser root at shockeye.UUCP
Sun Mar 20 10:00:20 AEST 1988


In article <143 at aoa.UUCP> mbr at aoa.UUCP (Mark Rosenthal) writes:
>How do you copy holey files?
...
>As far as I can tell, when reading such a file, there is no way to determine
>whether bytes whose value is 0 are really stored on disk, or are in the middle
>of a hole in the file.  Therefore, when copying such a file, the holes get
>converted to actual blocks which take up space on the disk, so the file expands.
>    1. Read through the bytes sequentially, but don't output any whose value
>	is 0.  Use lseek() before writing the next non-zero byte.  To guarantee
>	that the created file has the same extent, always write the last byte.
>	Disadvantage: When copying a file with huge holes and little data,
>	this would be very slow.
...
>Is there any direct method which will allow me to determine where the holes
>in a file are?  Does anybody know of any other tricks besides the two I have
>described above?  What, if any, are the differences among the following

You don't have to check every byte of the file - if you know what the
filesystem's block size (say 1024) then you can read the next 1024 bytes and
if any of them are not zero, write them all, otherwise lseek past them.

--
Mark Buda, The Embattled Hermit		Domain: hermit at chessene.uucp
Dumb: ...{rutgers,ihnp4,cbosgd}!bpa!vu-vlsi!devon!chessene!hermit
"Dr. Johnson, can you come over right away? My father has a hibachi on his
head."



More information about the Comp.unix.wizards mailing list