This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: BUG: Bad call to GetFileSze in ext2fsprogs lib/ext2fs/getsize.c


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

Earl

--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]