Path: utzoo!attcan!telly!nebulus!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.unix.questions Subject: Re: sparse files Message-ID: <1989Dec10.170841.26798@druid.uucp> Date: 10 Dec 89 17:08:41 GMT References: <21581@adm.BRL.MIL> <235@dg.dg.com> <2700@auspex.auspex.com> Reply-To: darcy@druid.UUCP (D'Arcy J.M. Cain) Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 43 In article <2700@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes: >>UNIX treats the "holes" as 0's when read. In fact, UNIX has only >>minimal support for sparse files. Backing up sparse files often >>involves copying large amounts of nulls. Once an area of a file is >>written, it cannot be returned to its previous sparse state. > >Not in general, anyway. At least the first version of AIX for the RT PC >claimed, in its documentation, that it had an "fclear()" call to punch >holes in files; I think this may show up in future releases of other >UNIXes as well. > Seems simple enough to write a utility. The core would be something like the following: file_pointer = 0L; skip_space = 0; while ((c = fgetc(in_fp)) != EOF) { if (skip_space) { fseek(out_fp, file_pointer, SEEK_SET); skip_space = 0; } if (c) fputc(c, out_fp); else skipspace = TRUE; file_pointer++; } Of course this is just off the cuff and probably needs some fleshing out and optimizing but I think it would work on any system supporting sparse files that return nulls for the empty parts. -- D'Arcy J.M. Cain (darcy@druid) | "You mean druid wasn't taken yet???" D'Arcy Cain Consulting | - Everybody - West Hill, Ontario, Canada | No disclaimers. I agree with me |