X
xf47
Unregistered / Unconfirmed
GUEST, unregistred user!
我想在在WIN2000下进行一个物理硬盘到另一个物理硬盘的按磁道拷贝。但利用下面代码进行硬盘拷贝时,拷贝出的硬盘出现盘符与源盘不符(目标盘容量大于源盘容量),中文目录出现乱码的现象,请高手帮忙看一下代码那里有错误。<br>procedure TThread_Disk.ReadSector(DeviceNum,TagetNum,EndSector,BytesPerSector:integer);<br>var<br> SectorCount:integer;<br> SourceDriveChar;<br> TagetDrivechar;<br> str:string;<br> pchar;<br> SectorStart:integer;<br> repeatcount,i:integer;<br>begin<br> SectorCount:=256;//一次拷贝256个扇区<br> SourceDrive:=PChar('//./PHYSICALDRIVE'+IntToStr(DeviceNum));//源盘<br> TagetDrive:=PChar('//./PHYSICALDRIVE'+IntToStr(TagetNum));//目标盘<br> hDeviceHandle := CreateFile(SourceDrive, GENERIC_READ, //如果只是读扇区,可以用GENERIC_READ<br> FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);<br> tDeviceHandle:= CreateFile(TagetDrive, GENERIC_All,<br> FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);<br><br> if (hDeviceHandle <> INVALID_HANDLE_VALUE) and (tDeviceHandle <> INVALID_HANDLE_VALUE)then<br> begin<br> try<br> SectorStart:=0; //从第一个扇区开始<br> RepeatCount:=(EndSector-SectorStart) div SectorCount;<br> P:=allocmem(SectorCount*BytesPerSector); //申请256个扇区的内存空间<br> for i:=0 to repeatcount do<br> begin<br> FileSeek(hDevicehandle,SectorStart*BytesPerSector,0); //查找指定扇区数据<br> if FileRead(hDevicehandle,p[0],SectorCount*BytesPerSector)<>SectorCount*BytesPerSector then<br> Break; //如果读取数不对,停止 <br><br> FileSeek(tDevicehandle,SectorStart*BytesPerSector,0);<br> if FileWrite(tDevicehandle,p[0],SectorCount*BytesPerSector)<>SectorCount*BytesPerSector then<br> break; //如果写入数不对,停止<br> Inc(SectorStart,SectorCount);<br> end;<br> freemem(p,SectorCount*BytesPerSector);<br><br> //剩余的扇区不到256个扇区时候<br> repeatcount:=(EndSector-StartSector) mod SectorCount;<br> if repeatcount<>0 then<br> begin<br> P:=allocmem(repeatcount*BytesPerSector); //申请新的内存空间<br> FileSeek(hDevicehandle,SectorStart*BytesPerSector,0); //查找制定扇区数据<br> if FileRead(hDevicehandle,p[0],repeatcount*BytesPerSector)<>repeatcount*BytesPerSector then<br> begin<br> Exit;<br> end;<br> FileSeek(tDevicehandle,SectorStart*BytesPerSector,0);<br> if FileWrite(tDevicehandle,p[0],repeatcount*BytesPerSector)<>repeatcount*BytesPerSector then<br> begin<br> Exit;<br> end;<br> freemem(p,repeatcount*BytesPerSector);<br> end;<br><br> finally<br> closehandle(hDeviceHandle);<br> closehandle(tDeviceHandle);<br> end;<br>end;<br>end;