aboutsummaryrefslogtreecommitdiff
path: root/meta.go
blob: 6fa2df109325b7aa960dc258faf6aea54189a39e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package bolt

var (
	InvalidMetaPageError = &Error{"Invalid meta page", nil}
)

// TODO: #define mm_psize mm_dbs[0].md_pad
// TODO: #define mm_flags mm_dbs[0].md_flags

// TODO:
// typedef union MDB_metabuf {
// 	MDB_page	mb_page;
// 	struct {
// 		char		mm_pad[PAGEHDRSZ];
// 		MDB_meta	mm_meta;
// 	} mb_metabuf;
// } MDB_metabuf;

// TODO:
// typedef struct MDB_dbx {
// 	MDB_val		md_name;		/**< name of the database */
// 	MDB_cmp_func	*md_cmp;	/**< function for comparing keys */
// 	MDB_cmp_func	*md_dcmp;	/**< function for comparing data items */
// 	MDB_rel_func	*md_rel;	/**< user relocate function */
// 	void		*md_relctx;		/**< user-provided context for md_rel */
// } MDB_dbx;

const magic uint32 = 0xC0DEC0DE
const version uint32 = 1

type meta struct {
	magic   uint32
	version uint32
	free    bucket
	buckets bucket
	pgno    int
	txnid   int
}

// validate checks the marker bytes and version of the meta page to ensure it matches this binary.
func (m *meta) validate() error {
	if m.magic != magic {
		return InvalidError
	} else if m.version != Version {
		return VersionMismatchError
	}
	return nil
}

// Read the environment parameters of a DB environment before
// mapping it into memory.
// @param[in] env the environment handle
// @param[out] meta address of where to store the meta information
// @return 0 on success, non-zero on failure.
func (m *meta) read(p *page) error {
	/*
			if (off == 0 || m->mm_txnid > meta->mm_txnid)
				*meta = *m;
		}
		return 0;
	*/
	return nil
}