| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright (C) 2016 Philippe Proulx <pproulx@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef CTF_FS_DS_FILE_H |
| 8 | #define CTF_FS_DS_FILE_H |
| 9 | |
| 10 | #include <glib.h> |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | #include <babeltrace2/babeltrace.h> |
| 14 | |
| 15 | #include "cpp-common/bt2c/logging.hpp" |
| 16 | |
| 17 | #include "../common/src/msg-iter/msg-iter.hpp" |
| 18 | |
| 19 | struct ctf_fs_ds_file_info |
| 20 | { |
| 21 | /* Owned by this. */ |
| 22 | GString *path = nullptr; |
| 23 | |
| 24 | /* Guaranteed to be set, as opposed to the index. */ |
| 25 | int64_t begin_ns = 0; |
| 26 | }; |
| 27 | |
| 28 | struct ctf_fs_ds_file |
| 29 | { |
| 30 | explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) : |
| 31 | logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"} |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | bt2c::Logger logger; |
| 36 | |
| 37 | /* Weak */ |
| 38 | struct ctf_fs_metadata *metadata = nullptr; |
| 39 | |
| 40 | /* Owned by this */ |
| 41 | struct ctf_fs_file *file = nullptr; |
| 42 | |
| 43 | /* Owned by this */ |
| 44 | bt_stream *stream = nullptr; |
| 45 | |
| 46 | void *mmap_addr = nullptr; |
| 47 | |
| 48 | /* |
| 49 | * Max length of chunk to mmap() when updating the current mapping. |
| 50 | * This value must be page-aligned. |
| 51 | */ |
| 52 | size_t mmap_max_len = 0; |
| 53 | |
| 54 | /* Length of the current mapping. Never exceeds the file's length. */ |
| 55 | size_t mmap_len = 0; |
| 56 | |
| 57 | /* Offset in the file where the current mapping starts. */ |
| 58 | off_t mmap_offset_in_file = 0; |
| 59 | |
| 60 | /* |
| 61 | * Offset, in the current mapping, of the address to return on the next |
| 62 | * request. |
| 63 | */ |
| 64 | off_t request_offset_in_mapping = 0; |
| 65 | }; |
| 66 | |
| 67 | struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream, |
| 68 | const char *path, const bt2c::Logger& logger); |
| 69 | |
| 70 | void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream); |
| 71 | |
| 72 | struct ctf_fs_ds_index *ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file, |
| 73 | struct ctf_fs_ds_file_info *ds_file_info, |
| 74 | struct ctf_msg_iter *msg_iter); |
| 75 | |
| 76 | struct ctf_fs_ds_index *ctf_fs_ds_index_create(const bt2c::Logger& logger); |
| 77 | |
| 78 | void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index); |
| 79 | |
| 80 | /* |
| 81 | * Medium operations to iterate on a single ctf_fs_ds_file. |
| 82 | * |
| 83 | * The data pointer when using this must be a pointer to the ctf_fs_ds_file. |
| 84 | */ |
| 85 | extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops; |
| 86 | |
| 87 | /* |
| 88 | * Medium operations to iterate on the packet of a ctf_fs_ds_group. |
| 89 | * |
| 90 | * The iteration is done based on the index of the group. |
| 91 | * |
| 92 | * The data pointer when using these medops must be a pointer to a ctf_fs_ds |
| 93 | * group_medops_data structure. |
| 94 | */ |
| 95 | extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops; |
| 96 | |
| 97 | enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create( |
| 98 | struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter, |
| 99 | const bt2c::Logger& logger, struct ctf_fs_ds_group_medops_data **out); |
| 100 | |
| 101 | void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data); |
| 102 | |
| 103 | void ctf_fs_ds_group_medops_data_destroy(struct ctf_fs_ds_group_medops_data *data); |
| 104 | |
| 105 | #endif /* CTF_FS_DS_FILE_H */ |