+ lttng_trace_chunk_put(chunk);
+ free(index_file);
+ return chunk_status;
+}
+
+enum lttng_trace_chunk_status lttng_index_file_create_from_trace_chunk(
+ struct lttng_trace_chunk *chunk,
+ const char *channel_path, const char *stream_name,
+ uint64_t stream_file_size, uint64_t stream_file_index,
+ uint32_t index_major, uint32_t index_minor,
+ bool unlink_existing_file, struct lttng_index_file **file)
+{
+ return _lttng_index_file_create_from_trace_chunk(chunk, channel_path,
+ stream_name, stream_file_size, stream_file_index,
+ index_major, index_minor, unlink_existing_file,
+ WRITE_FILE_FLAGS, false, file);
+}
+
+enum lttng_trace_chunk_status lttng_index_file_create_from_trace_chunk_read_only(
+ struct lttng_trace_chunk *chunk,
+ const char *channel_path, const char *stream_name,
+ uint64_t stream_file_size, uint64_t stream_file_index,
+ uint32_t index_major, uint32_t index_minor,
+ bool expect_no_file, struct lttng_index_file **file)
+{
+ return _lttng_index_file_create_from_trace_chunk(chunk, channel_path,
+ stream_name, stream_file_size, stream_file_index,
+ index_major, index_minor, false,
+ READ_ONLY_FILE_FLAGS, expect_no_file, file);
+}
+
+/*
+ * Write index values to the given index file.
+ *
+ * Return 0 on success, -1 on error.
+ */
+int lttng_index_file_write(const struct lttng_index_file *index_file,
+ const struct ctf_packet_index *element)
+{
+ int fd;
+ size_t len;
+ ssize_t ret;
+
+ assert(index_file);
+ assert(element);
+
+ fd = index_file->fd;
+ len = index_file->element_len;
+
+ if (fd < 0) {
+ goto error;
+ }
+
+ ret = lttng_write(fd, element, len);
+ if (ret < len) {
+ PERROR("writing index file");
+ goto error;
+ }
+ return 0;
+
+error:
+ return -1;