I have this macro defined in C++;
#define EXT_FIRST_EXTENT(__hdr__) \
((struct ext4_extent *) (((char *) (__hdr__)) + \
sizeof(struct ext4_extent_header)))
Where ext4_extent_header is a struct;
typedef struct ext4_extent_header {
uint16_t eh_magic; /* probably will support different formats */
uint16_t eh_entries; /* number of valid entries */
uint16_t eh_max; /* capacity of store in entries */
uint16_t eh_depth; /* has tree real underlying blocks? */
uint32_t eh_generation; /* generation of the tree */
}__attribute__ ((__packed__)) EXT4_EXTENT_HEADER;
And ext4_extent is also a struct;
typedef struct ext4_extent {
uint32_t ee_block; /* first logical block extent covers */
uint16_t ee_len; /* number of blocks covered by extent */
uint16_t ee_start_hi; /* high 16 bits of physical block */
uint32_t ee_start_lo; /* low 32 bits of physical block */
} __attribute__ ((__packed__)) EXT4_EXTENT;
This is my attempt at writing it in Delphi;
function Ext2Partition.EXT_First_Extent(hdr: PExt4_extent_header):PExt4_ExtEnt;
begin
Result := PExt4_ExtEnt(hdr + sizeof(ext4_extent_header));
end;
However the compiler tells me that the Operator not applicable to this operand type.
Here is my converted c++ struct to Delphi record's for both ext4_extent_header and ext4_extent;
Type
PExt4_extent_header = ^Ext4_extent_header;
Ext4_extent_header = REcord
eh_magic : Word;
eh_entries : Word;
eh_max : Word;
eh_depth : Word;
eh_generation : Cardinal;
End;
Type
PExt4_ExtEnt = ^Ext4_ExtEnt;
Ext4_ExtEnt = Record
ee_block : Cardinal;
ee_len : Word;
ee_start_hi : Word;
ee_start_low : Cardinal;
End;
Thanks!
Cardinal(hdr) + sizeof....ptrtoCardinaltype (or toUIntPtrtype for more convenience):Result := PExt4_ExtEnt(UIntPtr(hdr) + sizeof(ext4_extent_header));packed recordinstead ofrecordbecause__packed__directive in the source C code.