Добрый день, если не сложно кинте примерчик создания партиции, как создавать партицию на RAW диске мне ясно, но как ее создать на размеченном диске, с имеющемся не используемом пространстве? Если не сложно можно примером =) спасибо.
А что мешает просто добавить еще одну запись в таблицу разделов (partition table) MBR? Просто нужно вычислить неиспользуемый кусок на диске (в секторах), а потом записать начало и конец в таблицу (в LBA и CHS). Или я не так понял? Как ты создаешь партицию на RAW диске?
Вот так Код (Text): #define _WIN32_WINNT 0x500 #include <windows.h> #include<Winioctl.h> #include<vector> #include<iostream> #include<shlobj.h> #include <stdio.h> #include "tchar.h" using namespace std; //#define _WIN32_WINNT 0x0501 #include <string> #include<iostream> #include "fmifs.h" #define _UNICODE 1 #define BUFSIZE MAX_PATH #define FILESYSNAMEBUFSIZE MAX_PATH BOOL Error = FALSE; PFORMATEX FormatEx; PENABLEVOLUMECOMPRESSION EnableVolumeCompression; wstring temp; wstring temp1; //---------------------------------------------------------------------- // // FormatExCallback // // The file system library will call us back with commands that we // can interpret. If we wanted to halt the chkdsk we could return FALSE. // //---------------------------------------------------------------------- int get_next_free_drive_letter_orig( char *drv_letter) { DWORD ret = 0; short index = 25; if (drv_letter == NULL) { goto out; } if ((ret = GetLogicalDrives()) != 0) { printf("the ret value is %x\n",ret); for (index = 25; index >= 0; index--) { cout<<"the index is "<<index<<endl; if ((1 << index) & ~ret) { drv_letter[0] = (unsigned short)('A' + index); drv_letter[1] = (unsigned short)(':'); drv_letter[2] = (unsigned short)('\\'); drv_letter[3] = (unsigned short)(0); return 0; } } } memset((void *)drv_letter, 0 , 4 * sizeof (char)); out: return 0; } BOOLEAN __stdcall FormatExCallback( CALLBACKCOMMAND Command, DWORD Modifier, PVOID Argument ) { PDWORD percent; PTEXTOUTPUT output; PBOOLEAN status; static createStructures = FALSE; // // We get other types of commands, but we don't have to pay attention to them // switch( Command ) { case PROGRESS: percent = (PDWORD) Argument; wprintf(L"%d percent completed.\r", *percent); wprintf(L"in progress \n"); break; case OUTPUT: output = (PTEXTOUTPUT) Argument; fprintf(stdout, "%s", output->Output); wprintf(L"in output \n"); break; case DONE: status = (PBOOLEAN) Argument; if( *status == FALSE ) { wprintf(L"FormatEx was unable to complete successfully.\n\n"); Error = TRUE; wprintf(L"in done failure \n"); } else { Error = FALSE; wprintf(L"in done success \n"); } break; } return TRUE; } //---------------------------------------------------------------------- // // LoadFMIFSEntryPoints // // Loads FMIFS.DLL and locates the entry point(s) we are going to use // //---------------------------------------------------------------------- BOOLEAN LoadFMIFSEntryPoints() { LoadLibrary( "fmifs.dll" ); if( !(FormatEx = (PFORMATEX) GetProcAddress( GetModuleHandle( "fmifs.dll"), "FormatEx" )) ) { return FALSE; } if( !(EnableVolumeCompression = (PENABLEVOLUMECOMPRESSION) GetProcAddress( GetModuleHandle( "fmifs.dll"), "EnableVolumeCompression" )) ) { return FALSE; } return TRUE; } wstring str2tstr(const string &src) { wchar_t *dest; wstring temp; if(!src.length()){ return temp; } size_t iSize = mbstowcs(NULL, src.c_str(), 0); int destSize = (int)((iSize+1)* sizeof(wchar_t)); dest = (wchar_t *)malloc(destSize); iSize = mbstowcs(dest, src.c_str(), iSize+1); temp = dest; free(dest); return temp; } int get_next_free_drive_letter( char *drv_letter, vector<const wchar_t *> &ignoreVolumes) { DWORD ret = 0; short index = 25; if (drv_letter == NULL) { goto out; } UINT mediatype; char Target[BUFSIZE]; if ((ret = GetLogicalDrives()) != 0) { printf("the ret value is %x\n",ret); for (index = 25; index >= 0; index--) { cout<<"the index is "<<index<<endl; if ((1 << index) & ~ret) { drv_letter[0] = (unsigned short)('A' + index); drv_letter[1] = (unsigned short)(':'); drv_letter[2] = (unsigned short)('\\'); drv_letter[3] = (unsigned short)(0); } else { drv_letter[0] = (unsigned short)('A' + index); drv_letter[1] = (unsigned short)(':'); drv_letter[2] = (unsigned short)('\\'); drv_letter[3] = (unsigned short)(0); mediatype = GetDriveType(drv_letter); if (mediatype == DRIVE_FIXED) { printf("the drive letter is fixed %s \n",drv_letter); } if (mediatype == DRIVE_CDROM) { printf("the drive letter is cdrom %s \n",drv_letter); GetVolumeNameForVolumeMountPoint(drv_letter, // input volume mount point or directory Target, // output volume name buffer BUFSIZE // size of volume name buffer ); temp = str2tstr(Target); wprintf(L"we are pushing %s \n",temp.c_str()); ignoreVolumes.push_back(temp.c_str()); printf("the volume under it is %s \n",Target); } if (mediatype == DRIVE_REMOVABLE) { printf("the drive letter is removable %s \n",drv_letter); GetVolumeNameForVolumeMountPoint(drv_letter, // input volume mount point or directory Target, // output volume name buffer BUFSIZE // size of volume name buffer ); temp1 = str2tstr(Target); wprintf(L"we are pushing %s \n",temp1.c_str()); ignoreVolumes.push_back(temp1.c_str()); printf("the volume under it is %s \n",Target); } } } } memset((void *)drv_letter, 0 , 4 * sizeof (char)); out: return 0; } void PrintWin32Error( PWCHAR Message, DWORD ErrorCode ) { LPVOID lpMsgBuf; FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, ErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (PWCHAR) &lpMsgBuf, 0, NULL ); wprintf(L"%s: %s\n", Message, lpMsgBuf ); LocalFree( lpMsgBuf ); } // Process each mount point found here. This makes maintenance easier // than doing it in line. The result indicates whether there is // another mount point to be scanned. // This routine prints out the path to a mount point and its target. BOOL ProcessVolumeMountPoint (HANDLE hPt, wchar_t *PtBuf, DWORD dwPtBufSize, wchar_t *Buf) { BOOL bFlag; // Boolean result wchar_t Path[BUFSIZE]; // construct a complete path here wchar_t Target[BUFSIZE]; // target of mount at mount point printf (TEXT("\tVolume mount point found is \"%s\"\n"), PtBuf); // Detect the volume mounted at the mount point. // Build a unique path to the mount point. wcscpy(Path, Buf); wcscat(Path, PtBuf); wstring pathvar(Path); wstring ptbuf(PtBuf); bFlag = GetVolumeNameForVolumeMountPointW( pathvar.c_str(), // input volume mount point or directory Target, // output volume name buffer BUFSIZE // size of volume name buffer ); if (!bFlag) printf (TEXT("\tAttempt to get volume name for " "%s failed.\n"), Path); else printf (TEXT("\tTarget of the volume mount point " "is %s.\n"), Target); // Now, either get the next mount point and return it, or return a // value indicating there are no more mount points. bFlag = FindNextVolumeMountPointW( hPt, // handle to scan Path, // pointer to output string dwPtBufSize // size of output buffer ); return (bFlag); } finddiskextents(wchar_t *Buf) { //std::wstring wname(node->fid_objid->vid_name); wchar_t MyBuf[4096]; wcscpy(MyBuf, Buf); std::wstring wname(MyBuf); char drv_letter[256]; LPDWORD junk; DISK_GEOMETRY diskGeometry; HANDLE volumeHandle; MyBuf[wcslen(MyBuf)-1] = '\0'; wprintf (L"Volume found here is \"%s\".\n", MyBuf); try{ volumeHandle = CreateFileW(MyBuf, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); } catch(...) { return; } if (volumeHandle == INVALID_HANDLE_VALUE) { printf("invalid handle"); return; } BOOL flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device FSCTL_IS_VOLUME_MOUNTED, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) &junk, // number of bytes returned (LPOVERLAPPED) NULL // OVERLAPPED structure ); if (flag) return; static int MAX_DISK_EXTENTS = 32; bool tryagain(true); PVOLUME_DISK_EXTENTS extents = 0; while (tryagain) { DWORD size = sizeof(((PVOLUME_DISK_EXTENTS)0)->NumberOfDiskExtents); size += sizeof(DISK_EXTENT) * MAX_DISK_EXTENTS; extents = (PVOLUME_DISK_EXTENTS)malloc(size); if (extents == 0) { CloseHandle(volumeHandle); } memset(extents, 0, size); // // Try to get the extents of the volume, reallocating as needed // try{ DWORD bytesReturned; BOOL status = DeviceIoControl(volumeHandle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, extents, size, &bytesReturned, NULL); if (status == FALSE) { free(extents); } } catch(...) { PrintWin32Error( L"disk extents with error", GetLastError()); } tryagain = false; } CloseHandle(volumeHandle); try { for( DWORD i = 0; i < 1 ; i++ ) { wchar_t subObjName[4096] = {0}; if (extents->Extents[i].DiskNumber > 4096) { return; } //wprintf(L"\\\\.\\PHYSICALDRIVE%u", extents->Extents[i].DiskNumber); swprintf(subObjName,L"\\\\.\\PHYSICALDRIVE%u", extents->Extents[i].DiskNumber); if (!wcscmp(subObjName, L"\\\\.\\PHYSICALDRIVE4")) { wprintf(L"found the right volume %s and disk %s \n",Buf,subObjName); get_next_free_drive_letter_orig(drv_letter); wstring temp = str2tstr(drv_letter); int result = SetVolumeMountPointW(temp.c_str(),Buf); wprintf(L"the drive lettter is \n %s",temp.c_str()); printf("the result is %d \n",result); if( !LoadFMIFSEntryPoints()) { wprintf(L"Could not located FMIFS entry points.\n\n"); } wprintf(L"the vol sent to format is %s \n",MyBuf); FormatEx(MyBuf, FMIFS_HARDDISK, L"NTFS", L"", TRUE, 1024, FormatExCallback); PrintWin32Error( L"format with error", GetLastError()); } } } catch(...) { PrintWin32Error( L"printing extents with error", GetLastError()); } free(extents); extents = 0; } // Process each volume. This makes maintenance easier than doing it // in line. The Boolean result indicates whether there is another // volume to be scanned. BOOL ProcessVolume (HANDLE hVol, wchar_t *Buf, int iBufSize) { BOOL bFlag; // generic results flag for return HANDLE hPt; // handle for mount point scan wchar_t PtBuf[BUFSIZE]; // string buffer for mount points DWORD dwSysFlags; // flags that describe the file system wchar_t FileSysNameBuf[FILESYSNAMEBUFSIZE]; wchar_t *lpszVolumePathName; DWORD cchBufferLength; char drv_letter[256]; vector<const wchar_t *>ignoreVolumes; int found = 0; wprintf (L"Volume found is \"%s\".\n", Buf); get_next_free_drive_letter(drv_letter, ignoreVolumes); vector<const wchar_t *>::const_iterator itr; for (itr = ignoreVolumes.begin(); itr!=ignoreVolumes.end(); itr++) { wprintf(L"we got from vector guid %s \n",*itr); if (!wcscmp(*itr, Buf)) { found =1; wprintf(L"its floppy drive guid %s \n",*itr); printf("found floppy drive \n"); } if (!wcscmp(*itr, Buf)) { found = 1; wprintf(L"its CDrom drive guid %s\n",*itr); printf("found CDrom drive \n"); } } if (!found) finddiskextents(Buf); wstring buffer(Buf); // Determine if this volume uses an NTFS file system. GetVolumeInformationW(buffer.c_str(), NULL, 0, NULL, NULL, &dwSysFlags, FileSysNameBuf, FILESYSNAMEBUFSIZE); // Detect support for reparse points, and therefore for volume // mount points, which are implemented using reparse points. wprintf(L"the filesystem found is %s \n",FileSysNameBuf); if (! (dwSysFlags & FILE_SUPPORTS_REPARSE_POINTS)) { wprintf (L"\tThis file system does not support volume mount points.\n"); } else { // Start processing mount points on this volume. hPt = FindFirstVolumeMountPointW( Buf, // root path of volume to be scanned PtBuf, // pointer to output string BUFSIZE // size of output buffer ); if (hPt == INVALID_HANDLE_VALUE) { wprintf (L"\tNo volume mount points found!\n"); } else { // Process the volume mount point. bFlag = ProcessVolumeMountPoint(hPt, PtBuf, BUFSIZE, Buf); wprintf(L"the process volumemount point sent mtpt is %s\n",PtBuf); // Do while we have volume mount points to process. while (bFlag) bFlag = ProcessVolumeMountPoint(hPt, PtBuf, BUFSIZE, Buf); FindVolumeMountPointClose(hPt); } } // Stop processing mount points on this volume. bFlag = FindNextVolumeW( hVol, // handle to scan being conducted Buf, // pointer to output iBufSize // size of output buffer ); return (bFlag); } int enumeratevolumes(void) { wchar_t buf[BUFSIZE]; // buffer for unique volume identifiers HANDLE hVol; // handle for the volume scan BOOL bFlag; // generic results flag // Open a scan for volumes. hVol = FindFirstVolumeW(buf, BUFSIZE ); if (hVol == INVALID_HANDLE_VALUE) { printf (TEXT("No volumes found!\n")); return (-1); } // We have a volume; process it. bFlag = ProcessVolume (hVol, buf, BUFSIZE); // Do while we have volumes to process. while (bFlag) { bFlag = ProcessVolume (hVol, buf, BUFSIZE); } // Close out the volume scan. bFlag = FindVolumeClose( hVol // handle to be closed ); return (bFlag); } callmain() { SET_PARTITION_INFORMATION partinfn; CREATE_DISK crtdisk; PARTITION_INFORMATION_EX arraypartinfn_x[1]; PARTITION_INFORMATION arraypartinfn[1]; PARTITION_INFORMATION_EX arraypartinfnout_x[1]; DISK_GEOMETRY_EX diskGeometry_x; BOOL flag; FORMAT_PARAMETERS *fmtpar; DISK_GEOMETRY diskGeometry; LPDWORD lpBytesReturned; DWORD junk; DRIVE_LAYOUT_INFORMATION drivelayout; DRIVE_LAYOUT_INFORMATION_EX drivelayout_x; DRIVE_LAYOUT_INFORMATION driveoutparam; DRIVE_LAYOUT_INFORMATION_EX driveoutparam_x; //DISK_DETECTION_INFO disk_detect; //disk_detect //diskGeometry_x. fmtpar = (FORMAT_PARAMETERS *) malloc(sizeof(FORMAT_PARAMETERS)); memset(fmtpar, 0, sizeof(FORMAT_PARAMETERS)); memset(&drivelayout, 0, sizeof(DRIVE_LAYOUT_INFORMATION)); HANDLE volumeHandle = CreateFileW(L"\\\\.\\PHYSICALDRIVE4",GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (volumeHandle == INVALID_HANDLE_VALUE) { cout<<"error in opening device"; } PrintWin32Error( L"Create file with error", GetLastError()); flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device IOCTL_DISK_GET_DRIVE_GEOMETRY, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize (LPVOID) &diskGeometry, // output buffer (DWORD) sizeof(diskGeometry), // size of output buffer (LPDWORD) &lpBytesReturned, // number of bytes returned NULL // OVERLAPPED structure ); PrintWin32Error( L"get geometry with error", GetLastError()); partinfn.PartitionType = PARTITION_FAT32; crtdisk.PartitionStyle = PARTITION_STYLE_MBR; flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device IOCTL_DISK_CREATE_DISK, // dwIoControlCode (LPVOID) &crtdisk, // input buffer (DWORD) sizeof(CREATE_DISK), // size of input buffer NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) &lpBytesReturned, // number of bytes returned (LPOVERLAPPED)NULL // OVERLAPPED structure ); PrintWin32Error( L"create disk with error ", GetLastError()); cout<<"no of bytes returned is "<<lpBytesReturned; cout<<flag; char * temp = new char[4096]; flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device IOCTL_DISK_GET_DRIVE_LAYOUT_EX, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize (LPVOID) temp, // output buffer (DWORD) 4096, // size of output buffer (LPDWORD) &lpBytesReturned, // number of bytes returned (LPOVERLAPPED) NULL // OVERLAPPED structure ); PrintWin32Error( L"get drive_x layout with error ", GetLastError()); cout<<flag; DRIVE_LAYOUT_INFORMATION_EX *ptr = (DRIVE_LAYOUT_INFORMATION_EX *)temp; cout<<"partcount"<<ptr->PartitionCount; cout<<"signature"<<ptr->Mbr.Signature; cout<<"partition style"<<ptr->PartitionEntry[0].PartitionStyle; cout<<"partitiontype "<<ptr->PartitionEntry[0].Mbr.PartitionType; arraypartinfn_x[0].PartitionNumber = 1; arraypartinfn_x[0].RewritePartition = true; arraypartinfn_x[0].StartingOffset.QuadPart = 0; arraypartinfn_x[0].PartitionLength.QuadPart = ((((diskGeometry.Cylinders.QuadPart * diskGeometry.TracksPerCylinder)* diskGeometry.SectorsPerTrack)) * diskGeometry.BytesPerSector); arraypartinfn_x[0].Mbr.BootIndicator = false; arraypartinfn_x[0].Mbr.RecognizedPartition = true; arraypartinfn_x[0].Mbr.HiddenSectors = 1; arraypartinfn_x[0].Mbr.PartitionType = PARTITION_FAT32; arraypartinfn_x[0].RewritePartition =1; arraypartinfn_x[0].PartitionStyle = PARTITION_STYLE_MBR; drivelayout_x.PartitionCount = 1; drivelayout_x.PartitionEntry[0] = arraypartinfn_x[0]; drivelayout_x.PartitionStyle = PARTITION_STYLE_MBR; DRIVE_LAYOUT_INFORMATION_MBR mbrlayout; mbrlayout.Signature = ptr->Mbr.Signature; drivelayout_x.Mbr = mbrlayout; flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device IOCTL_DISK_SET_DRIVE_LAYOUT_EX, // dwIoControlCode (LPVOID) &drivelayout_x, // input buffer (DWORD) sizeof(DRIVE_LAYOUT_INFORMATION_EX), // size of input buffer NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) &lpBytesReturned, // number of bytes returned (LPOVERLAPPED) NULL // OVERLAPPED structure ); PrintWin32Error( L"set drive_x layout with error ", GetLastError()); cout<<flag; VERIFY_INFORMATION verify; verify.Length = ((((diskGeometry.Cylinders.QuadPart * diskGeometry.TracksPerCylinder)* diskGeometry.SectorsPerTrack)) * diskGeometry.BytesPerSector); verify.StartingOffset.QuadPart = 0; flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device IOCTL_DISK_VERIFY, // dwIoControlCode (LPVOID) &verify, // input buffer (DWORD) sizeof(VERIFY_INFORMATION), // size of input buffer NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) &lpBytesReturned, // number of bytes returned (LPOVERLAPPED) NULL // OVERLAPPED structure ); PrintWin32Error( L"verify disk with error ", GetLastError()); cout<<flag; flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device IOCTL_DISK_UPDATE_PROPERTIES,// dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD)&lpBytesReturned, // lpBytesReturned (LPOVERLAPPED)NULL // lpOverlapped ); PrintWin32Error( L"update propertioes with error ", GetLastError()); cout<<flag; flag = DeviceIoControl( (HANDLE) volumeHandle, // handle to device IOCTL_DISK_UPDATE_PROPERTIES,// dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD)&lpBytesReturned, // lpBytesReturned (LPOVERLAPPED)NULL // lpOverlapped ); PrintWin32Error( L"update propertioes with error ", GetLastError()); cout<<flag; CloseHandle(volumeHandle); enumeratevolumes(); } main() { do{ callmain(); if (Error) Sleep(240000); }while(Error); }
Так в чем проблема? Получай число разделов на диске и информацию о каждом, вычисляй неиспользуемую область на диске и создавай новый раздел. P. S. IMHO проще без всяких Windows все делать. Либо из Dos, либо с загрузочной дискеты - гораздо проще. Или, в конце концов, если совсем лень, так через WinHex вручную всю эту фигню проделать.
Вообщем делаю примерно так, но что-то не работает.... кто подскажет где лажаю? Код (Text): hDeviceOld = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); DRIVE_LAYOUT_INFORMATION* lpdlDriveLayoutInfo = NULL; lpdlDriveLayoutInfo = (DRIVE_LAYOUT_INFORMATION*)malloc(10); BOOL dev = DeviceIoControl( hDeviceOld, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, lpdlDriveLayoutInfo, 10, (LPDWORD) &dwRet, NULL); int t0 =lpdlDriveLayoutInfo->PartitionEntry[0].RecognizedPartition; LONGLONG mysize0 = 0; if(t0!=NULL) { mysize0=lpdlDriveLayoutInfo->PartitionEntry[0].PartitionLength.QuadPart; } int t1 =lpdlDriveLayoutInfo->PartitionEntry[1].RecognizedPartition; if(t1!=NULL) { mysize0 = mysize0+lpdlDriveLayoutInfo->PartitionEntry[1].PartitionLength.QuadPart; } int t2 =lpdlDriveLayoutInfo->PartitionEntry[2].RecognizedPartition; if(t2!=NULL) { mysize0 = mysize0+lpdlDriveLayoutInfo->PartitionEntry[2].PartitionLength.QuadPart; } int t3 =lpdlDriveLayoutInfo->PartitionEntry[3].RecognizedPartition; if(t3!=NULL) { mysize0 = mysize0+lpdlDriveLayoutInfo->PartitionEntry[3].PartitionLength.QuadPart; } DeviceIoControl( hDeviceOld , IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, (LPVOID) &diskGeometry, (DWORD) sizeof(diskGeometry), (LPDWORD) &lpBytesReturned, NULL ); LONGLONG fullsizedisk = diskGeometry.Cylinders.QuadPart*diskGeometry.SectorsPerTrack*diskGeometry.TracksPerCylinder*diskGeometry.BytesPerSector; LONGLONG emtrysizeondisk = fullsizedisk - mysize0; lpdlDriveLayoutInfo->PartitionEntry[3].BootIndicator = false; lpdlDriveLayoutInfo->PartitionEntry[3].HiddenSectors = lpdlDriveLayoutInfo->PartitionEntry[2].HiddenSectors; lpdlDriveLayoutInfo->PartitionEntry[3].PartitionLength.QuadPart = lpdlDriveLayoutInfo->PartitionEntry[2].PartitionLength.QuadPart; lpdlDriveLayoutInfo->PartitionEntry[3].PartitionNumber = 5; lpdlDriveLayoutInfo->PartitionEntry[3].PartitionType = lpdlDriveLayoutInfo->PartitionEntry[2].PartitionType; lpdlDriveLayoutInfo->PartitionEntry[3].RecognizedPartition = true; lpdlDriveLayoutInfo->PartitionEntry[3].RewritePartition = 1; lpdlDriveLayoutInfo->PartitionEntry[3].StartingOffset.QuadPart= lpdlDriveLayoutInfo->PartitionEntry[2].StartingOffset.QuadPart; lpdlDriveLayoutInfo->PartitionCount = 4; int tu = 0; tu = DeviceIoControl( hDeviceOld, // handle to device IOCTL_DISK_SET_DRIVE_LAYOUT, // dwIoControlCode &lpdlDriveLayoutInfo, // input buffer (DWORD) sizeof(DRIVE_LAYOUT_INFORMATION), // size of input buffer NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) &dwRet, NULL); PrintWin32Error( L"set drive_x layout with error ", GetLastError()); tu = DeviceIoControl( hDeviceOld, // handle to device IOCTL_DISK_UPDATE_PROPERTIES,// dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD)&lpBytesReturned, // lpBytesReturned (LPOVERLAPPED)NULL // lpOverlapped ); PrintWin32Error( L"update propertioes with error ", GetLastError()); tu = DeviceIoControl( hDeviceOld, // handle to device IOCTL_DISK_UPDATE_PROPERTIES,// dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD)&lpBytesReturned, // lpBytesReturned (LPOVERLAPPED)NULL // lpOverlapped ); PrintWin32Error( L"update propertioes with error ", GetLastError()); CloseHandle(hDeviceOld);