Path: utzoo!mnetor!uunet!husc6!bbn!rochester!udel!burdvax!bpa!cbmvax!vu-vlsi!devon!shockeye!root From: root@shockeye.UUCP (Bourne-again Superuser) Newsgroups: comp.unix.wizards Subject: Re: Holey files, Batman! Message-ID: <175@shockeye.UUCP> Date: 20 Mar 88 00:00:20 GMT References: <143@aoa.UUCP> Reply-To: root@shockeye.UUCP (Bourne-again Superuser) Organization: Competitive Computer Systems, Lancaster PA Lines: 26 In article <143@aoa.UUCP> mbr@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@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."