1

我需要澄清一下如何找到文件的最后一个簇。以下是一些关于我如何获取集群信息的代码片段。

hFile = CreateFile(result,                          
        GENERIC_READ | GENERIC_WRITE,   
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,                           
        OPEN_EXISTING,                  
        FILE_ATTRIBUTE_NORMAL,          
        NULL);          

while (error == ERROR_MORE_DATA){

    DWORD bytesReturned;

    returns = DeviceIoControl(hfile.hanFile,
        FSCTL_GET_RETRIEVAL_POINTERS,
        &startVcn,
        sizeof(startVcn),
        &output,
        sizeof(output),
        &bytesReturned,
        NULL);
    error = GetLastError();
    DWORD lastExtentN = retrievalBuffer->ExtentCount - 1;
LONGLONG lastExtent = retrievalBuffer->Extents[lastExtentN].Lcn.QuadPart;
LONGLONG lengthOfCluster = retrievalBuffer->Extents[lastExtentN].NextVcn.QuadPart - retrievalBuffer->Extents[lastExtentN - 1].NextVcn.QuadPart;         

switch (error){

    case ERROR_HANDLE_EOF:
        //file sizes 0-1kb will return EOF error 
        cout << "ERROR_HANDLE_EOF" << endl;
        returns = true;
        break;

    case ERROR_MORE_DATA:
        cout << "ERROR_MORE_DATA" << endl;
        startVcn.StartingVcn = retrievalBuffer->Extents[0].NextVcn; 

        case NO_ERROR:

    cout << "NO_ERROR, here is some info: " << endl 
    cout << "This is the lcnextent : "<<retrievalBuffer->Extents[lastExtentN].Lcn.QuadPart << endl;
    cout << "This is the nextvnc: " << retrievalBuffer->Extents[lastExtentN].NextVcn.QuadPart << endl;
    cout << "This is the Extent count: " << retrievalBuffer->ExtentCount << endl;
    cout << "This is the Starting Vnc" << retrievalBuffer->StartingVcn.QuadPart << endl;
    cout << " The length of the cluster is: " << lengthOfCluster << endl;
    cout << " The last cluster is: " << lastExtent + lengthOfCluster - 1 << endl << endl << endl;
            break;

        default:
            cout << "Error in the code or input error" << endl;
            break;
        }
}

我不确定我是否找到了正确的集群。为了找到最后一个集群,我首先找到了最后一个集群的大小Extents[lastExtentN].NextVcn.QuadPart-Extents[lastExtentN - 1].NextVcn.QuadPart然后我找到了Extents[lastExtentN].Lcn.QuadPart+ lengthOfCluster- 1 的位置。例如,在我的输出中,我得到:

This is the lcnextent : 76638
This is the nextvnc: 285
This is the Extent count: 3
This is the Starting Vnc 0
The length of the cluster is: 1
The last cluster is: 76638

我的代码和输出有意义吗?输出的数字是否以字节为单位?

4

0 回答 0