Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting raw data to a disk in windows fails with error code 83 (invalid parameter)
    primarykey
    data
    text
    <p>I have a little snippet of code that I am trying to use to write a string that is roughly 100 bytes long to a disk at the address 0x600.</p> <pre><code>UCHAR szStr[0x4C] = {0}; memcpy(szStr, "Example string", 8); DWORD bytes, cb; HANDLE hDisk = CreateFile("\\\\.\\I:", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDisk == INVALID_HANDLE_VALUE) { cout &lt;&lt; "CreateFile error"&lt;&lt; endl &lt;&lt; GetLastError(); } if (!DeviceIoControl(hDisk, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &amp;cb, NULL)) { cout &lt;&lt; "IO Error"&lt;&lt; endl &lt;&lt; GetLastError(); } if (SetFilePointer(hDisk, 0x600, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { cout &lt;&lt; "Pointer error"&lt;&lt; endl &lt;&lt; GetLastError(); } if (!WriteFile(hDisk, szStr, 0x4C, &amp;bytes, 0)) { cout &lt;&lt; "Write error" &lt;&lt; endl &lt;&lt; GetLastError(); //Only one that triggers (err code 87) } CloseHandle(hDisk); </code></pre> <p>For some reason everything is OK until I call <code>WriteFile()</code> which fails. <code>GetLastError()</code> returns a code of 83 which means <code>INVALID_PARAMETER</code>. I have tried debugging it by specifing a normal file on the desktop instead of the drive <code>I:\</code> and the operation fires off successfully so my best guess would be the problem lies with the disk handle to the drive <code>I:\</code>.</p> <p>I read an article by MSDN located <a href="http://msdn.microsoft.com/en-us/library/ff551353.aspx" rel="nofollow">here</a> that explains that raw disk I/O gets blocked if you don't lock/dismount the drive first. I am confused as to why that would be a problem as in my code I call <code>DeviceIoControl</code> with <code>FSCTL_LOCK_VOLUME</code> to lock the device before I perform anything else. The disk has an active file system (FAT32/FAT16) and the 0x600 region likely lies within the filesystem, but according to the article if I lock the drive I should be able to write to it. Any idea what is going on here? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload