title: Readfile() occasionally returns 998 / ERROR_NOACCESS
body: <p>I am trying to implement fast IO under Windows, and working my way up to Overlapped IO.  In my research, Unbuffered IO requires page aligned buffers. Ive attempted to implement this in my code below. However, I occasionally have Readfiles last error report no access (error 998, ERROR_NOACCESS) - prior to completing the read, and after a few reads of a page aligned buffer. Sometimes 16. Sometimes 4, etc.</p>
  
  <p>I cant for the life of me figure out why i am occasionally throwing an error. Any insight would be helpful.</p>
  
  <pre><code>ci::BufferRef CinderSequenceRendererApp::CreateFileLoadWinNoBufferSequential(fs::path path) {
  HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  
  if (file == INVALID_HANDLE_VALUE)
  {
      console() &lt;&lt; "Could not open file for reading" &lt;&lt; std::endl;
  }
  
  ci::BufferRef latestAvailableBufferRef = nullptr;
  
  LARGE_INTEGER nLargeInteger = { 0 };
  
  GetFileSizeEx(file, &amp;nLargeInteger);
  
  // how many reads do we need to fill our buffer with a buffer size of x and a read size of y
  // Our buffer needs to hold 'n' sector sizes that wil fit the size of the file
  
  SYSTEM_INFO si;
  GetSystemInfo(&amp;si);
  long readAmount = si.dwPageSize;
  
  int numReads = 0;
  ULONG bufferSize = 0;
  
  // calculate sector aligned buffer size that holds our file size
  while (bufferSize &lt; nLargeInteger.QuadPart)
  {
      numReads++;
      bufferSize = (numReads) * readAmount;
  }
  
  // need one page extra for null if we need it
  latestAvailableBufferRef = ci::Buffer::create(bufferSize + readAmount);
  
  if (latestAvailableBufferRef != nullptr)
  {
      DWORD outputBytes = 1;
  
      // output bytes = 0 when OEF
      void* address = latestAvailableBufferRef-&gt;getData();
      DWORD bytesRead = 0;
      while (outputBytes != 0)
      {
          bool result = ReadFile(file, address, readAmount, &amp;outputBytes, 0);
          if (!result )//&amp;&amp; (outputBytes == 0))
          {
              getLastReadError();
          }
  
          address = (void*)((long)address + readAmount);
          bytesRead += outputBytes;
  
      }
  }
  
  CloseHandle(file);  
  
  // resize our buffer to expected file size?
  latestAvailableBufferRef-&gt;resize(nLargeInteger.QuadPart);
  
  return latestAvailableBufferRef;
  }
  </code></pre>