Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Apr : FSCTL_GET_VOLUME_BITMAP: Error 5, Access is denied.

www.cryer.info
Managed Newsgroup Archive

FSCTL_GET_VOLUME_BITMAP: Error 5, Access is denied.

Subject:FSCTL_GET_VOLUME_BITMAP: Error 5, Access is denied.
Posted by:"Ian Boyd" (ian.borlandnews0..@avatopia.com)
Date:Fri, 1 Apr 2005 13:53:13

Trying to use FSCTL_GET_VOLUME_BITMAP:
Error 5: Access is denied.

What gives?

const
    VOLUME_BITMAP_BYTES = 512; //bytes to retrieve
    VOLUME_BITMAP_SIZE = 2*SizeOf(LARGE_INTEGER)+VOLUME_BITMAP_BYTES;
var
    hDevice: THandle;
    bResult: Boolean;
    StartingBuffer: TStartingLcnInputBuffer;
    VolumeBitmap: PVolumeBitmapBuffer;
    nError: DWORD;
begin
    hDevice := CreateFile(
           '\.\D:',  // drive to open
           GENERIC_READ,                // no access to the drive
           FILE_SHARE_READ or FILE_SHARE_WRITE, // share mode
           nil,             // default security attributes
           OPEN_EXISTING,    // disposition
           0,                // file attributes
           0);            // do not copy file attributes}


    GetMem(VolumeBitmap, VOLUME_BITMAP_SIZE);
    StartingBuffer.StartingLcn.QuadPart := 0;
    StartingBuffer.BitmapSize.QuadPart := VOLUME_BITMAP_BYTES;

     bResult := DeviceIOControl(
              hDevice ,
              FSCTL_GET_VOLUME_BITMAP,
              @StartingBuffer,
              SizeOf(StartingBuffer),
              FVolumeBitmap,
              VOLUME_BITMAP_SIZE,
              BytesRead,
              nil);

    if (not bResult) then
    begin
        Log('Error '+IntToStr(nError)+': '+SysErrorMessage(nError));
        Exit;
    end;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive