Page 1 of 1

WinAPI - Direct disk access

Posted: Mon Aug 01, 2016 2:48 pm
by npelov
Hi,

I have a question that's a bit off-topic. I was playing with direct disk access:

Code: Select all

  HANDLE hDevice;
  DWORD br;
  buffer = (char*)malloc (32768);
  hDevice = CreateFile(
      devicename,
      GENERIC_READ, // |GENERIC_WRITE
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL, // lpSecurityAttributes
      OPEN_EXISTING,
      FILE_FLAG_RANDOM_ACCESS,// FILE_FLAG_NO_BUFFERING 
      NULL
  );
  if (hDevice == INVALID_HANDLE_VALUE) {
    printf("error opening device!\n");
    return 1;
  }
  SetFilePointer (hDevice, 0, NULL, FILE_BEGIN); // read boot sector
  if (!ReadFile (hDevice, buffer, 512, &br, NULL) ){
    printf("error reading boot sector!");
    return 2;
  }
Everything I read does not pass through PrimoCache, nor Windows cache, even though FILE_FLAG_NO_BUFFERING is not set. Is there a way to do cached read on logical volumes (or physical disks) using win32 API?

Re: WinAPI - Direct disk access

Posted: Tue Aug 02, 2016 3:59 am
by Support
Since you want to directly access disks, bypassing file system layers and volume layers, neither Windows cache (within file system layer) nor PrimoCache (within volume layer) will be available. Our old program named FancyCache Disk Edition implements caching within disk layer, however this program is now stopped.

BTW, direct access to the disk or to a volume is restricted. For more information, see http://support.microsoft.com/kb/942448

Re: WinAPI - Direct disk access

Posted: Tue Aug 02, 2016 7:18 am
by npelov
My idea was to preload certain sectors. Maybe you can make primocache FS aware and allow the user to choose to pre-load certain fails/regions of disk (FAT, $MFT, others) and exclude others (movies)