Bug 403 - scp generates sparse file when no space left
Summary: scp generates sparse file when no space left
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: scp (show other bugs)
Version: -current
Hardware: HPPA HP-UX
: P2 normal
Assignee: OpenSSH Bugzilla mailing list
URL:
Keywords:
Depends on: 85
Blocks:
  Show dependency treegraph
 
Reported: 2002-09-26 03:26 AEST by rusr
Modified: 2004-04-14 12:24 AEST (History)
0 users

See Also:


Attachments
Shorter fix (521 bytes, patch)
2003-01-07 11:07 AEDT, Damien Miller
no flags Details | Diff
Correct fix (already in tree) (522 bytes, patch)
2003-02-10 14:43 AEDT, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description rusr 2002-09-26 03:26:12 AEST
When someone copies a file using scp in HP-UX 11.i Secure Shell (the HP
supported version of OpenSSH) and the destination file system hasn´t
enough space, a sparse file is being created. To reproduce the problem:

# bdf .
Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol4    1015808  999189   15607   98% /old-opt 

Now copy over a large file like vmunix to show the problem, the
first scp works fine, the second will fail:

# scp  /stand/vmunix <machine>:/old-opt/mab/vmunix         
vmunix               100% |*****************************| 12027 KB    00:09  

# scp  /stand/vmunix <machine>:/old-opt/mab/vmunix2
vmunix               100% |*****************************| 12027 KB    00:08    
scp: /old-opt/mab/vmunix2: No space left on device

# ll
total 33238
-rwxr-xr-x   1 mab        wtec       12316048 Sep 24 18:20 vmunix*
-rwxr-xr-x   1 mab        wtec       12316048 Sep 24 18:21 vmunix2*
                                     ^^^^^^^^ <<<=== PROBLEM 

Now we can check for the real size:
# du *
24056   vmunix
9182    vmunix2 

I suspect that this problem is also present on other OS's, but at the moment, I
have confirmed it only on HP systems.

Running tusc on an "scp -t" process shows that ftruncate is being called no
matter what.

In sink() in file scp.c, we can see:

                if (ftruncate(ofd, size)) {
                        run_err("%s: truncate: %s", np, strerror(errno));
                        wrerr = DISPLAYED;
                }


This code fragment should be enclosed in this if condition:

              if(wrerr == NO){
                if (ftruncate(ofd, size)) {
                        run_err("%s: truncate: %s", np, strerror(errno));
                        wrerr = DISPLAYED;
                }
              }
Comment 1 Damien Miller 2003-01-07 11:07:12 AEDT
Created attachment 196 [details]
Shorter fix

Here is a shorter fix (rcp needs it too)
Comment 2 Damien Miller 2003-01-10 21:25:20 AEDT
Fix committed to CVS. Thanks.
Comment 3 Damien Miller 2003-02-10 14:43:07 AEDT
Created attachment 226 [details]
Correct fix (already in tree)

I'll put the correct fix here for the benefit of distributors
Comment 4 Damien Miller 2004-04-14 12:24:18 AEST
Mass change of RESOLVED bugs to CLOSED