1

我在磁盘克隆上遇到问题。(即)克隆完成后,操作系统分区将作为 RAW 而不是 NTFS 文件系统出现。

我使用FSCTL_GET_VOLUME_BITMAP设备 IO 控制 API 来获取音量位图缓冲区。使用此卷位图,我只从源磁盘克隆了使用过的集群,并写入目标磁盘的相同偏移量。在空闲簇位置保持原样。

  1. 仅使用集群克隆会导致任何问题吗?

  2. 体积位图中的常驻和非常驻内容是否正确?因为我没有考虑非常驻属性。简单地说,我使用以下代码克隆了只使用过的集群。

  3. 我只在 Windows 服务器计算机上遇到这个问题。

请任何人提出解决我问题的方法。找到下面的代码片段。

查找使用过的集群

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

获取音量位图:

 STARTING_LCN_INPUT_BUFFER StartingLCN; 
            VOLUME_BITMAP_BUFFER *Bitmap = NULL; 
            ULONGLONG BitmapSize; 
            DWORD BytesReturned1; 
            BOOL Status; 
            ULONGLONG ClusterCount = 0;
            DWORD BytesReturned = 0;

            _tprintf(L"[%s %d]>>GetBitmap()volume Vol(%s)\n",
                            gpCFileName,
                            __LINE__,
                            i_VolumeName);

            if(ISNULL(o_BitmapBuffer) ||  ISNULL(o_Size))
            {
                _tprintf(L"[%s %d]>>GetBitmap()Input null open volume Vol(%s)\n",
                            gpCFileName,
                            __LINE__,
                            i_VolumeName);



                return -1;
            }

            HANDLE hFile=CreateFile(L"\\\\.\\C:",GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
            if(hFile == INVALID_HANDLE_VALUE) // this may happen if another program is already reading from disk
            {  
                LastError = ::GetLastError();

                INFOLOG(L"[%s %d]>>GetBitmap()-Unable to open volume Vol(%s) LError(0x%x)\n",
                            gpCFileName,
                            __LINE__,
                            i_VolumeName,
                            LastError);

                CloseHandle(hFile);



                return -1;
            }

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

            Bitmap = (VOLUME_BITMAP_BUFFER *) malloc ((size_t)BitmapSize); 
            LastError = ::GetLastError();
            if(ISNULL(Bitmap))
            {
                _tprintf(L"[%s %d]>>GetBitmap()-Couldn't properly read volume Bitmap Vol(%s) size(%d) LError(0x%x)\n",
                         gpCFileName,
                         __LINE__,
                         i_VolumeName,
                         (size_t)BitmapSize,
                         LastError);



                return -1;
            }

            Status = DeviceIoControl( hFile, FSCTL_GET_VOLUME_BITMAP, &StartingLCN, sizeof (StartingLCN), Bitmap, (DWORD)BitmapSize, &BytesReturned1, NULL); 
            LastError = ::GetLastError();
            if (Status == FALSE && LastError != ERROR_MORE_DATA) 
            { 
                SECURE_FREE(Bitmap); 
                _tprintf(L"[%s %d]>>GetBitmap()-Unable to get Bitmap Vol(%s) LError(0x%x)\n",
                         gpCFileName,
                         __LINE__,
                         i_VolumeName,
                        LastError);



                return -1;
            } 

            ClusterCount = Bitmap->BitmapSize.QuadPart - Bitmap->StartingLcn.QuadPart;//TOT noof clusters 

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

            //printf("Reallocate Memory \n");

            BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + ((Bitmap->BitmapSize.QuadPart) / i_SectorPerCluster) + 1; 

            Bitmap = (VOLUME_BITMAP_BUFFER *) realloc (Bitmap, (size_t)BitmapSize); 

            //cout<<"\n Realloc BitmapSize :"<<BitmapSize<<"\n";
            //cout<<"\n Realloc size_t BitmapSize :"<<(size_t)BitmapSize<<"\n";
            //cout<<"\n GetClusterSize :"<<this->GetClusterSize()<<"\n";

            Status = DeviceIoControl( hFile, FSCTL_GET_VOLUME_BITMAP, &StartingLCN, sizeof (StartingLCN), Bitmap, (DWORD)BitmapSize, &BytesReturned, NULL); 
            LastError = ::GetLastError(); 
            if (Status == FALSE) 
            { 
                _tprintf(L"[%s %d]>>GetBitmap()-Couldn't properly read volume Bitmap Vol(%s) Bytes(%ld) LError(0x%x)\n",
                         gpCFileName,
                         __LINE__,
                         i_VolumeName,
                         BytesReturned,
                         LastError);

                SECURE_FREE(Bitmap); 



                return -1;
            }

            ULONGLONG len = sizeof(UINT32) * (1 + (ClusterCount / 32));

            *o_BitmapBuffer = (PUINT)new BYTE[(size_t)len];
            memcpy (*o_BitmapBuffer, Bitmap->Buffer, ((size_t)(len)));
            *o_Size = (DWORD)len;

            SECURE_FREE(Bitmap);

            CloseHandle(hFile);
4

0 回答 0