sparse files

D'Arcy J.M. Cain darcy at druid.uucp
Mon Dec 11 04:08:41 AEST 1989


In article <2700 at auspex.auspex.com> guy at 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 at druid)     |   "You mean druid wasn't taken yet???"
D'Arcy Cain Consulting             |                    - Everybody -
West Hill, Ontario, Canada         |
No disclaimers.  I agree with me   |



More information about the Comp.unix.questions mailing list