HANDLE hDoc=INVALID_HANDLE_VALUE;
//output、input record for Bindary partition
flOutputStatusRecord outputStatusRecord;
flBDKOperationInput bdkOperationInput;
//output、input record for Disk partition
flReadWriteInputFH readWriteInput;
flReadWriteOutput readWriteOutput;
flMountInputFH mountInput;
flOutputStatusRecord outputStatusRecord;
DWORD bytesReturned;
//open DOC driver
hDoc = CreateFile(L"DSK6:",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0);
if (INVALID_HANDLE_VALUE == hDoc)
{
return 0;
}
//Read Bindary partition=================================
// Initialize for BDK read
bdkOperationInput.type = BDK_INIT_READ;
bdkOperationInput.partitionNumber = 1;
bdkOperationInput.bdkStruct.startingBlock = UnitNumber;
bdkOperationInput.bdkStruct.length = kDocBlockSize;
bdkOperationInput.bdkStruct.oldSign[0] = 'B';
bdkOperationInput.bdkStruct.oldSign[1] = 'I';
bdkOperationInput.bdkStruct.oldSign[2] = 'P';
bdkOperationInput.bdkStruct.oldSign[3] = 'O';
bdkOperationInput.bdkStruct.signOffset = 8;
if (!DeviceIoControl(hDoc, FL_IOCTL_BDK_OPERATION, &bdkOperationInput, sizeof(bdkOperationInput), &outputStatusRecord, sizeof(outputStatusRecord), &bytesReturned, NULL))
{
return 0;
}
//Read BDK blocks
bdkOperationInput.type = BDK_READ;
bdkOperationInput.partitionNumber = 1;
bdkOperationInput.bdkStruct.length = kDocBlockSize;
bdkOperationInput.bdkStruct.bdkBuffer = gBuffer;
if (!DeviceIoControl(hDoc, FL_IOCTL_BDK_OPERATION, &bdkOperationInput, sizeof(bdkOperationInput), &outputStatusRecord, sizeof(outputStatusRecord), &bytesReturned, NULL))
{
return 0;
}
//==============================================================
//Read Disk partition==========================================
// calling for FL_IOCTL_MOUNT_VOLUME_FH/FL_MOUNT
mountInput.partitionNumber = 0x2; //BDTL2
mountInput.type = FL_MOUNT;
if (!DeviceIoControl(hDoc, FL_IOCTL_MOUNT_VOLUME_FH,&mountInput,sizeof(mountInput),&outputStatusRecord,sizeof(outputStatusRecord), &bytesReturned, NULL))
{
return 0;
}
// calling for FL_IOCTL_WRITE_SECTORS_FH
readWriteInput.partitionNumber = 0x2; //BDTL2
readWriteInput.firstSector = 0;
readWriteInput.numberOfSectors = SectorNumber;
readWriteInput.buf = gBuffer;
if (!DeviceIoControl(hDoc, FL_IOCTL_READ_SECTORS_FH, &readWriteInput, sizeof(readWriteInput), &readWriteOutput, sizeof(readWriteOutput), &bytesReturned, NULL))
{
return 0;
}
//calling for FL_IOCTL_MOUNT_VOLUME_FH/FL_DISMOUNT
mountInput.type = FL_DISMOUNT;
if (!DeviceIoControl(hDoc, FL_IOCTL_MOUNT_VOLUME_FH,&mountInput,sizeof(mountInput),&outputStatusRecord,sizeof(outputStatusRecord), &bytesReturned, NULL))
{
return 0;
}
//===================================================================
//close Doc handle
if(hDoc)
{
CloseHandle(hDoc);
}
沒有留言:
張貼留言