title: SetFilePointer from FILE_END always fails for a volume handle
body: <p>I simply want to move the file-pointer of a volume handle backwards from <code>FILE_END</code>. Unfortunately, the operation fails regardless of any input value I pass to it !</p>
  <p>I'm using the following code:</p>
  <pre class="lang-c prettyprint-override"><code>HANDLE vol_handle = CreateFile (&quot;\\\\.\\C:&quot;,
                           GENERIC_READ | GENERIC_WRITE,
                           FILE_SHARE_READ | FILE_SHARE_WRITE,
                           NULL, OPEN_EXISTING, 0, NULL);
  
  if (vol_handle == INVALID_HANDLE_VALUE)
  {
      printf(&quot;Failed to create volume handle!\n&quot;);
      print_last_error(GetLastError());
      return ERROR;
  }
  printf(&quot;Handle acquired for volume %s \n&quot;, VOLUME);
  
  long int dist = 512000; // 500 KB forwards
  
  SetLastError(0);
  int result = SetFilePointer (vol_handle, dist, NULL, FILE_BEGIN);
  if (result == INVALID_SET_FILE_POINTER)
  {
      printf(&quot;SetFilePointer (BEGIN) FAILED!\n&quot;);
      print_last_error(GetLastError());
  }
  else
      printf(&quot;SetFilePointer (BEGIN) SUCCESS!\n&quot;);
  
  dist = -5120; // 50 KB backwards
  
  SetLastError(0);
  result = SetFilePointer (vol_handle, dist, NULL, FILE_END);
  if (result == INVALID_SET_FILE_POINTER)
  {
      printf(&quot;SetFilePointer (END) FAILED!\n&quot;);
      print_last_error(GetLastError());
  }
  else
      printf(&quot;SetFilePointer (END) SUCCESS!\n&quot;);
  
  SetLastError(0);
  result = SetFilePointer (vol_handle, dist, NULL, FILE_CURRENT);
  if (result == INVALID_SET_FILE_POINTER)
  {
      printf(&quot;SetFilePointer (CURRENT) FAILED!\n&quot;, offset_low_part);
      print_last_error(GetLastError());
  }
  else
      printf(&quot;SetFilePointer (CURRENT) SUCCESS!\n&quot;);
  </code></pre>
  <p>The output:</p>
  <pre>
    Handle acquired for volume \\.\C:
    SetFilePointer (BEGIN) SUCCESS!
    SetFilePointer (END) FAILED!
       Error 0x57: The parameter is incorrect.
    SetFilePointer (CURRENT) SUCCESS!
  </pre>
  <p>As you can see, the seek works fine for <code>FILE_BEGIN</code> and <code>FILE_CURRENT</code>, but it always fails for <code>FILE_END</code> with error code <code>0x57</code> (87 in decimal) saying:</p>
  <pre>
    The parameter is incorrect
  </pre>
  <p>Note that changing <code>dist</code> to a positive value doesn't change the situation.</p>
  <p>What am I missing here?</p>
  <p><strong>( NOTE: Testing on Windows-5.1.2600 (XP SP3) in latest Code::Blocks IDE 16.01 with MinGW compiler, and Administrator privileges )</strong></p>
  <hr />
  <p><strong>NOTE:</strong> This is absolutely not a duplicate of <a href="https://stackoverflow.com/questions/23382356/">this question</a>, since I am not accessing physical disk (volume access is different from physical disk) and the distance value is a multiple of 512 bytes (the logical sector size). If the distance length was incorrect, then the other seeks (BEGIN and CURRENT) would have failed as well, yet they don't.</p>
  <hr />
  <h3>Update</h3>
  <p>Based on <a href="https://stackoverflow.com/questions/37738926/37739935#37739935">Rohans'</a> answer, I performed another check with the following code:</p>
  <pre class="lang-c prettyprint-override"><code>long long int offset_64 = 5120000 // 5000 KB distance;
  long int offset_low_part = -(0xffffffff &amp; offset_64);
  long int offset_hig_part = offset_64 &gt;&gt; 32;
  
  printf(&quot;offset_64 = %lld\n&quot;, offset_64);
  printf(&quot;low_part  = %ld\n&quot;, offset_low_part);
  printf(&quot;high_part = %ld\n\n&quot;, offset_hig_part);
  
  // Get volume handle using CreateFile(...) exactly as before;
  
  SetLastError(0);
  int result = SetFilePointer (vol_handle, offset_low_part, &amp;offset_hig_part, FILE_END);
  
  if (result == INVALID_SET_FILE_POINTER)
  {
      print_last_error(GetLastError());
      printf(&quot;Failed to set file pointer!\n&quot;);
      printf(&quot;high_part after SetFilePointer = %ld\n&quot;, offset_hig_part);
      return ERROR;
  }
  </code></pre>
  <p>Although I believe Rohans' point is important, it still doesn't solve the problem:</p>
  <pre><code>offset_64 = 5120000
  low_part  = -5120000
  high_part = 0
  
  Handle acquired for volume \\.\C:
  Error 0x57: The parameter is incorrect.
  Failed to set file pointer!
  high_part after SetFilePointer = 0
  </code></pre>
  <p>Using a positive value for <code>low_part</code> doesn't change the situation.</p>
  <hr />
  <h3>Update</h3>
  <p>Based on David Heffernan's comment below, I acknowledge that this code can be shorter and easier using <code>SetFilePointerEx</code>, but the result is still the same and the operation fails to seek from <code>FILE_END</code> on the volume handle.</p>