Afternoon all,
I have been working on a Firebird Internals manual for some time, and it
was built with the help of a small tool I wrote to dump out specific
pages from a database. The structs for each page were blatantly copied
from jrd/ods.h and when I compiled my app back then (ahem, 2009!) my gcc
version was 4.1.2 and all worked fine.
On my own laptop I have gcc version 4.6.3 and I'm getting complete
garbage with the same source code.
I suspect I'm falling foul of some gcc alignment/padding thing and I'm
wondering if anyone could point me in the right direction?
At present I compile with a simple "gcc -o fbdump fbdump.c" and that's
the same on the old system and my laptop (exactly the same source.)
As an example of how wrong it can be, here's a Firebird 2.5 employee
page header showing all sorts of errors:
FBDUMP 1.00 - Firebird Page Dump Utility
Parameters : -v -p 0
Database: /var/lib/firebird/2.5/data/employee.fdb
DATABASE PAGE DETAILS - Page 0
PAGE HEADER
Page Type: 1
Flags: 0
Checksum: 12345
Generation: 0
SCN: 15033110528
Reserved: 2993592205312
PAGE DATA
Database Page Size: 698
ODS Version: 0
Pages: 240028567601152
Next Page: 348481045616
Oldest Transaction: 563031557799936
Oldest Active: 6291458
Next Transaction: 2997887172609
Sequence: 0
Flags: 0
Creation Date: COMING SOON
Attachment Id: 0
Shadow Count: 0
Implementation: 0
ODS minor: 0
ODS minororiginal: 0
HDR_END: 0
Page Buffers: 0
Bumped Transaction: 0
Oldest Snapshot: 0
Backup Pages: 0
A straight hexdump of the first page is as follows:
01 00 39 30 c8 02 00 00 00 00 00 00 00 00 00 00
0010 00 10 0b 80 03 00 00 00 00 00 00 00 b9 02 00 00
0020 ba 02 00 00 bb 02 00 00 00 00 82 01 4e da 00 00
0030 70 c4 16 23 51 00 00 00 00 00 00 00 13 00 02 00
0040 02 00 60 00 00 00 00 00 01 00 00 00 ba 02 00 00
0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
And finally, how the header page is defined in the utility:
// Page Header - on every page type.
typedef struct
{
SCHAR pag_type;
UCHAR pag_flags;
USHORT pag_checksum;
ULONG pag_generation;
ULONG pag_scn;
ULONG pag_reserved;
} pageHeader;
// Database Header page. Type 1.
typedef struct
{
pageHeader hdr_header;
USHORT hdr_page_size;
USHORT hdr_ods_version;
SLONG hdr_pages;
ULONG hdr_next_page;
SLONG hdr_oldest_transaction;
SLONG hdr_oldest_active;
SLONG hdr_next_transaction;
USHORT hdr_sequence;
USHORT hdr_flags;
SLONG hdr_creation_date[2];
SLONG hdr_attachment_id;
SLONG hdr_shadow_count;
SSHORT hdr_implementation;
USHORT hdr_ods_minor;
USHORT hdr_ods_minor_original;
USHORT hdr_end;
ULONG hdr_page_buffers;
SLONG hdr_bumped_transaction;
SLONG hdr_oldest_snapshot;
SLONG hdr_backup_pages;
SLONG hdr_misc[3];
UCHAR hdr_data[1];
} header_page;
I have tried adding __attribute__((packed)) and it makes no difference.
I suspect that it is something that changed between gcc versions I was
using and what I'm able to use now.
I appreciate that this might be off topic, if Helen thinks so, please
contact me direct. Ta.
Oh, I have the latest source code for firebird 2.5 and as far as I can
see, nothing has changed regarding the pages' structs.
Cheers,
Norm.
--
Norman Dunbar
Dunbar IT Consultants Ltd
Registered address:
Thorpe House
61 Richardshaw Lane
Pudsey
West Yorkshire
United Kingdom
LS28 7EL
Company Number: 05132767
--
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel