입출력 Control code를 사용하여 파티션 생성 및 포맷
3789 단어 Security
BOOL Result; // used to read bad DeviceIoControl calls
DWORD szReturned;
unsigned int SectorSize = 512;
LARGE_INTEGER DiskSize.QuadPart = 40007761920i64;
LARGE_INTEGER Part_1_size.QuadPart = 27406600704i64;
LARGE_INTEGER Part_2_size.QuadPart =40007761920i64-27406600704i64;
// Very important! Size correctly this structure. Even if there's only
// one primary partition, you MUST size the buffer to contain
// AT LEAST 4 PARTITION_INFORMATION_EX!
DWORD szNewLayout = sizeof(DRIVE_LAYOUT_INFORMATION_EX)+4*sizeof(PARTITION_INFOR MATION_EX);
DRIVE_LAYOUT_INFORMATION_EX *dl = (DRIVE_LAYOUT_INFORMATION_EX*) new BYTE[szNewLayout];
// Open handle to physical device
// NtCreateFile() function can be used too with "\\device\\harddisk1\\partiton0" path.
hDrive=CreateFile("\\\\.\\PhysicalDrive1",GENERIC_READ|GEN ERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, //default security attributes
OPEN_EXISTING, // disposition
0,// file attributes
NULL);
if(!hDrive){
// handle the error
}
CREATE_DISK disk;
ZeroMemory(&disk,sizeof(CREATE_DISK));
disk.PartitionStyle = PARTITION_STYLE_MBR;
disk.Mbr.Signature = 0xA4B57300;// the signature can be randomly generated
// Create primary partition MBR
Result = DeviceIoControl(hDrive,IOCTL_DISK_CREATE_DISK,&disk,size of(CREATE_DISK),NULL,0,&szReturned,NULL);
if(!Result){
// handle the error
}
DeviceIoControl(hDrive,IOCTL_DISK_UPDATE_PROPERTIES,
NULL,0,NULL,0,&szReturned,NULL);
//Setup drive layout
ZeroMemory(dl,szNewLayout);
dl->PartitionEntry[0].PartitionStyle = PARTITION_STYLE_MBR;
dl->PartitionEntry[0].StartingOffset.QuadPart = 32256;
dl->PartitionEntry[0].PartitionLength = Part_1_Size;
dl->PartitionEntry[0].PartitionNumber = 1;
dl->PartitionEntry[0].RewritePartition = TRUE;
dl->PartitionEntry[0].Mbr.PartitionType = 0x07;// PARTITION_IFS (NTFS partition or logical drive)
dl->PartitionEntry[0].Mbr.BootIndicator = TRUE;
dl->PartitionEntry[0].Mbr.RecognizedPartition = 1;
dl->PartitionEntry[0].Mbr.HiddenSectors=32256/SectorSize;
dl->PartitionEntry[1].PartitionStyle=PARTITION_STYLE_MBR;
dl->PartitionEntry[1].StartingOffset.QuadPart= Part_1_Size.QuadPart + 32256i64;
dl->PartitionEntry[1].PartitionLength = Part_2_Size;
dl->PartitionEntry[1].PartitionNumber=2;
dl->PartitionEntry[1].RewritePartition = TRUE;
dl->PartitionEntry[1].Mbr.PartitionType = 0x07;
dl->PartitionEntry[1].Mbr.RecognizedPartition = 1;
dl->PartitionEntry[1].Mbr.HiddenSectors = (32256i64+Part_1_Size.QuadPart)/SectorSize;
// set RewritePartition=true in every partition to force rewrite.
for (int item=0;item<4;item++)
dl->PartitionEntry[item].RewritePartition = 1;
// setup drive layout
dl->PartitionStyle = PARTITION_STYLE_MBR;
dl->PartitionCount = 4;// specify AT LEAST 4 partitions!!!
dl->Mbr.Signature = 0xA4B57300;
// Set layout
Result = DeviceIoControl(hDrive,IOCTL_DISK_SET_DRIVE_LAYOUT_EX,
& ; ;nbs p; dl,szNewLayout,NULL,0,& ; ; ;szReturned,NULL);
if(!Result)
throw Exception(WhatError());
// update disk properties
DeviceIoControl(hDrive,IOCTL_DISK_UPDATE_PROPERTIES,
NULL,0,NULL,0,&szReturned,NULL);
CloseHandle(hDrive);
delete dl;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
클립보드로 컨텐트 복사//txt参数为显示和复制的文本内容 function copyToBoard(txt) { if(window.clipboardData) { window.clipboardData.clearData(); window.clipb...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.