WinAPI - Direct disk access

FAQ, getting help, user experience about PrimoCache
Post Reply
npelov
Level 6
Level 6
Posts: 60
Joined: Thu Jun 30, 2016 3:01 pm

WinAPI - Direct disk access

Post 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?
User avatar
Support
Support Team
Support Team
Posts: 3731
Joined: Sun Dec 21, 2008 2:42 am

Re: WinAPI - Direct disk access

Post 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
npelov
Level 6
Level 6
Posts: 60
Joined: Thu Jun 30, 2016 3:01 pm

Re: WinAPI - Direct disk access

Post 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)
Post Reply