Support ctf index version 1.1
[babeltrace.git] / formats / ctf / ctf.c
index 9cb19f4dc323159be1da0bb8e4b00b3526577ffd..7d51b7dc544e2a700e8be0c0512a1cc883b1f690 100644 (file)
@@ -936,6 +936,11 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                        assert(0);
                }
 
+               if (pos->cur_index >= pos->packet_index->len) {
+                       pos->offset = EOF;
+                       return;
+               }
+
                packet_index = &g_array_index(pos->packet_index,
                                struct packet_index, pos->cur_index);
                if (pos->cur_index > 0) {
@@ -948,11 +953,6 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                ctf_update_current_packet_index(&file_stream->parent,
                                prev_index, packet_index);
 
-               if (pos->cur_index >= pos->packet_index->len) {
-                       pos->offset = EOF;
-                       return;
-               }
-
                /*
                 * We need to check if we are in trace read or called
                 * from packet indexing.  In this last case, the
@@ -1551,6 +1551,8 @@ begin:
        packet_index.ts_cycles.timestamp_end = 0;
        packet_index.events_discarded = 0;
        packet_index.events_discarded_len = 0;
+       packet_index.stream_instance_id = 0;
+       packet_index.packet_seq_num = 0;
 
        /* read and check header, set stream id (and check) */
        if (file_stream->parent.trace_packet_header) {
@@ -1837,7 +1839,7 @@ int import_stream_packet_index(struct ctf_trace *td,
        struct ctf_packet_index *ctf_index = NULL;
        struct ctf_packet_index_file_hdr index_hdr;
        struct packet_index index;
-       uint32_t packet_index_len;
+       uint32_t packet_index_len, index_minor;
        int ret = 0;
        int first_packet = 1;
        size_t len;
@@ -1865,6 +1867,8 @@ int import_stream_packet_index(struct ctf_trace *td,
                ret = -1;
                goto error;
        }
+       index_minor = be32toh(index_hdr.index_minor);
+
        packet_index_len = be32toh(index_hdr.packet_index_len);
        if (packet_index_len == 0) {
                fprintf(stderr, "[error] Packet index length cannot be 0.\n");
@@ -1891,6 +1895,10 @@ int import_stream_packet_index(struct ctf_trace *td,
                index.events_discarded_len = 64;
                index.data_offset = -1;
                stream_id = be64toh(ctf_index->stream_id);
+               if (index_minor >= 1) {
+                       index.stream_instance_id = be64toh(ctf_index->stream_instance_id);
+                       index.packet_seq_num = be64toh(ctf_index->packet_seq_num);
+               }
 
                if (!first_packet) {
                        /* add index to packet array */
This page took 0.02684 seconds and 4 git commands to generate.