不愿写了,COPY一段代码给你吧,可以参考一下^_^
TBPB = packed record
JMPCode: array[0..2] of BYTE; // * 引导跳转代码
System_ID: array[0..7] of CHAR; // * 厂商标志和版本号
SectorBytes: WORD; // * 每扇区字节数
SectorsPerCluster: BYTE; // * 每簇扇区数
ReservedSectors: WORD; // * 保留扇区数
NbrFat: BYTE; // * FAT的个数
RootEntry: WORD; // * 根目录项数
TotalSectors: WORD; // * 分区总扇区数(分区小于32M时)
Media: BYTE; // * 分区介质标识
SectorsPerFAT: WORD; // * 每个FAT占的扇区数
SectorsPerTrack: WORD; // * 每道扇区数
Heads: WORD; // * 磁头数
HiddenSectors: DWORD; // * 隐含扇区数
BigTotalSectors: DWORD; // * 分区总扇区数(分区大于32M时) * //*end of 23 Bytes*/
Drive: BYTE; // * 驱动器号
Head: BYTE; // * 磁头号
boot_rec_sig: BYTE; // * 含义未知
Vol_Serial_NoL: WORD; // * 磁盘序列号
Vol_Serial_NoH: WORD;
vlabel: array[0..10] of CHAR; // * 磁盘卷标号
FileSys_ID: array[0..7] of CHAR; // * 文件系统标识号
BootCode: array[0..449] of BYTE; // * 启动代码
end;
TParRec = packed record
bootid: byte;
beginh: byte;
beginsc: word;
filetype: byte;
endh: byte;
endsc: word;
forwsnum: DWORD;
totolsnum: DWORD;
end;
TDisk0 = packed record
Bootrecord: array[0..445] of byte;
ParRec: array[0..3] of TParRec;
AA55: WORD;
end;
TFileItem = packed record
index: integer;
startpos: int64;
nextpos: int64;
ParRec: array[0..3] of TParRec;
end;
TSDiskFile = packed record
Magic: DWORD; //$FFFF0001
FItem: array[0..17] of TFileItem;
EndFlag: DWORD; //$FFFF0001
end;
function SundyWriteFile(hFile: THANDLE; lpBuffer: Pointer; nNumberOfBytesToWrite: DWORD; lpNumberOfBytesWritten: PDWORD; lpOverlapped: Pointer): boolean; stdcall; external kernel32 name 'WriteFile';
Tcallbackfunc = procedure(var param: TDisk0; index: integer; Driveindex: int64);
function SundyFileWrite(Handle: Integer; Buffer: Pointer; Count: LongWord): Integer;
var
return: DWORD;
begin
return := Count;
if not SundyWriteFile(THandle(Handle), Buffer, Count, PDWORD(@return), nil) then
Result := -1
else
result := return;
end;
function _subfunc(hwnd: THandle; pos, rvpos: int64; callbackfunc: pointer; isc: boolean): boolean;
var
hpos, lpos: DWORD;
jpos, ipos, bpbpos: int64;
ptbuf: TDisk0;
bpb: TBpb;
i, j: integer;
begin
jpos := pos;
hpos := jpos div $FFFFFFFF;
lpos := jpos mod $FFFFFFFF;
ZeroMemory(@ptbuf, sizeof(TDisk0));
if SetFilePointer(hwnd, lpos, @hpos, 0) < lpos then
raise exception.Create('Partition Pointer Set Error.');
if FileRead(hwnd, ptbuf, sizeof(TDisk0)) = 0 then
raise exception.Create('Partition Read Error.');
if ptbuf.AA55 <> $AA55 then
raise exception.Create('Invalid Partition Format.');
i := 0;
while true do
begin
if ptbuf.ParRec.forwsnum = 0 then
break;
if (ptbuf.ParRec.filetype = $B) or
(ptbuf.ParRec.filetype = $C) or
(ptbuf.ParRec.filetype = $6) or
(ptbuf.ParRec.filetype = $E) then
begin
{bpbpos := ptbuf.ParRec.forwsnum;
bpbpos := bpbpos * 512;
bpbpos := jpos + bpbpos;
hpos := bpbpos div $FFFFFFFF;
lpos := bpbpos mod $FFFFFFFF;
ZeroMemory(@bpb, sizeof(bpb));
if SetFilePointer(hwnd, lpos, @hpos, 0) < lpos then
raise exception.Create('BPB Pointer Set Error.');
if FileRead(hwnd, bpb, sizeof(TBpb)) = 0 then
raise exception.Create('BPB Read Error.'); }
j := 0;
//j := bpb.Drive;
if assigned(callbackfunc) then
Tcallbackfunc(callbackfunc)(ptbuf, i, jpos);
end
else if (ptbuf.ParRec.filetype = $5) or
(ptbuf.ParRec.filetype = $F) then
begin
ipos := ptbuf.parRec.forwsnum;
ipos := ipos * sizeof(TDisk0);
if isc then
result := _subfunc(hwnd, ipos, rvpos, callbackfunc, false)
else
result := _subfunc(hwnd, ipos + rvpos, rvpos, callbackfunc, false);
end
else
begin
{bpbpos := ptbuf.ParRec.forwsnum;
bpbpos := bpbpos * 512;
bpbpos := jpos + bpbpos;
hpos := bpbpos div $FFFFFFFF;
lpos := bpbpos mod $FFFFFFFF;
ZeroMemory(@bpb, sizeof(bpb));
if SetFilePointer(hwnd, lpos, @hpos, 0) < lpos then
raise exception.Create('BPB Pointer Set Error.');
if FileRead(hwnd, bpb, sizeof(TBpb)) = 0 then
raise exception.Create('BPB Read Error.'); }
j := 0;
//showmessage(inttostr(sizeof(bpb)));
//j := bpb.Drive;
if assigned(callbackfunc) then
Tcallbackfunc(callbackfunc)(ptbuf, i, jpos);
end;
inc(i);
if i > 3 then break;
end;
result := true;
end;
function EnumPartition(callfunc: pointer): boolean;
var
hfile: THandle;
lagpos, rva: int64;
ptbuf: TDisk0;
begin
result := false;
hfile := CreateFile(pchar('//./PHYSICALDRIVE0'), GENERIC_ALL,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hfile = INVALID_HANDLE_VALUE then
raise Exception.Create('Partiton Information Read Error.');
lagpos := 0;
FileSeek(hfile, 0, 0);
ZeroMemory(@ptbuf, sizeof(TDisk0));
FileRead(hfile, ptbuf, sizeof(TDisk0));
rva := ptbuf.ParRec[1].forwsnum;
rva := rva * sizeof(TDisk0);
result := _subfunc(hfile, lagpos, rva, callfunc, true);
CloseHandle(hfile);
end;
var
partitonnum: integer = 0;
partinfo: array[0..17] of TParRec;
SysMenu: HMenu;
diskfile: TSDiskFile;
procedure callback(var param: TDisk0; index: integer; Driveindex: int64);
var
stype: string;
begin
stype := '未知类型';
case Param.ParRec[index].filetype of
$1, $4, $6, $E: stype := 'FAT16';
$B, $C: stype := 'FAT32';
$7: stype := 'NTFS';
$82: stype := 'Linux';
$83: stype := 'Linux Swap';
end;
SetForms.Memo1.Lines.Add('分区:' + inttostr(partitonnum + 1));
SetForms.Memo1.Lines.Add('启动标志: 0x' + inttohex(Param.ParRec[index].bootid, 2));
SetForms.Memo1.Lines.Add('格式类型: ' + stype);
SetForms.Memo1.Lines.Add('磁盘大小: ' + format('%0.2f', [param.ParRec[index].totolsnum / 2 / 1024 / 1024]) + ' G byte');
if not fExists then
begin
CopyMemory(Pointer(@diskfile.FItem[partitonnum].ParRec[0]), Pointer(@Param.ParRec[0].bootid), 4 * sizeof(TParRec));
diskfile.FItem[partitonnum].index := partitonnum;
diskfile.FItem[partitonnum].startpos := Driveindex;
diskfile.FItem[partitonnum].nextpos := 0;
end;
CopyMemory(pointer(@partinfo[partitonnum].bootid), Pointer(@Param.ParRec[index].bootid), sizeof(TParRec));
inc(partitonnum);
end;