Subject: Re: WG: cp command - problem with sparse [sparse file suuport under NTFS (Win2k)]
From: Corinna Vinschen <[email-masked]>
To: [email-masked]
Cc: RE <[email-masked]>
Date: Wed, 2 Feb 2005 12:21:02 +0100

[Please don't CC me, send everything just to the ML]

On Feb  2 11:29, RE wrote:
> Hi Corinna,
> 
> Eric Blake send me a mail with a reference to your post
> <[email-masked]>
> 
> Well, I am not a programmer but I am looking for a solution for the
> following.  And I think that cp.exe from fileutils/coreutils might do the
> job.  But so far I wasn't successful.
> 
> I have files on my HD that contain large amounts of zeroes (between 4 and
> 100 MB of zeroes) and I want to convert them into sparse files.  I already
> tried the GNU fileutils with their cp command.  They say that it converts
> standard files into sparse files by using the command
> 
> "cp --sparse=always c:\test.cfg c:\test2.cfg"
> 
> 
> Everything works fine with that cp command, except the fact that I do not
> get a sparse file.  Even when I copy a sparse file, the sparse attribute is
> no longer present in the copy and the occupied space on my HD is the same as
> with the original file.
> 
> What am I doing wrong?  Is there a bug with cp.exe?  Is the command I am
> using not correct?

That's something which has to be debugged.  Erik, your call.  The question
is, does cp use lseek to skip over 128K of 0-bits and then simply writes
further?  What Cygwin does is this, basically:

	On lseek:

	  did_lseek = true;

	On write:

	  if (did_lseek)
	    if (current_position > actual_length)
	      if (filesystem supports sparse
	          AND current_position >= actual_length + (128 * 1024))
		make_file_sparse
	        
If make_file_sparse doesn't work, the strace will have an entry along
the lines of

  0 = DeviceIoControl(1234, FSCTL_SET_SPARSE, ...

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          mailto:[email-masked]
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/