delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2000/04/02/22:17:17

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Date: Sun, 2 Apr 2000 22:17:00 -0400
From: Chris Faylor <cgf AT cygnus DOT com>
To: cygwin-developers AT sourceware DOT cygnus DOT com,
Corinna Vinschen <corinna AT vinschen DOT de>
Subject: Re: Permission denied with makeinfo from texinfo-4.0
Message-ID: <20000402221700.A25094@cygnus.com>
Reply-To: cygwin-developers AT sourceware DOT cygnus DOT com
Mail-Followup-To: Chris Faylor <cgf AT cygnus DOT com>,
cygwin-developers AT sourceware DOT cygnus DOT com,
Corinna Vinschen <corinna AT vinschen DOT de>
References: <20000402204634 DOT D23469 AT cygnus DOT com> <200004030110 DOT UAA11749 AT hp2 DOT xraylith DOT wisc DOT edu> <20000402212045 DOT A24086 AT cygnus DOT com>
Mime-Version: 1.0
User-Agent: Mutt/1.1.8i
In-Reply-To: <20000402212045.A24086@cygnus.com>; from cgf@cygnus.com on Sun, Apr 02, 2000 at 09:20:45PM -0400

On Sun, Apr 02, 2000 at 09:20:45PM -0400, Chris Faylor wrote:
>I can't see an easy fix for this behavior other than to detect an
>ERROR_ACCESS_DENIED in _read and then attempt to see if we're at EOF.
>In this case, we'd have to figure out how many bytes are actually left
>in the file and just pass that many to ReadFile.  That could still fail,
>of course, but in that case, it would be a UNIX-type failure.

On second thought, this isn't feasible either.  We actually have to figure
out how many bytes are actually valid (x) in the buffer and how many bytes
would be read in (y).  If y <= x then the read should succeed.

Corinna, do you want to take a shot at fixing this?  I think the correct
place to do this is probably in fhandler_disk_file::read since you can't
really determine the number of bytes remaining anywhere else, can you?

Maybe to be safe we need a new fhandler method which can be triggered to
restart a read in the above scenario.  So it would be something like:


    In fhandler_base::read()

	if (!ReadFile (...)  && GetLastError == ERROR_ACCESS_DENIED &&
	    get_device () == FH_DISK)
	  return read_retry (in_ptr, in_len);

    New function:
	int
	fhandler_base::read_retry (void *in_ptr, size_t in_len)
	{
	  DWORD lowpos, highpos, lowsize, highsize;
	  long long size, pos;
	  size_t left;
	  MEMORY_BASIC_INFORMATION in_ptr_info;

	  lowsize = GetFileSize (get_io_handle (), &highsize);
	  if (lowsize == 0xffffffff && GetLastError () != NO_ERROR)
	    return -1; // need to preserve last GetLastError value

	  highpos = 0;
	  lowpos = SetFilePointer (get_io_handle (), 0, &highpos, FILE_CURRENT);
	  if (lowpos == 0xffffffff && GetLastError () != NO_ERROR)
	    return -1; // need to preserve last GetLastError value

	  size = ((long long) highsize) << 32 | lowsize;
	  pos = ((long long) highpos) << 32 | lowpos;
	  left = size - pos;	// hopefully it fits

	  (void) VirtualQuery (in_ptr + left - 1, &in_ptr_info, sizeof (in_ptr_info));
	  if (in_ptr_info.AllocationProtect == PAGE_NOACCESS ||
	      in_ptr_info.State == MEM_FREE) // not sure these are the correct things to check for
	    return -1;	// need to etc.
	  return read (in_ptr, left);
	}
	  
I think that is at least generally right, althought it is probably
full of typos.

cgf

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019