From: Michael Tremer Date: Sun, 7 Jan 2018 20:09:44 +0000 (+0000) Subject: database: Map network nodes section when opening the database X-Git-Tag: 0.9.0~122 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Flibloc.git;a=commitdiff_plain;h=f66b7b0965660ae80d9a0d88ce9f4baf5781e515 database: Map network nodes section when opening the database Signed-off-by: Michael Tremer --- diff --git a/src/database.c b/src/database.c index 07cb66c..b1eead6 100644 --- a/src/database.c +++ b/src/database.c @@ -46,6 +46,10 @@ struct loc_database { struct loc_database_as_v0* as_v0; size_t as_count; + // Network tree + struct loc_database_network_node_v0* network_nodes_v0; + size_t network_nodes_count; + struct loc_stringpool* pool; }; @@ -98,6 +102,26 @@ static int loc_database_read_as_section_v0(struct loc_database* db, return 0; } +static int loc_database_read_network_nodes_section_v0(struct loc_database* db, + FILE* f, off_t network_nodes_offset, size_t network_nodes_length) { + DEBUG(db->ctx, "Reading network nodes section from %jd (%zu bytes)\n", + network_nodes_offset, network_nodes_length); + + if (network_nodes_length > 0) { + db->network_nodes_v0 = mmap(NULL, network_nodes_length, PROT_READ, + MAP_SHARED, fileno(f), network_nodes_offset); + + if (db->network_nodes_v0 == MAP_FAILED) + return -errno; + } + + db->network_nodes_count = network_nodes_length / sizeof(*db->network_nodes_v0); + + INFO(db->ctx, "Read %zu network nodes from the database\n", db->network_nodes_count); + + return 0; +} + static int loc_database_read_header_v0(struct loc_database* db, FILE* f) { struct loc_database_header_v0 header; @@ -131,6 +155,15 @@ static int loc_database_read_header_v0(struct loc_database* db, FILE* f) { if (r) return r; + // Network Nodes + off_t network_nodes_offset = be32toh(header.network_tree_offset); + size_t network_nodes_length = be32toh(header.network_tree_length); + + r = loc_database_read_network_nodes_section_v0(db, f, + network_nodes_offset, network_nodes_length); + if (r) + return r; + return 0; } diff --git a/src/loc/format.h b/src/loc/format.h index a1c0ebd..2c7496b 100644 --- a/src/loc/format.h +++ b/src/loc/format.h @@ -49,7 +49,7 @@ struct loc_database_header_v0 { uint32_t network_data_offset; uint32_t network_data_length; - // Tells us where the network tree starts + // Tells us where the network nodes start uint32_t network_tree_offset; uint32_t network_tree_length;