BUG: Bad call to GetFileSze in ext2fsprogs lib/ext2fs/getsize.c
Christopher Faylor
cgf-no-personal-reply-please@cygwin.com
Tue Sep 14 18:46:00 GMT 2004
On Tue, Sep 14, 2004 at 10:32:47AM -0700, Earl Chew wrote:
>Earl Chew wrote:
>>The call to GetFileSize() doesn't match the Microsoft documentation,
>>and invariably mis-sizes the disk image as zero.
>
>A couple of comments regarding your recent changes:
>
>a. GetFileSize() returns the bits 32-63 of the file size in
> the 2nd parameter. I think code like this is more better:
>
> DWORD high_filesize;
> filesize = GetFileSize(dev, &high_filesize);
> if (filesize != INVALID_FILE_SIZE || GetLastError() != NO_ERROR)
> *retblocks (((unsigned long long) high_filesize << 32)
> + filesize) / blocksize;
>
>b. Use of CreateFile() causes problems because win32 doesn't know
> about the cygwin mount points. Code like this is more flexible:
>
> fd = open(file, O_RDONLY | O_BINARY);
> if (fd == -1)
> return EBADF;
> dev = (HANDLE) get_osfhandle(fd);
>
> ...
> close(fd);
>
>c. Similarly, code in unix_io.c needs to force binary mode to
> avoid getting incorrect results when cygwin decides the image
> is text!
>
> open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY;
> #ifdef O_BINARY
> open_flags |= O_BINARY;
> #endif
Let me again point out that a cygwin program shouldn't be doing *ANY OF
THIS*.
It shouldn't be calling GetFileSize and it shouldn't be calling
CreateFile.
cgf
--
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/
More information about the Cygwin
mailing list