Overlap.Offset =Offset.LowPart; //SetpositiontoOverlap.
Overlap.OffsetHigh=Offset.HighPart;
ReadFile(hVolume,Buffer,BootBlk.BytesPerSector,&ReadBytes,&Overlap);
if(ReadBytes!
=BootBlk.BytesPerSector){
printf("ReadSectorfailed:
%d:
%d:
%d\n",Offset.LowPart,Cnt*BootBlk.BytesPerSector,ReadBytes);
return;
}
Buffer=(UCHAR*)Buffer+BootBlk.BytesPerSector;
Offset.QuadPart+=BootBlk.BytesPerSector; //Updatethephysicalposition.
++CntIdx;
}
//}else{
//printf("Error%d...\n",GetLastError());
//}
}
return;
}
VOIDReadLCN(ULONGLONGLCN,ULONGCnt,PVOIDBuffer)
{
ReadSector(LCN*BootBlk.SectorsPerCluster,Cnt*BootBlk.SectorsPerCluster,Buffer);
}
VOIDWriteSector(ULONGLONGSector,ULONGCnt,PVOIDBuffer)
{
ULARGE_INTEGEROffset;
OVERLAPPEDOverlap={0};
ULONGWritten;
Offset.QuadPart =Sector*BootBlk.BytesPerSector;//Assignthephysicalposition.
Overlap.Offset =Offset.LowPart; //SetpositiontoOverlap.
Overlap.OffsetHigh=Offset.HighPart;
WriteFile(hVolume,Buffer,Cnt*BootBlk.BytesPerSector,&Written,&Overlap);
if(Written!
=Cnt*BootBlk.BytesPerSector)printf("Wrotefailed:
%d:
%d:
%d\n",Overlap.Offset,Cnt*BootBlk.BytesPerSector,Written);
}
VOIDWriteLCN(ULONGLONGLCN,ULONGCnt,PVOIDBuffer)
{
WriteSector(LCN*BootBlk.SectorsPerCluster,Cnt*BootBlk.SectorsPerCluster,Buffer);
}
VOIDZeroLCN(ULONGLONGLCN,ULONGCnt)
{
ULONGLONGZeroSectorNum=512;
BYTE*p512Sector=newBYTE[(UINT)BootBlk.BytesPerSector*(UINT)ZeroSectorNum];
ULONGLONGSectorNum=Cnt*(UINT)BootBlk.SectorsPerCluster;
ULONGLONGSectorSrtIdx=LCN*BootBlk.SectorsPerCluster,Idx;
ULONGLONGSectorEndIdx=SectorSrtIdx+SectorNum;
printf("->SectorStartIndex:
%d,ZeroSectornumberis%d\n",(UINT)SectorSrtIdx,(UINT)SectorNum);
memset(p512Sector,'0',(UINT)BootBlk.BytesPerSector*(UINT)ZeroSectorNum);
if(p512Sector){
Idx=SectorSrtIdx;
while((SectorNum>0)&&(ZeroSectorNum>0)){
printf("\n%3d--->",ZeroSectorNum);
for(;(Idx=ZeroSectorNum);Idx+=ZeroSectorNum){
WriteSector(Idx,(UINT)ZeroSectorNum,p512Sector);
SectorNum-=ZeroSectorNum;
printf(".");
}
ZeroSectorNum>>=1;
}
if(SectorNum){
assert(SectorNum==1);
WriteSector(Idx,1,p512Sector);
printf("\n%3d--->.",1);
}
printf("\n");
delete[]p512Sector;
}
}
ULONGAttributeLength(PATTRIBUTEAttr)
{
returnAttr->Nonresident==FALSE
?
PRESIDENT_ATTRIBUTE(Attr)->ValueLength
:
ULONG(PNONRESIDENT_ATTRIBUTE(Attr)->DataSize);
}
ULONGAttributeLengthAllocated(PATTRIBUTEAttr)
{
returnAttr->Nonresident==FALSE
?
PRESIDENT_ATTRIBUTE(Attr)->ValueLength
:
ULONG(PNONRESIDENT_ATTRIBUTE(Attr)->AllocatedSize);
}
ULONGRunLength(PUCHARRun)
{
return(*Run&0xf)+((*Run>>4)&0xf)+1;
}
ULONGLONGRunCount(PUCHARRun)
{
UCHARIdx=*Run&0xF; //GetEndIndex.
ULONGLONGCnt=0;
for(;Idx>0;Idx--)
Cnt=(Cnt<<8)+Run[Idx];
returnCnt;
}
LONGLONGRunLCN(PUCHARRun)
{
UCHARVCNNumEndIdx=*Run&0xf;