From: Jérémie Galarneau Date: Sat, 30 Jun 2018 18:51:55 +0000 (-0400) Subject: Move index initialization to ctf-index.h X-Git-Tag: v2.12.0-rc1~560 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=71b4cdb4772eee93e11df518caeb5f8466156764;p=lttng-tools.git Move index initialization to ctf-index.h 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 --- diff --git a/src/common/index/ctf-index.h b/src/common/index/ctf-index.h index 8f0a56c25..b96888bb7 100644 --- a/src/common/index/ctf-index.h +++ b/src/common/index/ctf-index.h @@ -25,7 +25,12 @@ #ifndef LTTNG_INDEX_H #define LTTNG_INDEX_H +#include +#include + +#include #include +#include #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 */ diff --git a/src/common/index/index.c b/src/common/index/index.c index 40ac0de19..0935d702d 100644 --- a/src/common/index/index.c +++ b/src/common/index/index.c @@ -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");