+ struct bt_clock_class *timestamp_begin_cc = NULL;
+ struct bt_clock_class *timestamp_end_cc = NULL;
+ struct bt_field *timestamp_begin = NULL;
+ struct bt_field *timestamp_end = NULL;
+
+ timestamp_begin = bt_field_structure_borrow_field_by_name(
+ packet_context, "timestamp_begin");
+ if (!timestamp_begin) {
+ BT_LOGD_STR("Cannot retrieve timestamp_begin field in packet context.");
+ ret = -1;
+ goto end;
+ }
+
+ timestamp_begin_cc = borrow_field_mapped_clock_class(timestamp_begin);
+ if (!timestamp_begin_cc) {
+ BT_LOGD_STR("Cannot retrieve the clock mapped to timestamp_begin.");
+ }
+
+ timestamp_end = bt_field_structure_borrow_field_by_name(
+ packet_context, "timestamp_end");
+ if (!timestamp_end) {
+ BT_LOGD_STR("Cannot retrieve timestamp_end field in packet context.");
+ ret = -1;
+ goto end;
+ }
+
+ timestamp_end_cc = borrow_field_mapped_clock_class(timestamp_end);
+ if (!timestamp_end_cc) {
+ BT_LOGD_STR("Cannot retrieve the clock mapped to timestamp_end.");
+ }
+
+ if (_timestamp_begin_cc) {
+ *_timestamp_begin_cc = timestamp_begin_cc;
+ }
+ if (_timestamp_begin) {
+ *_timestamp_begin = timestamp_begin;
+ }
+ if (_timestamp_end_cc) {
+ *_timestamp_end_cc = timestamp_end_cc;
+ }
+ if (_timestamp_end) {
+ *_timestamp_end = timestamp_end;
+ }
+end:
+ return ret;
+}
+
+static
+int borrow_ds_file_packet_bounds_clock_classes(struct ctf_fs_ds_file *ds_file,
+ struct bt_clock_class **timestamp_begin_cc,
+ struct bt_clock_class **timestamp_end_cc)
+{
+ struct bt_field *packet_context = NULL;
+ int ret = ctf_fs_ds_file_borrow_packet_header_context_fields(ds_file,
+ NULL, &packet_context);
+
+ if (ret || !packet_context) {
+ BT_LOGD("Cannot retrieve packet context field: ds-file-path=\"%s\"",
+ ds_file->file->path->str);
+ ret = -1;
+ goto end;
+ }
+
+ ret = borrow_packet_bounds_from_packet_context(packet_context,
+ timestamp_begin_cc, NULL,
+ timestamp_end_cc, NULL);
+
+end:
+ return ret;
+}
+
+static
+int convert_cycles_to_ns(struct bt_clock_class *clock_class,
+ uint64_t cycles, int64_t *ns)
+{
+ return bt_clock_class_cycles_to_ns(clock_class, cycles, ns);
+}
+
+static
+struct ctf_fs_ds_index *build_index_from_idx_file(
+ struct ctf_fs_ds_file *ds_file)
+{
+ int ret;