ERROR_SHARING_VIOLATION
32 (0x20)
The process cannot access the file because it is being used by another process.
if hFile = INVALID_HANDLE_VALUE then Exit;
if readsecto(drive,strtoint(edit1.text),strtoint(edit2.text),pointer(buf))=0
then showmessage('Нет доступа');
--------------------------------------------------------------------------------------
function ReadSecto(drive:char;StartingSector, SectorCount: DWORD;
Buffer: Pointer; BytesPerSector: DWORD = 512): DWORD;
var
hFile: THandle;
br,TmpLo,TmpHi: DWORD;
begin
Result := 0;
hFile := CreateFile(PChar('\\.\'+Drive+':'),
GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hFile = INVALID_HANDLE_VALUE then Exit;
TmpLo := __Mul(StartingSector,BytesPerSector,TmpHi);
if SetFilePointer(hFile,TmpLo,@TmpHi,FILE_BEGIN) = TmpLo then
begin
SectorCount := SectorCount*BytesPerSector;
if ReadFile(hFile,Buffer^,SectorCount,br,nil) then Result := br;
end;
CloseHandle(hFile);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
b,c:integer;
begin
form1.hide;
b:=1; c:=16; j:=3;
form2.StringGrid1.RowHeights[0]:=0;
form2.StringGrid1.ColWidths[0]:=0;
ReadSectors1(DriveComboBox1.Drive,0,1,@buf[0]);
form2.ValueListEditor1.Cells[1,1]:= inttostr(strtoint('$'+inttohex(buf[$10],2)));
form2.ValueListEditor1.Cells[2,2]:= inttostr(strtoint('$'+ inttohex(buf[$27],2)+ inttohex(buf[$26],2)+ inttohex(buf[$25],2)+ inttohex(buf[$24],2)));
form2.ValueListEditor1.Cells[3,3]:= inttostr(strtoint('$'+ inttohex(buf[$2F],2)+ inttohex(buf[$2E],2)+ inttohex(buf[$2D],2)+ inttohex(buf[$2C],2)));
form2.ValueListEditor1.Cells[4,4]:= inttostr(strtoint('$'+inttohex(buf[$F],2)+ inttohex(buf[$e],2)));
form2.ValueListEditor1.Cells[5,5]:= chr(buf[$52])+ chr(buf[$53])+chr(buf[$54])+chr(buf[$55])+chr(buf[$56])+chr(buf[$57])+chr(buf[$58])+chr(buf[$59]);
ReadSectors(DriveNumber,0,1,@buf[0]);
form2.ValueListEditor1.Cells[6,6]:=inttostr((strtoint('$'+ inttohex(buf[$1C9],2)+ inttohex(buf[$1C8],2)+ inttohex(buf[$1C7],2)+ inttohex(buf[$1C6],2)))+strtoint(form2.ValueListEditor1.Cells[4,4]));
form2.ValueListEditor1.Cells[7,7]:=intToStr(strtoint(form2.ValueListEditor1.Cells[6,6])+ strtoint(form2.ValueListEditor1.Cells[2,2]));
form2.ValueListEditor1.Cells[8,8]:=intToStr(strtoint(form2.ValueListEditor1.Cells[7,7])+strtoint(form2.ValueListEditor1.Cells[2,2]));
Sector1:=strtoint(form2.ValueListEditor1.Cells[6,6]);
ReadSectors(DriveNumber,Sector1,1,@buf[0]);
For i:=b to c do
begin
for k:=1 to 8 do
begin
form2.StringGrid1.Cells[k,i]:=IntToHex(buf[j],2)+IntToHex(buf[j-1],2)+IntToHex(buf[j-2],2)+IntToHex(buf[j-3],2);
j:=j+4;
end;
end;
Form2.button4.Visible:=false;
Form2.Show;
end;
function ReadSectors1(DriveNumber: char; StartingSector, SectorCount: DWORD;
Buffer: Pointer; BytesPerSector: DWORD = 512): DWORD;
var
hFile: THandle;
br,TmpLo,TmpHi: DWORD;
begin
Result := 0;
hFile := CreateFile(PChar('\\.\'+DriveNumber+':'),
GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hFile = INVALID_HANDLE_VALUE then Exit;
TmpLo := __Mul(StartingSector,BytesPerSector,TmpHi);
if SetFilePointer(hFile,TmpLo,@TmpHi,FILE_BEGIN) = TmpLo then
begin
SectorCount := SectorCount*BytesPerSector;
if ReadFile(hFile,Buffer^,SectorCount,br,nil) then Result := br;
end;
CloseHandle(hFile);
end;
function ReadSectors(DriveNumber: Byte; StartingSector, SectorCount: DWORD;
Buffer: Pointer; BytesPerSector: DWORD = 512): DWORD;
var
hFile: THandle;
br,TmpLo,TmpHi: DWORD;
begin
Result := 0;
hFile := CreateFile(PChar('\\.\PhysicalDrive'+IntToStr(DriveNumber)),
GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hFile = INVALID_HANDLE_VALUE then Exit;
TmpLo := __Mul(StartingSector,BytesPerSector,TmpHi);
if SetFilePointer(hFile,TmpLo,@TmpHi,FILE_BEGIN) = TmpLo then
begin
SectorCount := SectorCount*BytesPerSector;
if ReadFile(hFile,Buffer^,SectorCount,br,nil) then Result := br;
end;
CloseHandle(hFile);
end;
На виртуалке при установке винды фат32 выбирал, да и в свойствах диска тоже она, так что вроде все правильно
И в свойствах флешки тоже фат32, но все равно ошибка...
Может это уже ОС защищает диск как-то, эксклюзивное право или еще что