Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
struct bt_ctf_field *integer = NULL;
struct ctf_stream_pos packet_context_pos;
bool empty_packet;
struct bt_ctf_field *integer = NULL;
struct ctf_stream_pos packet_context_pos;
bool empty_packet;
+ uint64_t packet_size_bits;
if (!stream || stream->pos.fd < 0) {
/*
if (!stream || stream->pos.fd < 0) {
/*
+ /* Rounded-up in case content_size is not byte-aligned. */
+ packet_size_bits = (stream->pos.offset + (CHAR_BIT - 1)) &
+ ~(CHAR_BIT - 1);
+ stream->pos.packet_size = packet_size_bits;
+
if (stream->packet_context) {
/*
* Update the packet total size and content size and overwrite
if (stream->packet_context) {
/*
* Update the packet total size and content size and overwrite
}
ret = set_structure_field_integer(stream->packet_context,
}
ret = set_structure_field_integer(stream->packet_context,
- "packet_size", stream->pos.packet_size);
+ "packet_size", packet_size_bits);
g_ptr_array_set_size(stream->events, 0);
stream->flushed_packet_count++;
g_ptr_array_set_size(stream->events, 0);
stream->flushed_packet_count++;
+ stream->size += packet_size_bits / CHAR_BIT;
end:
bt_put(integer);
return ret;
end:
bt_put(integer);
return ret;
stream = container_of(obj, struct bt_ctf_stream, base);
ctf_fini_pos(&stream->pos);
stream = container_of(obj, struct bt_ctf_stream, base);
ctf_fini_pos(&stream->pos);
- if (stream->pos.fd >= 0 && close(stream->pos.fd)) {
- perror("close");
+ if (stream->pos.fd >= 0) {
+ int ret;
+
+ /*
+ * Truncate the file's size to the minimum required to fit the
+ * last packet as we might have grown it too much on the last
+ * mmap.
+ */
+ do {
+ ret = ftruncate(stream->pos.fd, stream->size);
+ } while (ret == -1 && errno == EINTR);
+ if (ret) {
+ perror("ftruncate");
+ }
+
+ if (close(stream->pos.fd)) {
+ perror("close");
+ }
struct bt_object base;
uint32_t id;
struct bt_ctf_stream_class *stream_class;
struct bt_object base;
uint32_t id;
struct bt_ctf_stream_class *stream_class;
+ GString *name;
+ struct bt_ctf_field *packet_header;
+ struct bt_ctf_field *packet_context;
+
+ /* Writer-specific members. */
/* Array of pointers to bt_ctf_event for the current packet */
GPtrArray *events;
struct ctf_stream_pos pos;
unsigned int flushed_packet_count;
/* Array of pointers to bt_ctf_event for the current packet */
GPtrArray *events;
struct ctf_stream_pos pos;
unsigned int flushed_packet_count;
- GString *name;
- struct bt_ctf_field *packet_header;
- struct bt_ctf_field *packet_context;