Subject Re: [ib-support] 5.6 & gstat info (API).
Author Ann W. Harrison
Jason,

Gstat gets the db statistics by reading the header page
without going through the engine. All the interesting
information is in the first 1024 bytes of page 0 of the
database file. I've added the code below that describes
the header page. Open the database file for read-only,
read the first 1024 bytes and map them to a HDR structure.
I've got some examples, but they're all built into things
that provide open/read/write and it would take longer
to pick that apart than write the four lines of code
necessary...

Regards,

Ann


/* Basic page header */

typedef struct pag {
SCHAR pag_type;
SCHAR pag_flags;
USHORT pag_checksum;
ULONG pag_generation;
ULONG pag_seqno; /* WAL seqno of last update */
ULONG pag_offset; /* WAL offset of last update */
} *PAG;
/* Header page */

typedef struct hdr {
struct pag hdr_header;
USHORT hdr_page_size; /* Page size of database */
USHORT hdr_ods_version; /* Version of on-disk structure */
SLONG hdr_PAGES; /* Page number of PAGES relation */
ULONG hdr_next_page; /* Page number of next hdr page */
SLONG hdr_oldest_transaction; /* Oldest interesting transaction */
SLONG hdr_oldest_active; /* Oldest transaction thought active */
SLONG hdr_next_transaction; /* Next transaction id */
USHORT hdr_sequence; /* sequence number of file */
USHORT hdr_flags; /* Flag settings, see below */
SLONG hdr_creation_date [2]; /* Date/time of creation */
SLONG hdr_attachment_id; /* Next attachment id */
SLONG hdr_shadow_count; /* Event count for shadow synchronization */
SSHORT hdr_implementation; /* Implementation number */
USHORT hdr_ods_minor; /* Update version of ODS */
USHORT hdr_ods_minor_original; /* Update version of ODS at creation */
USHORT hdr_end; /* offset of HDR_end in page */
ULONG hdr_page_buffers; /* Page buffers for database cache */
SLONG hdr_bumped_transaction; /* Bumped transaction id for log
optimization */
SLONG hdr_oldest_snapshot; /* Oldest snapshot of active transactions */
SLONG hdr_misc [4]; /* Stuff to be named later */
UCHAR hdr_data [1]; /* Misc data */
} *HDR;

#define HDR_SIZE OFFSETA (HDR, hdr_data)
#define hdr_cache_file hdr_data

/* Header page clumplets */

/* Data items have the format

<type_byte> <length_byte> <data...>
*/

#define HDR_end 0
#define HDR_root_file_name 1 /* Original name of root file */
#define HDR_journal_server 2 /* Name of journal server */
#define HDR_file 3 /* Secondary file */
#define HDR_last_page 4 /* Last logical page number of file */
#define HDR_unlicensed 5 /* Count of unlicensed activity */
#define HDR_sweep_interval 6 /* Transactions between sweeps */
#define HDR_log_name 7 /* replay log name */
#define HDR_journal_file 8 /* Intermediate journal file */
#define HDR_password_file_key 9 /* Key to compare to password db */
#define HDR_backup_info 10 /* WAL backup information */
#define HDR_cache_file 11 /* Shared cache file */
#define HDR_max 11 /* Maximum HDR_clump value */

/* Header page flags */

#define hdr_active_shadow 0x1 /* 1 file is an active shadow file */
#define hdr_force_write 0x2 /* 2 database is forced write */
#define hdr_short_journal 0x4 /* 4 short-term journalling */
#define hdr_long_journal 0x8 /* 8 long-term journalling */
#define hdr_no_checksums 0x10 /* 16 don't calculate checksums */
#define hdr_no_reserve 0x20 /* 32 don't reserve space for versions */
#define hdr_disable_cache 0x40 /* 64 disable using shared cache file */
#define hdr_shutdown 0x80 /* 128 database is shutdown */
#define hdr_SQL_dialect_3 0x100 /* 256 database SQL dialect 3 */
#define hdr_read_only 0x200 /* 512 Database in ReadOnly. If not set, DB is
RW */