2007年6月20日 星期三

MDOC Read

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);
}

2007年6月1日 星期五

sort

1.Quick_sort

int a[7]; //input sequence
void main()
{
Quicksort(0,6);
}

Quicksort(int f, int l)
{
if f>=l then
{
return;
}

int X = a[f];
int i = f;
int j = l;
while i < j do
{
while a[j] >= X do
{
j = j-1;
}
a[i] = a[j];

while a[i] <= X do
{
i = i+1;
}
a[i] = a[j];

}
Quicksort(f, j-1);
Quicksort(j+1, l);
}

//============================

2.Straight_selection_sort


int a[7]; //input sequence
void main()
{
straight_selection_sort();
}

straight_selection_sort()
{
int i, j;
int x;
for( i = 0 ; i < 6 ; i ++)
{
for( j = i+1 ; j < 7 ; j++)
{
if( a[i] > a[j] )
{
x = a[i];
a[i] = a[j];
a[j] = x;
}
}
}
}