Backport: 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)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 21 Sep 2018 04:00:52 +0000 (00:00 -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 5d6bd80f4cf11b32ed81574141e4ed7c5854c33a..d60fe0b26bf9f0cdc4c790b03c25617fb1cced4b 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 c94ec701c869f2df3bf61e2845409d3c46697131..f5f250a9f0393173b960871cf3c8dda5579cabc7 100644 (file)
@@ -88,11 +88,7 @@ struct lttng_index_file *lttng_index_file_create(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.027226 seconds and 5 git commands to generate.