I'm dealing with an USB storage device that contains a proprietary file system. So, I need to read these device's 512 bytes blocks to implement a viewer for this filesystem.
How should I go about this? Is there some material on it using Delphi?
I'm dealing with an USB storage device that contains a proprietary file system. So, I need to read these device's 512 bytes blocks to implement a viewer for this filesystem.
How should I go about this? Is there some material on it using Delphi?
I hate components so here is some code
var
RawMBR : array [0..511] of byte;
btsIO : DWORD;
begin
hDevice := CreateFile('\\.\PHYSICALDRIVE1', GENERIC_READ,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice <> INVALID_HANDLE_VALUE then
begin
SetFilePointer(hDevice,512 * 0,nil,FILE_BEGIN); // replace 0 with sector that you wish to read
ReadFile(hDevice, RawMBR[0], 512, btsIO, nil);
CloseHandle(hDevice);
end;
end;
Did you try RawDiskAccess component, source for Delphi 7 here
Read it just like any other disk when doing a raw read access. You just need the first sector
For Delphi you can look at:
http://www.torry.net/pages.php?id=253
Physical Disk Access (may work for you) Raw Disk Access (may work for you) TDiskIO (too old, works only under w9x)
We have RawDisk product which provides read and write access to raw partitions under XP, Vista and Windows 7 (there exist certain security restrictions when using Windows API and RawDisk lets you bypass those restrictions). Code is available for all versions of Delphi from Delphi 5 to Delphi XE (XE2 support will be added in a couple of days).