Move index initialization to ctf-index.h
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 30 Jun 2018 18:51:55 +0000 (14:51 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 25 Jul 2019 19:45:26 +0000 (15:45 -0400)
This initialization code is moved to a common header to re-use
it in a follow-up patch.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/index/ctf-index.h
src/common/index/index.c

index 8f0a56c25228509ffe6794ae22dac3203e080894..b96888bb7e5a41067c29b31531316c898034ee5e 100644 (file)
 #ifndef LTTNG_INDEX_H
 #define LTTNG_INDEX_H
 
+#include <common/compat/endian.h>
+#include <common/macros.h>
+
+#include <stdint.h>
 #include <limits.h>
+#include <stddef.h>
 
 #define CTF_INDEX_MAGIC 0xC1F1DCC1
 #define CTF_INDEX_MAJOR 1
@@ -101,4 +106,16 @@ static inline uint32_t lttng_to_index_minor(uint32_t lttng_major,
        abort();
 }
 
+static inline void ctf_packet_index_file_hdr_init(
+               struct ctf_packet_index_file_hdr *hdr,
+               uint32_t idx_major, uint32_t idx_minor)
+{
+       memset(hdr, 0, sizeof(*hdr));
+       hdr->magic = htobe32(CTF_INDEX_MAGIC);
+       hdr->index_major = htobe32(idx_major);
+       hdr->index_minor = htobe32(idx_minor);
+       hdr->packet_index_len = htobe32(
+                       ctf_packet_index_len(idx_major, idx_minor));
+}
+
 #endif /* LTTNG_INDEX_H */
index 40ac0de199cd53bdcba43bb80bbd91253e63276e..0935d702dccea0b2fd60ea4de2baa3babd9848f3 100644 (file)
@@ -88,11 +88,7 @@ struct lttng_index_file *lttng_index_file_create(const char *path_name,
        }
        fd = ret;
 
-       hdr.magic = htobe32(CTF_INDEX_MAGIC);
-       hdr.index_major = htobe32(major);
-       hdr.index_minor = htobe32(minor);
-       hdr.packet_index_len = htobe32(element_len);
-
+       ctf_packet_index_file_hdr_init(&hdr, major, minor);
        size_ret = lttng_write(fd, &hdr, sizeof(hdr));
        if (size_ret < sizeof(hdr)) {
                PERROR("write index header");
This page took 0.026616 seconds and 4 git commands to generate.