Q: sparse file creation in existing data?

From: Ph. Marek (marek@bmlv.gv.at)
Date: Fri Jun 29 2001 - 06:39:15 EST

Hi everybody,

though looking and grepping through the sources I couldn't find a way (via
fcntl() or whatever) to allow an existing file to get holes.

I found that cp has a parameter --sparse (or suchlike) - but strace shows
it doing a open(,O_TRUNC) which has a bit of impact on previous filedata :-)

What I'd like to do is something like

  fh=open( ... , O_RDWR);
  lseek(fh, position ,SEEK_START);
// where position is a multiple of fs block size

to create a 16kB hole in a file.
If the underlying fs doesn't support holes, I'd get ENOSYS or something.

What I'd like to use that for:

I imagine having a file on hd (eg. tar) and not enough space to decompress.
So with SOME space at least I'd open the file and stream it's data to tar,
after each few kB read I'd free some space - so this could eventually succeed.

I also thought about simple reversing the filedata - so I'd read off the
end of the file and truncate() downwards - but that would mean reversing
the whole file which could take some time on creation and would solve only
this specific case.

Ideas, anyone?



To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

This archive was generated by hypermail 2b29 : Sat Jun 30 2001 - 21:00:21 EST