Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Tue, 14 Sep 2004 14:25:19 -0400 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: BUG: Bad call to GetFileSze in ext2fsprogs lib/ext2fs/getsize.c Message-ID: <20040914182519.GD5258@trixie.casa.cgf.cx> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <414532D7 DOT 8050506 AT agilent DOT com> <41472B3F DOT 8030800 AT agilent DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41472B3F.8030800@agilent.com> User-Agent: Mutt/1.4.1i 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/