From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "identification" |
|---|
| subject | "Format:LMDB database file" |
|---|
| claim | "mdb_env_read_header (mdb.master3 source) treats a file as LMDB only if each of pages 0 and 1 has the P_META flag (0x08), mm_magic == 0xBEEFC0DE and mm_version == MDB_DATA_VERSION (3; 999 when MDB_DEVEL). Ordinary opens read sizeof(MDB_metabuf) bytes with pread/ReadFile at offset 0 and then at offset mm_psize of the first meta; an empty file gives MDB_NO_META, any other short read MDB_INVALID, a missing P_META flag MDB_INVALID, a bad magic MDB_INVALID and a different data version MDB_VERSION_MISMATCH. A separate memory-mapped branch runs only when the environment has MDB_RAWPART (raw partition) set, and there a missing P_META gives MDB_NO_META. The meta with the larger mm_txnid is the live one (the smaller when reading the backup meta with prev)." |
|---|
| scope | | level | "format" |
|---|
| applies_to | "Format:LMDB database file" |
|---|
| observed_in | |
|---|
|
|---|
| data | | method | "read both meta pages (pread at 0 and at the first meta's mm_psize) and compare flags, magic, version, txnid" |
|---|
| indicator | "page flags & 0x08 (P_META); u32 at body start == 0xBEEFC0DE (DE C0 EF BE little-endian); next u32 == 3 on mdb.master3 (MDB_DEVEL builds 999)" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "Loop over NUM_METAS: F_ISSET(mp_flags, P_META), magic, version checks, then keeps the meta with the higher mm_txnid (lower when reading the backup meta with prev)." |
|---|
| repo | "https://github.com/LMDB/lmdb" |
|---|
| commit | "253ba5219172531b719bc14fee6b4aa1a2a5c4a5" |
|---|
| path | "libraries/liblmdb/mdb.c" |
|---|
| lines | "4707-4789" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "LMDB env header checks" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-19T11:32:06.994Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T13:17:32.732Z" |
|---|
| result | "confirmed" |
|---|
| method | "Read mdb_env_read_header in liblmdb/mdb.c 4698-4790 at 253ba52 plus MDB_MAGIC 0xBEEFC0DE and MDB_DATA_VERSION ((MDB_DEVEL)?999:3): RAWPART mmap branch vs pread branch, NO_META only for an empty first read, INVALID for short read / missing P_META / bad magic, VERSION_MISMATCH, txnid selection with prev. Matches." |
|---|
|
|
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T11:38:59.782Z" |
|---|
| summary | "The memory-mapped branch of mdb_env_read_header runs only for MDB_RAWPART (raw partition) environments, not for ordinary opens; ordinary opens use pread/ReadFile of sizeof(MDB_metabuf) bytes at…" |
|---|
| changed | |
|---|
|
|
|---|