1 /*
2 * Copyright (c) 2012-2013 Spotify AB
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16 #ifndef SPARKEY_LOGHEADER_H_INCLUDED
17 #define SPARKEY_LOGHEADER_H_INCLUDED
18 
19 #include <stdint.h>
20 
21 #include "sparkey.h"
22 
23 #define LOG_MAGIC_NUMBER (0x49b39c95)
24 #define LOG_MAJOR_VERSION (1)
25 #define LOG_MINOR_VERSION (0)
26 #define LOG_HEADER_SIZE (84)
27 
28 typedef struct {
29   uint32_t major_version;
30   uint32_t minor_version;
31   uint32_t file_identifier;
32   uint64_t num_puts;
33   uint64_t num_deletes;
34   uint64_t data_end;
35   uint64_t max_key_len;
36   uint64_t max_value_len;
37   uint64_t delete_size;
38   sparkey_compression_type compression_type;
39   uint32_t compression_block_size;
40   uint64_t put_size;
41   uint32_t header_size;
42   uint32_t max_entries_per_block;
43 } sparkey_logheader;
44 
45 /**
46  * fills up a logheader struct based on the contents at the beginning of the file.
47  * @param header header struct to fill
48  * @param filename a log file
49  * @returns an error code if it could not load the file.
50  */
51 sparkey_returncode sparkey_load_logheader(sparkey_logheader *header, const char *filename);
52 
53 /**
54  * Dumps a human readable representation of the header to stdout
55  * @param header an initialized header struct
56  */
57 void print_logheader(sparkey_logheader *header);
58 
59 /**
60  * Writes a header to the current position in the file
61  * @param fd a file descripter pointing to a file open for writing
62  * @param header the header to write
63  * @returns an error code if it could not write to file.
64  */
65 sparkey_returncode write_logheader(int fd, sparkey_logheader *header);
66 
67 #endif
68 
69