How to use DeviceIOControl with FSCTL_GET_VOLUME_BITMAP

Archived from groups: microsoft.public.win2000.file_system (More info?)

Hi All,

I need to check if there is the volume large enough to accept the entire
file, I need to save my file on continuous clusters.

So, I decide to use DeviceIOControl with FSCTL_GET_VOLUME_BITMAP, however, I
always get AccessViolation when printing GetLastError(), also I cannot get
the BITMAP.

Generally, I use the following:

hVolume = CreateFile("\\\\.\\f:",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);

stStartLCN.StartingLcn.QuadPart = 0;

bResult = DeviceIoControl(hVolume,
FSCTL_GET_VOLUME_BITMAP,
&stStartLCN,
sizeof(stStartLCN),
vbb,
sizeof(*vbb) + (512 * sizeof VOLUME_BITMAP_BUFFER)),

&junk,
(LPOVERLAPPED) NULL);

Also, how do I use vbb to check a continuous cluster space?

Any help will be highly appreciated. Thank you in advance for your time.

Sincerely,

bbdd
1 answer Last reply
More about deviceiocontrol fsctl_get_volume_bitmap
  1. Mr.....

    try this code.... I face some problems here...But it may be useful for u...
    And if u can solve my problems with code ,,,,,should reply...


    I'm trying to copy the used clusters of a hard disk partition(NTFS,windows os) to another partition.

    I used the "FSCTL_GET_VOLUME_BITMAP" to get the cluster usage details.And I'm getting the used and free cluster counts correctly.And the cluster number I got is continuous.This makes problem for me. I wanna copy the used clusters to a different partition.

    What type of cluster number I'm getting.? ; but the answer is correct.It makes confusion to me.the clusters may not be continuous so what the following program segment gives..??



    BOOL IsClusterUsed (UINT64 Cluster)
    {
    return ((BitmapDetail[Cluster / 32] & (1 << (Cluster % 32))) ? TRUE : FALSE);
    }


    STARTING_LCN_INPUT_BUFFER StartingLCN;
    VOLUME_BITMAP_BUFFER *Bitmap = NULL;
    UINT32 BitmapSize;
    DWORD BytesReturned1;
    BOOL Result;
    ULONGLONG ClusterCount = 0;

    StartingLCN.StartingLcn.QuadPart = 0;
    BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + 4;
    Bitmap = (VOLUME_BITMAP_BUFFER *) malloc (BitmapSize);

    Result = DeviceIoControl(
    h_MyDevice_src2,
    FSCTL_GET_VOLUME_BITMAP,
    &StartingLCN,
    sizeof (StartingLCN),
    Bitmap,
    BitmapSize,
    &BytesReturned1,
    NULL);

    if (Result == FALSE &&GetLastError()!= ERROR_MORE_DATA)
    {
    free (Bitmap);
    cout<<"\n bitmap error occured";
    goto label12;
    }

    ClusterCount = Bitmap->BitmapSize.QuadPart -
    Bitmap->StartingLcn.QuadPart;//TOT noof clusters
    cout<<"\n Tot no of clusters :"<<ClusterCount<<"\n";

    BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + (Bitmap->BitmapSize.QuadPart / 8) + 1;
    Bitmap = (VOLUME_BITMAP_BUFFER *) realloc (Bitmap, BitmapSize);

    Result = DeviceIoControl(
    h_MyDevice_src2,
    FSCTL_GET_VOLUME_BITMAP,
    &StartingLCN,
    sizeof (StartingLCN),
    Bitmap,
    BitmapSize,
    &BytesReturned,
    NULL);

    DWORD LastError = GetLastError ();
    if (Result == FALSE)
    {
    printf ("\nCouldn't properly read volume bitmap\n");
    free (Bitmap);
    goto label12;
    }
    BitmapDetail = (UINT32 *) malloc (sizeof(UINT32) * (1 + (ClusterCount / 32)));
    memcpy (BitmapDetail, Bitmap->Buffer, sizeof(UINT32) * (1 + (ClusterCount / 32)));


    UINT64 Max;
    UINT64 cc;
    Max=ClusterCount;
    UINT64 usedcluster=0;


    for (cc = 0; cc < Max; cc++)
    {

    if ( IsClusterUsed (cc)) // return 1 from buffer
    {
    // cluster used

    usedcluster=usedcluster+1;

    }
    }


    cout<<"\n Used no of clusters :"<<usedcluster<<"\n";

    ============================================================
    ============================================================
    Getting the total cluster counts correctly
    Getting the used cluster counts correctly
    while printing the used cluster number it shows continuous numbers....?? why...?

    I know.... Logical and virtual cluster numbers are there...Other than these original cluster number will be there....????

    Sometimes my question may be totally wrong.....

    with regards
    Krish
    Krishnampkkm@gmail.com
Ask a new question

Read More

File System Windows