MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / DB_Wrap

Method DB_Wrap

tools/comdb2ar/db_wrap.cpp:29–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29DB_Wrap::DB_Wrap(const std::string& filename) : m_filename(filename)
30{
31 // This comes straight from pgdump - can't ask berkeley to do this
32 // because db might be encrypted and we don't have passwd
33 uint8_t meta_buf[DBMETASIZE];
34 int fd = open(filename.c_str(), O_RDONLY);
35 size_t n = read(fd, meta_buf, DBMETASIZE);
36 if (n == -1) {
37 perror("read");
38 }
39 close(fd);
40 DBMETA *meta = (DBMETA *)meta_buf;
41 bool swapped = false;
42 uint32_t flags = meta->flags;
43 uint32_t magic = meta->magic;
44 uint32_t pagesize = meta->pagesize;
45again: switch (magic) {
46 case DB_BTREEMAGIC:
47 if (LF_ISSET(BTM_RECNO))
48 m_type = DB_RECNO;
49 else
50 m_type = DB_BTREE;
51 break;
52 case DB_HASHMAGIC:
53 m_type = DB_HASH;
54 break;
55 case DB_QAMMAGIC:
56 m_type = DB_QUEUE;
57 break;
58 default:
59 if (swapped) {
60 std::ostringstream ss;
61 ss << filename << ": bad meta page type 0x" << std::hex << magic << std::endl;
62 throw Error(ss);
63 }
64 swapped = true;
65 magic = myflip(magic);
66 flags = myflip(flags);
67 pagesize = myflip(pagesize);
68 goto again;
69 }
70 m_swapped = swapped;
71 m_metaflags = meta->metaflags;
72 m_crypto = meta->encrypt_alg;
73 m_pagesize = pagesize;
74}
75
76size_t DB_Wrap::get_pagesize() const
77{

Callers

nothing calls this directly

Calls 2

ErrorClass · 0.85
myflipFunction · 0.85

Tested by

no test coverage detected