From 71b4cdb4772eee93e11df518caeb5f8466156764 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sat, 30 Jun 2018 14:51:55 -0400 Subject: [PATCH] Move index initialization to ctf-index.h MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/common/index/ctf-index.h | 17 +++++++++++++++++ src/common/index/index.c | 6 +----- 2 files changed, 18 insertions(+), 5 deletions(-) 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"); -- 2.34.1