bolt/meta.go

50 lines
1.0 KiB
Go
Raw Normal View History

2014-01-08 15:06:17 +00:00
package bolt
2014-01-10 14:32:12 +00:00
var (
2014-01-27 15:11:54 +00:00
InvalidError = &Error{"Invalid database", nil}
VersionMismatchError = &Error{"version mismatch", nil}
2014-01-10 14:32:12 +00:00
)
2014-01-08 15:06:17 +00:00
2014-01-30 05:11:46 +00:00
const magic uint32 = 0xDEADC0DE
2014-01-12 05:51:01 +00:00
const version uint32 = 1
2014-01-10 14:32:12 +00:00
type meta struct {
2014-01-24 23:32:18 +00:00
magic uint32
version uint32
pageSize uint32
pgid pgid
2014-01-30 03:50:29 +00:00
free pgid
2014-01-30 23:22:02 +00:00
sys pgid
2014-01-30 05:11:46 +00:00
txnid txnid
2014-01-10 14:32:12 +00:00
}
// 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
}
2014-01-30 03:35:58 +00:00
// copy copies one meta object to another.
func (m *meta) copy(dest *meta) {
2014-01-30 23:22:02 +00:00
dest.magic = m.magic
dest.version = m.version
2014-01-30 03:35:58 +00:00
dest.pageSize = m.pageSize
dest.pgid = m.pgid
2014-01-30 23:22:02 +00:00
dest.free = m.free
2014-01-30 03:35:58 +00:00
dest.txnid = m.txnid
dest.sys = m.sys
}
2014-01-30 23:22:02 +00:00
// write writes the meta onto a page.
func (m *meta) write(p *page) {
// Page id is either going to be 0 or 1 which we can determine by the Txn ID.
p.id = pgid(m.txnid % 2)
p.flags |= p_meta
m.copy(p.meta())
}