Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would go with</p> <pre><code>HANDLE drive = CreateFile(_T("\\.\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); // error handling DWORD br = 0; DISK_GEOMETRY dg; DeviceIOControl(drive, IOCTL_DISK_GET_DRIVE_GEOMETRY, 0, 0, &amp;dg, sizeof(dg), &amp;br, 0); // LARGE_INTEGER pos; pos.QuadPart = static_cast&lt;LONGLONG&gt;(sectorToRead) * dg.BytesPerSector; SetFilePointerEx(drive, pos, 0, FILE_BEGIN); const bool success = ReadFile(drive, sectorData, dg.BytesPerSector, &amp;br) &amp;&amp; br == dg.BytesPerSector; // CloseHandle(drive); </code></pre> <p>Please note that in order to verify that you've successfully read a sector you must verify that the read byte count corresponds to the number of bytes you wanted to read, i.e. in my experience ReadFile() on a physical disk can return TRUE even when no bytes are read (or maybe I just have a buggy driver).</p> <p>The problem that remains is to determine your drive number (0 as is used in my example refers to C: which is probably not what you want). I don't know how to do that, but if you only have one drive connected which is not formatted, it ought to be possible by calling opening each PhysicalDrive in order and calling DeviceIOControl() with <code>IOCTL_DISK_GET_DRIVE_LAYOUT_EX</code> as a command:</p> <pre><code>DRIVE_LAYOUT_INFORMATION_EX dl; DeviceIOControl(drive, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, 0, 0, &amp;dl, sizeof(dl), &amp;br, 0); if(dl.PartitionStyle == PARTITION_STYLE_RAW) { // found correct disk } </code></pre> <p>But that's just a guess.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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