file size wraps at 2GiB

Advertisement

jmichae3
Joined:
Posts:
5
Location:
WA, USA

file size wraps at 2GiB

WinSCP 4.1.9 build 416
Windows XP Pro SP3
SFTP+SCP
GUI, Norton Commander

there is a problem with calculation of filesize.
calculation of filesize seems to wrap around and start at 0 again at the 2GiB point, which tells me a 32-bit number type is being used.
Perhaps an int or long or DWORD (32-bit number) is being used for the data type, because my 2.6GB .ISO file showd up as a 500MB.
download in the progress bar, numbers, etc.

you should be using an __int64 or LARGE_INTEGER instead for your calculations.
LARGE_INTEGER is a structure rather than a simple data type like __int64.
the part you are interested in with LARGE_INTEGER is .QuadPart which is 64-bit.

file sizes should be calculated using the windows structure LARGE_INTEGER and the Win32 call GetFileSize().

for some sample code using LARGE_INTEGER, try this:
#include <windows.h>
LARGE_INTEGER li;
__int64 filesize64=0;
li.QuadPart=0;
HANDLE h=CreateFile(
  lpFileName, // pointer to name of the file
  GENERIC_READ, // access (read-write) mode
  FILE_SHARE_READ,  // share mode
  NULL, // pointer to security attributes
  OPEN_EXISTING, // how to create
  FILE_ATTRIBUTE_NORMAL,  // file attributes
  INVALID_HANDLE_VALUE // handle to file with attributes to copy
);
if (INVALID_HANDLE_VALUE != h) {
    DWORD d0, d1;
    d0=GetFileSize(
      h,  // handle of file to get size of
      &d1 // pointer to high-order word for file size
    );
    if (0xFFFFFFFF==d0) {
        DWORD er=GetLastError();
        if (NO_ERROR==er) {
            li.LowPart=d0;
            li.HighPart=(LONG)d1;
            filesize64=li.QuadPart;
        } else {
            //ERROR: problem getting filesize.
        }
    }
    CloseHandle(h);
} else {
    //ERROR: could not open file.
}
//at this point, filesize is in both filesize64 and li.QuadPart
//for sprintf, use "%I64d"

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: file size wraps at 2GiB

WinSCP does that. At least in most situations. So I need to know where exactly do you see this happening.

Reply with quote

jmichae3
Joined:
Posts:
5
Location:
WA, USA

Re: file size wraps at 2GiB

martin wrote:

WinSCP does that. At least in most situations. So I need to know where exactly do you see this happening.

the problem with truncated "bytes transferred" seemed to wrap at 500,000kb. I don't know if I can get it to do it again. when I was uploading a 2.5-2.6GB ISO file, and this showed in the "single-file-transfer" mode where the progress bar shows.

I was confused by the estimated time earlier with the 1 in front with no desination, thought it was garbage and ignored it. turned out to be number of days.

However, when I am using the queue and viewing the queue, this seems to be accurate, and even tells me the number of days (although having a "days" or "d" or "dys" would be slightly easier to read). but don't quote me on the queue, because I didn't try uploading 150MB just to try it out. I don't have a lot of time to waste.

given there are 36 blocks in the progress bar at 2mm/block (72mm total on my 19" monitor), and the file is 2.7GB, that means that
2 blocks*2.7GB/(36blocks*100%)=150MB, where 100%=1.00
so 2 blocks=150MB.
You can either put the number of blocks on the top of the equation or put the percentage at the top of the equation.

currently single-file-mode just tripped 2 blocks in the progress bar at 31,000kb. so something is being calculated all wrong in the progress bar. time estimation looks correct in all cases, somewhere around a 17hrs-1day.

I was wrong about file size, only in the file browser there is a file size. none of the upload stuff says anything about the file size. anyway, filesize is correct.

well, I can't reproduce it because I just lost my settings. what's going on? this save button is dangerous (requires constant monitoring of everything). everything blank now after trying to save directory settings. :-(
all the more reason to keep directory settings with the session. broken.

winscp also gives me "network error. software caused abort(reconnect,abort)".

Reply with quote

anoncoward
Guest

winscp419 - copy remote to local failed at 4GB of data

Copy of remote file to local directory failed on file reaching max unsigned 32bits.

Reports insufficient disk space to write file, asks what to do (abort, retry, skip, skip all, etc.)

destination drive has > 500GB available.

winscp 4.1.9, build 416 (per help about box)

The item was a foreground download, not queued.

Reply with quote

Advertisement

You can post new topics in this forum