summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/chunkio/include
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:22 +0000
commitc21c3b0befeb46a51b6bf3758ffa30813bea0ff0 (patch)
tree9754ff1ca740f6346cf8483ec915d4054bc5da2d /fluent-bit/lib/chunkio/include
parentAdding upstream version 1.43.2. (diff)
downloadnetdata-c21c3b0befeb46a51b6bf3758ffa30813bea0ff0.tar.xz
netdata-c21c3b0befeb46a51b6bf3758ffa30813bea0ff0.zip
Adding upstream version 1.44.3.upstream/1.44.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/lib/chunkio/include')
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/chunkio.h143
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/chunkio_compat.h93
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_chunk.h94
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_crc32.h29
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_error.h39
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_file.h86
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_file_native.h56
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_file_st.h170
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_info.h.in26
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_log.h62
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_memfs.h54
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_meta.h31
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_os.h27
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_scan.h28
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_sha1.h36
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_stats.h40
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_stream.h43
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_utils.h32
-rw-r--r--fluent-bit/lib/chunkio/include/chunkio/cio_version.h.in36
19 files changed, 1125 insertions, 0 deletions
diff --git a/fluent-bit/lib/chunkio/include/chunkio/chunkio.h b/fluent-bit/lib/chunkio/include/chunkio/chunkio.h
new file mode 100644
index 000000000..c60ddacce
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/chunkio.h
@@ -0,0 +1,143 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CHUNKIO_H
+#define CHUNKIO_H
+
+#include <chunkio/cio_info.h>
+#include <monkey/mk_core/mk_list.h>
+
+#define CIO_FALSE 0
+#define CIO_TRUE !0
+
+/* debug levels */
+#define CIO_LOG_ERROR 1
+#define CIO_LOG_WARN 2
+#define CIO_LOG_INFO 3
+#define CIO_LOG_DEBUG 4
+#define CIO_LOG_TRACE 5
+
+/* Storage backend */
+#define CIO_STORE_FS 0
+#define CIO_STORE_MEM 1
+
+/* flags */
+#define CIO_OPEN 1 /* open/create file reference */
+#define CIO_OPEN_RW CIO_OPEN /* new name for read/write mode */
+#define CIO_OPEN_RD 2 /* open and read/mmap content if exists */
+#define CIO_CHECKSUM 4 /* enable checksum verification (crc32) */
+#define CIO_FULL_SYNC 8 /* force sync to fs through MAP_SYNC */
+#define CIO_DELETE_IRRECOVERABLE 16 /* delete irrecoverable chunks from disk */
+#define CIO_TRIM_FILES 32 /* trim files to their required size */
+
+/* Return status */
+#define CIO_CORRUPTED -3 /* Indicate that a chunk is corrupted */
+#define CIO_RETRY -2 /* The operations needs to be retried */
+#define CIO_ERROR -1 /* Generic error */
+#define CIO_OK 0 /* OK */
+
+/* Configuration limits */
+/* The file minimum growth factor is 8 memory pages and
+ * the file maximum growth factor is 8 megabytes
+ */
+#define CIO_REALLOC_HINT_MIN (cio_getpagesize() * 8)
+#define CIO_REALLOC_HINT_MAX (8 * 1000 * 1000)
+
+/* defaults */
+#define CIO_MAX_CHUNKS_UP 64 /* default limit for cio_ctx->max_chunks_up */
+#define CIO_DISABLE_REALLOC_HINT -1 /* default value of size of realloc hint */
+#define CIO_DEFAULT_REALLOC_HINT CIO_REALLOC_HINT_MIN
+#define CIO_INITIALIZED 1337
+
+struct cio_ctx;
+
+struct cio_options {
+ /* this bool flag sets if the options has been initialized, that's a mandatory step */
+ int initialized;
+
+ int flags;
+ char *root_path;
+
+ /* logging */
+ int log_level;
+ int (*log_cb)(struct cio_ctx *, int, const char *, int, char *);
+
+ char *user;
+ char *group;
+ char *chmod;
+
+ /* chunk handlings */
+ int realloc_size_hint;
+};
+
+struct cio_ctx {
+ int page_size;
+ int realloc_size_hint;
+ struct cio_options options;
+
+ void *processed_user;
+ void *processed_group;
+
+ /*
+ * Internal counters
+ */
+ size_t total_chunks; /* Total number of registered chunks */
+ size_t total_chunks_up; /* Total number of chunks 'up' in memory */
+
+ /*
+ * maximum open 'file' chunks: this limit helps where there are many
+ * chunks in the filesystem and you don't need all of them up in
+ * memory. For short, it restrict the open number of files and
+ * the amount of memory mapped.
+ */
+ size_t max_chunks_up;
+
+ /* streams */
+ struct mk_list streams;
+
+ /* errors */
+ int last_chunk_error; /* this field is necessary to discard irrecoverable
+ * chunks in cio_scan_stream_files, it's not the
+ * best approach but the only at the moment.
+ */
+};
+
+#include <chunkio/cio_stream.h>
+#include <chunkio/cio_chunk.h>
+
+void cio_options_init(struct cio_options *options);
+struct cio_ctx *cio_create(struct cio_options *options);
+void cio_destroy(struct cio_ctx *ctx);
+int cio_load(struct cio_ctx *ctx, char *chunk_extension);
+int cio_qsort(struct cio_ctx *ctx, int (*compar)(const void *, const void *));
+
+void cio_set_log_callback(struct cio_ctx *ctx, void (*log_cb));
+int cio_set_log_level(struct cio_ctx *ctx, int level);
+int cio_set_max_chunks_up(struct cio_ctx *ctx, int n);
+int cio_set_realloc_size_hint(struct cio_ctx *ctx, size_t realloc_size_hint);
+
+void cio_enable_file_trimming(struct cio_ctx *ctx);
+void cio_disable_file_trimming(struct cio_ctx *ctx);
+
+int cio_meta_write(struct cio_chunk *ch, char *buf, size_t size);
+int cio_meta_cmp(struct cio_chunk *ch, char *meta_buf, int meta_len);
+int cio_meta_read(struct cio_chunk *ch, char **meta_buf, int *meta_len);
+int cio_meta_size(struct cio_chunk *ch);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/chunkio_compat.h b/fluent-bit/lib/chunkio/include/chunkio/chunkio_compat.h
new file mode 100644
index 000000000..3e4951b98
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/chunkio_compat.h
@@ -0,0 +1,93 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CHUNKIO_COMPAT_H
+#define CHUNKIO_COMPAT_H
+
+#include <chunkio/cio_info.h>
+
+#ifdef _WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <winsock2.h>
+#include <windows.h>
+#include <aclapi.h>
+#include <io.h>
+#include <direct.h>
+#pragma comment(lib, "ws2_32.lib")
+
+/** mode flags for access() */
+#define R_OK 04
+#define W_OK 02
+#define X_OK 01
+#define F_OK 00
+
+#define PATH_MAX MAX_PATH
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
+
+typedef SSIZE_T ssize_t;
+typedef unsigned mode_t;
+
+static inline char* dirname(const char *path)
+{
+ char drive[_MAX_DRIVE];
+ char dir[_MAX_DIR];
+ char fname[_MAX_FNAME];
+ char ext[_MAX_EXT];
+ static char buf[_MAX_PATH];
+
+ _splitpath_s(path, drive, _MAX_DRIVE, dir, _MAX_DIR,
+ fname, _MAX_FNAME, ext, _MAX_EXT);
+
+ _makepath_s(buf, _MAX_PATH, drive, dir, "", "");
+
+ /*
+ * If path does not contain a separator, dirname() must
+ * return the string ".".
+ */
+ if (strlen(buf) == 0) {
+ strcpy_s(buf, _MAX_PATH, ".");
+ }
+
+ return buf;
+}
+
+#ifndef CIO_HAVE_GETPAGESIZE
+static inline int cio_getpagesize(void)
+{
+ SYSTEM_INFO system_info;
+ GetSystemInfo(&system_info);
+ return system_info.dwPageSize;
+}
+#else
+static inline int cio_getpagesize(void)
+{
+ return getpagesize();
+}
+#endif
+
+#else
+#include <unistd.h>
+#include <libgen.h>
+#include <dirent.h>
+#include <arpa/inet.h>
+#endif
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_chunk.h b/fluent-bit/lib/chunkio/include/chunkio/cio_chunk.h
new file mode 100644
index 000000000..369401bf8
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_chunk.h
@@ -0,0 +1,94 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_CHUNK_H
+#define CIO_CHUNK_H
+
+#include <sys/types.h>
+#include <inttypes.h>
+
+#include <chunkio/chunkio_compat.h>
+
+struct cio_chunk {
+ int lock; /* locked for write operations ? */
+ char *name; /* chunk name */
+ void *backend; /* backend context (cio_file, cio_memfs) */
+
+ /* Transaction helpers */
+ int tx_active; /* active transaction ? */
+ uint32_t tx_crc; /* CRC32 upon transaction begin */
+ off_t tx_content_length; /* content length */
+
+ struct cio_ctx *ctx; /* library context */
+ struct cio_stream *st; /* stream context */
+
+ /* error handling */
+ int error_n;
+
+ /*
+ * The state head links to the stream->chunks_up or stream->chunks_down
+ * linked list.
+ */
+ struct mk_list _state_head;
+
+ struct mk_list _head; /* head link to stream->files */
+};
+
+struct cio_chunk *cio_chunk_open(struct cio_ctx *ctx, struct cio_stream *st,
+ const char *name, int flags, size_t size,
+ int *err);
+void cio_chunk_close(struct cio_chunk *ch, int delete);
+int cio_chunk_delete(struct cio_ctx *ctx, struct cio_stream *st, const char *name);
+int cio_chunk_write(struct cio_chunk *ch, const void *buf, size_t count);
+int cio_chunk_write_at(struct cio_chunk *ch, off_t offset,
+ const void *buf, size_t count);
+int cio_chunk_sync(struct cio_chunk *ch);
+int cio_chunk_get_content(struct cio_chunk *ch, char **buf, size_t *size);
+int cio_chunk_get_content_copy(struct cio_chunk *ch,
+ void **out_buf, size_t *out_size);
+
+ssize_t cio_chunk_get_content_size(struct cio_chunk *ch);
+ssize_t cio_chunk_get_real_size(struct cio_chunk *ch);
+size_t cio_chunk_get_content_end_pos(struct cio_chunk *ch);
+void cio_chunk_close_stream(struct cio_stream *st);
+char *cio_chunk_hash(struct cio_chunk *ch);
+int cio_chunk_lock(struct cio_chunk *ch);
+int cio_chunk_unlock(struct cio_chunk *ch);
+int cio_chunk_is_locked(struct cio_chunk *ch);
+
+/* transaction handling */
+int cio_chunk_tx_begin(struct cio_chunk *ch);
+int cio_chunk_tx_commit(struct cio_chunk *ch);
+int cio_chunk_tx_rollback(struct cio_chunk *ch);
+
+/* Chunk content up/down */
+int cio_chunk_is_up(struct cio_chunk *ch);
+int cio_chunk_is_file(struct cio_chunk *ch);
+int cio_chunk_up(struct cio_chunk *ch);
+int cio_chunk_up_force(struct cio_chunk *ch);
+int cio_chunk_down(struct cio_chunk *ch);
+char *cio_version();
+
+/* Counters */
+size_t cio_chunk_counter_total_add(struct cio_ctx *ctx);
+size_t cio_chunk_counter_total_sub(struct cio_ctx *ctx);
+size_t cio_chunk_counter_total_up_add(struct cio_ctx *ctx);
+size_t cio_chunk_counter_total_up_sub(struct cio_ctx *ctx);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_crc32.h b/fluent-bit/lib/chunkio/include/chunkio/cio_crc32.h
new file mode 100644
index 000000000..dd15cd270
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_crc32.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_CRC32_H
+#define CIO_CRC32_H
+
+#include <crc32/crc32.h>
+
+#define cio_crc32_init() crc_init()
+#define cio_crc32_update(a, b, c) crc_update(a, b, c)
+#define cio_crc32_finalize(a) crc_finalize(a)
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_error.h b/fluent-bit/lib/chunkio/include/chunkio/cio_error.h
new file mode 100644
index 000000000..faec54073
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_error.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018-2021 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_ERROR_H
+#define CIO_ERROR_H
+
+#include <chunkio/chunkio.h>
+#include <chunkio/cio_chunk.h>
+
+/*
+ * Error status (do not confuse with return statuses!)
+ */
+#define CIO_ERR_BAD_CHECKSUM -10 /* Chunk has a bad checksum */
+#define CIO_ERR_BAD_LAYOUT -11 /* Bad magic bytes or general layout */
+#define CIO_ERR_PERMISSION -12 /* Permission error */
+#define CIO_ERR_BAD_FILE_SIZE -13 /* Chunk has a bad file size */
+
+char *cio_error_get_str(struct cio_chunk *ch);
+int cio_error_get(struct cio_chunk *ch);
+void cio_error_set(struct cio_chunk *ch, int status);
+void cio_error_reset(struct cio_chunk *ch);
+
+#endif \ No newline at end of file
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_file.h b/fluent-bit/lib/chunkio/include/chunkio/cio_file.h
new file mode 100644
index 000000000..7d4474929
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_file.h
@@ -0,0 +1,86 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_FILE_H
+#define CIO_FILE_H
+
+#include <chunkio/cio_chunk.h>
+#include <chunkio/cio_file_st.h>
+#include <chunkio/cio_crc32.h>
+
+/* Linux fallocate() strategy */
+#define CIO_FILE_LINUX_FALLOCATE 0
+#define CIO_FILE_LINUX_POSIX_FALLOCATE 1
+
+struct cio_file {
+ int fd; /* file descriptor */
+ int flags; /* open flags */
+ int synced; /* sync after latest write ? */
+ int allocate_strategy; /* linux-only: fallocate strategy */
+ size_t fs_size; /* original size in the file system */
+ size_t data_size; /* number of bytes used */
+ size_t page_size; /* curent page size */
+ size_t alloc_size; /* allocated size */
+ size_t realloc_size; /* chunk size to increase alloc */
+ char *path; /* root path + stream */
+ char *map; /* map of data */
+#ifdef _WIN32
+ HANDLE backing_file;
+ HANDLE backing_mapping;
+#endif
+ /* cached addr */
+ char *st_content;
+ crc_t crc_cur; /* crc: current value calculated */
+ int crc_reset; /* crc: must recalculate from the beginning ? */
+};
+
+size_t cio_file_real_size(struct cio_file *cf);
+struct cio_file *cio_file_open(struct cio_ctx *ctx,
+ struct cio_stream *st,
+ struct cio_chunk *ch,
+ int flags,
+ size_t size,
+ int *err);
+void cio_file_close(struct cio_chunk *ch, int delete);
+int cio_file_delete(struct cio_ctx *ctx, struct cio_stream *st, const char *name);
+int cio_file_write(struct cio_chunk *ch, const void *buf, size_t count);
+int cio_file_write_metadata(struct cio_chunk *ch, char *buf, size_t size);
+int cio_file_sync(struct cio_chunk *ch);
+int cio_file_resize(struct cio_file *cf, size_t new_size);
+char *cio_file_hash(struct cio_file *cf);
+void cio_file_hash_print(struct cio_file *cf);
+void cio_file_calculate_checksum(struct cio_file *cf, crc_t *out);
+void cio_file_scan_dump(struct cio_ctx *ctx, struct cio_stream *st);
+int cio_file_read_prepare(struct cio_ctx *ctx, struct cio_chunk *ch);
+int cio_file_content_copy(struct cio_chunk *ch,
+ void **out_buf, size_t *out_size);
+
+
+int cio_file_is_up(struct cio_chunk *ch, struct cio_file *cf);
+int cio_file_down(struct cio_chunk *ch);
+int cio_file_up(struct cio_chunk *ch);
+int cio_file_up_force(struct cio_chunk *ch);
+int cio_file_lookup_user(char *user, void **result);
+int cio_file_lookup_group(char *group, void **result);
+int cio_file_update_size(struct cio_file *cf);
+
+#define cio_file_report_runtime_error() { cio_file_native_report_runtime_error(); }
+#define cio_file_report_os_error() { cio_file_native_report_os_error(); }
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_file_native.h b/fluent-bit/lib/chunkio/include/chunkio/cio_file_native.h
new file mode 100644
index 000000000..1658495fd
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_file_native.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_FILE_NATIVE_H
+#define CIO_FILE_NATIVE_H
+
+#include <chunkio/cio_file.h>
+
+
+
+#ifdef _WIN32
+#define cio_file_native_is_open(cf) (cf->backing_file != INVALID_HANDLE_VALUE)
+#define cio_file_native_is_mapped(cf) (cf->backing_mapping != INVALID_HANDLE_VALUE)
+#define cio_file_native_report_runtime_error() { cio_errno(); }
+#define cio_file_native_report_os_error() { cio_winapi_error(); }
+#else
+#define cio_file_native_is_open(cf) (cf->fd != -1)
+#define cio_file_native_is_mapped(cf) (cf->map != NULL)
+#define cio_file_native_report_runtime_error() { cio_errno(); }
+#define cio_file_native_report_os_error() { cio_errno(); }
+#endif
+
+int cio_file_native_apply_acl_and_settings(struct cio_ctx *ctx, struct cio_file *cf);
+char *cio_file_native_compose_path(char *root_path, char *stream_name,
+ char *chunk_name);
+int cio_file_native_unmap(struct cio_file *cf);
+int cio_file_native_map(struct cio_file *cf, size_t map_size);
+int cio_file_native_remap(struct cio_file *cf, size_t new_size);
+int cio_file_native_lookup_user(char *user, void **result);
+int cio_file_native_lookup_group(char *group, void **result);
+int cio_file_native_get_size(struct cio_file *cf, size_t *file_size);
+int cio_file_native_filename_check(char *name);
+int cio_file_native_open(struct cio_file *cf);
+int cio_file_native_close(struct cio_file *cf);
+int cio_file_native_delete(struct cio_file *cf);
+int cio_file_native_delete_by_path(const char *path);
+int cio_file_native_sync(struct cio_file *cf, int sync_mode);
+int cio_file_native_resize(struct cio_file *cf, size_t new_size);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_file_st.h b/fluent-bit/lib/chunkio/include/chunkio/cio_file_st.h
new file mode 100644
index 000000000..4b1552b61
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_file_st.h
@@ -0,0 +1,170 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_FILE_ST_H
+#define CIO_FILE_ST_H
+
+#include <stdlib.h>
+#include <inttypes.h>
+
+/*
+ * ChunkIO data file layout as of 2018/10/26
+ *
+ * - 2 first bytes as identification: 0xC1 0x00
+ * - 4 bytes for checksum of content section (CRC32)
+ * - Content section is composed by:
+ * - 2 bytes to specify the length of metadata
+ * - optional metadata
+ * - user data
+ *
+ * +--------------+----------------+
+ * | 0xC1 | 0x00 +--> Header 2 bytes
+ * +--------------+----------------+
+ * | 4 BYTES +--> CRC32(Content)
+ * | 4 BYTES +--> CRC32(Padding)
+ * | 4 BYTES +--> Content length
+ * | 8 BYTES +--> Padding
+ * +-------------------------------+
+ * | Content |
+ * | +-------------------------+ |
+ * | | 2 BYTES +-----> Metadata Length
+ * | +-------------------------+ |
+ * | +-------------------------+ |
+ * | | | |
+ * | | Metadata +-----> Optional Metadata (up to 65535 bytes)
+ * | | | |
+ * | +-------------------------+ |
+ * | +-------------------------+ |
+ * | | | |
+ * | | Content Data +-----> User Data
+ * | | | |
+ * | +-------------------------+ |
+ * +-------------------------------+
+ */
+
+#define CIO_FILE_ID_00 0xc1 /* header: first byte */
+#define CIO_FILE_ID_01 0x00 /* header: second byte */
+#define CIO_FILE_HEADER_MIN 24 /* 24 bytes for the header */
+#define CIO_FILE_CONTENT_OFFSET 22
+#define CIO_FILE_CONTENT_LENGTH_OFFSET 10 /* We store the content length
+ * right after the checksum in
+ * what used to be padding
+ */
+/* Return pointer to hash position */
+static inline char *cio_file_st_get_hash(char *map)
+{
+ return map + 2;
+}
+
+/* Return metadata length */
+static inline uint16_t cio_file_st_get_meta_len(char *map)
+{
+ return (uint16_t) ((uint8_t) map[22] << 8) | (uint8_t) map[23];
+}
+
+/* Set metadata length */
+static inline void cio_file_st_set_meta_len(char *map, uint16_t len)
+{
+ map[22] = (uint8_t) (len >> 8);
+ map[23] = (uint8_t) (len & 0xFF);
+}
+
+/* Return pointer to start point of metadata */
+static inline char *cio_file_st_get_meta(char *map)
+{
+ return map + CIO_FILE_HEADER_MIN;
+}
+
+/* Return pointer to start point of content */
+static inline char *cio_file_st_get_content(char *map)
+{
+ uint16_t len;
+
+ len = cio_file_st_get_meta_len(map);
+ return map + CIO_FILE_HEADER_MIN + len;
+}
+
+/* Infer content length when not available */
+static inline ssize_t cio_file_st_infer_content_len(char *map, size_t size)
+{
+ size_t content_length;
+
+ content_length = size;
+ content_length -= CIO_FILE_HEADER_MIN;
+ content_length -= cio_file_st_get_meta_len(map);
+
+ return content_length;
+}
+
+/* Get content length */
+static inline ssize_t cio_file_st_get_content_len(char *map, size_t size,
+ size_t page_size)
+{
+ uint8_t *content_length_buffer;
+ ssize_t content_length;
+
+ if (size < CIO_FILE_HEADER_MIN) {
+ return -1;
+ }
+
+ content_length_buffer = (uint8_t *) &map[CIO_FILE_CONTENT_LENGTH_OFFSET];
+
+ content_length = (ssize_t) (((uint32_t) content_length_buffer[0]) << 24) |
+ (((uint32_t) content_length_buffer[1]) << 16) |
+ (((uint32_t) content_length_buffer[2]) << 8) |
+ (((uint32_t) content_length_buffer[3]) << 0);
+
+ /* This is required in order to be able to load chunk files generated by
+ * previous versions of chunkio that didn't include the content length
+ * as part of the headers.
+ *
+ * The reason why we need to ensure that the file size is larger than 4096
+ * is that this is the minimal expected page size which is the unit used
+ * to initialize chunk files when they are created.
+ *
+ * In doing so, we effectively avoid returning bogus results when loading
+ * newly created, non trimmed files while at the same time retaining the
+ * capability of loading legacy files (that don't have a content size)
+ * that are larger than 4096 bytes.
+ *
+ * The only caveat is that trimmed files
+ */
+ if (content_length == 0 &&
+ size > 0 &&
+ size != page_size) {
+ content_length = cio_file_st_infer_content_len(map, size);
+ }
+
+ return content_length;
+}
+
+/* Set content length */
+static inline void cio_file_st_set_content_len(char *map, uint32_t len)
+{
+ uint8_t *content_length_buffer;
+
+ content_length_buffer = (uint8_t *) &map[CIO_FILE_CONTENT_LENGTH_OFFSET];
+
+ content_length_buffer[0] = (uint8_t) ((len & 0xFF000000) >> 24);
+ content_length_buffer[1] = (uint8_t) ((len & 0x00FF0000) >> 16);
+ content_length_buffer[2] = (uint8_t) ((len & 0x0000FF00) >> 8);
+ content_length_buffer[3] = (uint8_t) ((len & 0x000000FF) >> 0);
+}
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_info.h.in b/fluent-bit/lib/chunkio/include/chunkio/cio_info.h.in
new file mode 100644
index 000000000..87924fbf5
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_info.h.in
@@ -0,0 +1,26 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018-2020 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_INFO_H
+#define CIO_INFO_H
+
+/* General flags set by CMakeLists.txt */
+@CIO_BUILD_FLAGS@
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_log.h b/fluent-bit/lib/chunkio/include/chunkio/cio_log.h
new file mode 100644
index 000000000..83dc46169
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_log.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_LOG_H
+#define CIO_LOG_H
+
+#include <errno.h>
+
+#define CIO_LOG_BUF_SIZE 256
+
+void cio_log_print(void *ctx, int level, const char *file, int line,
+ const char *fmt, ...);
+int cio_errno_print(int errnum, const char *file, int line);
+
+#define cio_log_error(ctx, fmt, ...) \
+ cio_log_print(ctx, CIO_LOG_ERROR, __FILENAME__, \
+ __LINE__, fmt, ##__VA_ARGS__)
+
+#define cio_log_warn(ctx, fmt, ...) \
+ cio_log_print(ctx, CIO_LOG_WARN, __FILENAME__, \
+ __LINE__, fmt, ##__VA_ARGS__)
+
+#define cio_log_info(ctx, fmt, ...) \
+ cio_log_print(ctx, CIO_LOG_INFO, __FILENAME__, \
+ __LINE__, fmt, ##__VA_ARGS__)
+
+#define cio_log_debug(ctx, fmt, ...) \
+ cio_log_print(ctx, CIO_LOG_DEBUG, __FILENAME__, \
+ __LINE__, fmt, ##__VA_ARGS__)
+
+#define cio_log_trace(ctx, fmt, ...) \
+ cio_log_print(ctx, CIO_LOG_TRACE, __FILENAME__, \
+ __LINE__, fmt, ##__VA_ARGS__)
+
+#ifdef __FILENAME__
+#define cio_errno() cio_errno_print(errno, __FILENAME__, __LINE__)
+#else
+#define cio_errno() cio_errno_print(errno, __FILE__, __LINE__)
+#endif
+
+#ifdef _WIN32
+void cio_winapi_error_print(const char *func, int line);
+#define cio_winapi_error() cio_winapi_error_print(__func__, __LINE__)
+#endif
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_memfs.h b/fluent-bit/lib/chunkio/include/chunkio/cio_memfs.h
new file mode 100644
index 000000000..ffcaeae4c
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_memfs.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_MEMFS_H
+#define CIO_MEMFS_H
+
+#include <chunkio/chunkio.h>
+#include <chunkio/cio_stream.h>
+#include <chunkio/cio_chunk.h>
+#include <chunkio/cio_crc32.h>
+
+struct cio_memfs {
+ char *name; /* file name */
+ crc_t crc_cur; /* un-finalized checksum */
+
+ /* metadata */
+ char *meta_data;
+ int meta_len;
+
+ /* content-data */
+ char *buf_data; /* buffer with content data */
+ size_t buf_len; /* buffer content length */
+ size_t buf_size; /* buffer allocated size */
+ size_t realloc_size; /* chunk size to increase buf_data */
+};
+
+
+struct cio_memfs *cio_memfs_open(struct cio_ctx *ctx, struct cio_stream *st,
+ struct cio_chunk *ch, int flags,
+ size_t size);
+void cio_memfs_close(struct cio_chunk *ch);
+int cio_memfs_write(struct cio_chunk *ch, const void *buf, size_t count);
+int cio_memfs_close_stream(struct cio_stream *st);
+void cio_memfs_scan_dump(struct cio_ctx *ctx, struct cio_stream *st);
+int cio_memfs_content_copy(struct cio_chunk *ch,
+ void **out_buf, size_t *out_size);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_meta.h b/fluent-bit/lib/chunkio/include/chunkio/cio_meta.h
new file mode 100644
index 000000000..885e8c636
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_meta.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_META_H
+#define CIO_META_H
+
+#include <chunkio/cio_file.h>
+#include <chunkio/cio_chunk.h>
+
+int cio_meta_write(struct cio_chunk *ch, char *buf, size_t size);
+int cio_meta_read(struct cio_chunk *ch, char **meta_buf, int *meta_len);
+int cio_meta_cmp(struct cio_chunk *ch, char *meta_buf, int meta_len);
+int cio_meta_size(struct cio_chunk *ch);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_os.h b/fluent-bit/lib/chunkio/include/chunkio/cio_os.h
new file mode 100644
index 000000000..388de89db
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_os.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_OS_H
+#define CIO_OS_H
+#include <sys/types.h>
+
+int cio_os_isdir(const char *dir);
+int cio_os_mkpath(const char *dir, mode_t mode);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_scan.h b/fluent-bit/lib/chunkio/include/chunkio/cio_scan.h
new file mode 100644
index 000000000..ce74229bb
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_scan.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_SCAN_H
+#define CIO_SCAN_H
+
+#include <chunkio/chunkio.h>
+
+int cio_scan_streams(struct cio_ctx *ctx, char *chunk_extension);
+void cio_scan_dump(struct cio_ctx *ctx);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_sha1.h b/fluent-bit/lib/chunkio/include/chunkio/cio_sha1.h
new file mode 100644
index 000000000..3899d2b8b
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_sha1.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_SHA1_H
+#define CIO_SHA1_H
+
+#include <sha1/sha1.h>
+
+struct cio_sha1 {
+ SHA_CTX sha;
+};
+
+void cio_sha1_init(struct cio_sha1 *ctx);
+void cio_sha1_update(struct cio_sha1 *ctx, const void *data, unsigned long len);
+void cio_sha1_final(unsigned char hash[20], struct cio_sha1 *ctx);
+void cio_sha1_hash(const void *data_in, unsigned long length,
+ unsigned char *data_out, void *state);
+void cio_sha1_to_hex(unsigned char *in, char *out);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_stats.h b/fluent-bit/lib/chunkio/include/chunkio/cio_stats.h
new file mode 100644
index 000000000..b3c41789b
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_stats.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2019 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_STATS_H
+#define CIO_STATS_H
+
+#include <chunkio/chunkio.h>
+
+struct cio_stats {
+ /* Streams */
+ int streams_total; /* total number of registered streams */
+
+ /* Chunks */
+ int chunks_total; /* total number of registered chunks */
+ int chunks_mem; /* number of chunks of memory type */
+ int chunks_fs; /* number of chunks in file type */
+ int chunks_fs_up; /* number of chunks in file type 'Up' in memory */
+ int chunks_fs_down; /* number of chunks in file type 'down' */
+};
+
+void cio_stats_get(struct cio_ctx *ctx, struct cio_stats *stats);
+void cio_stats_print_summary(struct cio_ctx *ctx);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_stream.h b/fluent-bit/lib/chunkio/include/chunkio/cio_stream.h
new file mode 100644
index 000000000..22e34c2ca
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_stream.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2019 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_STREAM_H
+#define CIO_STREAM_H
+
+#include <monkey/mk_core/mk_list.h>
+
+struct cio_stream {
+ int type; /* type: CIO_STORE_FS or CIO_STORE_MEM */
+ char *name; /* stream name */
+ struct mk_list _head; /* head link to ctx->streams list */
+ struct mk_list chunks; /* list of all chunks in the stream */
+ struct mk_list chunks_up; /* list of chunks who are 'up' */
+ struct mk_list chunks_down; /* list of chunks who are 'down' */
+ void *parent; /* ref to parent ctx */
+};
+
+struct cio_stream *cio_stream_create(struct cio_ctx *ctx, const char *name,
+ int type);
+struct cio_stream *cio_stream_get(struct cio_ctx *ctx, const char *name);
+int cio_stream_delete(struct cio_stream *st);
+void cio_stream_destroy(struct cio_stream *st);
+void cio_stream_destroy_all(struct cio_ctx *ctx);
+size_t cio_stream_size_chunks_up(struct cio_stream *st);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_utils.h b/fluent-bit/lib/chunkio/include/chunkio/cio_utils.h
new file mode 100644
index 000000000..b8a9deac6
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_utils.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_UTILS_H
+#define CIO_UTILS_H
+
+#include <chunkio/cio_info.h>
+
+#ifdef CIO_HAVE_GETPAGESIZE
+int cio_getpagesize();
+#endif
+
+int cio_utils_recursive_delete(const char *dir);
+int cio_utils_read_file(const char *path, char **buf, size_t *size);
+
+#endif
diff --git a/fluent-bit/lib/chunkio/include/chunkio/cio_version.h.in b/fluent-bit/lib/chunkio/include/chunkio/cio_version.h.in
new file mode 100644
index 000000000..852151f4e
--- /dev/null
+++ b/fluent-bit/lib/chunkio/include/chunkio/cio_version.h.in
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* Chunk I/O
+ * =========
+ * Copyright 2018-2020 Eduardo Silva <eduardo@monkey.io>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CIO_VERSION_H
+#define CIO_VERSION_H
+
+/* Helpers to convert/format version string */
+#define STR_HELPER(s) #s
+#define STR(s) STR_HELPER(s)
+
+/* Chunk I/O Version */
+#define CIO_VERSION_MAJOR @CIO_VERSION_MAJOR@
+#define CIO_VERSION_MINOR @CIO_VERSION_MINOR@
+#define CIO_VERSION_PATCH @CIO_VERSION_PATCH@
+#define CIO_VERSION (CIO_VERSION_MAJOR * 10000 \
+ CIO_VERSION_MINOR * 100 \
+ CIO_VERSION_PATCH)
+#define CIO_VERSION_STR "@CIO_VERSION_STR@"
+
+#endif