X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Findex%2Fctf-index.h;h=b96888bb7e5a41067c29b31531316c898034ee5e;hb=71b4cdb4772eee93e11df518caeb5f8466156764;hp=8755f1218ad3d114ac8f464051de42d7f92d23af;hpb=234cd6367843a2106a4cb10f8fb99443208516df;p=lttng-tools.git diff --git a/src/common/index/ctf-index.h b/src/common/index/ctf-index.h index 8755f1218..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 @@ -60,4 +65,57 @@ struct ctf_packet_index { uint64_t packet_seq_num; /* packet sequence number */ } __attribute__((__packed__)); +static inline size_t ctf_packet_index_len(uint32_t major, uint32_t minor) +{ + if (major == 1) { + switch (minor) { + case 0: + return offsetof(struct ctf_packet_index, stream_id) + + member_sizeof(struct ctf_packet_index, + stream_id); + case 1: + return offsetof(struct ctf_packet_index, packet_seq_num) + + member_sizeof(struct ctf_packet_index, + packet_seq_num); + default: + abort(); + } + } + abort(); +} + +static inline uint32_t lttng_to_index_major(uint32_t lttng_major, + uint32_t lttng_minor __attribute__((unused))) +{ + if (lttng_major == 2) { + return 1; + } + abort(); +} + +static inline uint32_t lttng_to_index_minor(uint32_t lttng_major, + uint32_t lttng_minor) +{ + if (lttng_major == 2) { + if (lttng_minor < 8) { + return 0; + } else { + return 1; + } + } + 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 */