1
0
Files
overlaydirs/overlay.hh
2025-05-27 11:36:06 +03:00

91 lines
1.8 KiB
C++

/* SPDX-License-Identifier: Apache-2.0
* (c) 2025, Konstantin Demin
*/
#ifndef INCLUDE_OVERLAY_HH
#define INCLUDE_OVERLAY_HH 1
#include <cstring>
extern "C" {
#include <sys/types.h>
}
#include "overlay-common.hh"
#include "print.hh"
#include "sort.hh"
#include "xxhash.hh"
struct ovl_dirspec_t {
dev_t dev;
ino_t ino;
int fd;
ovl_path_t root;
};
typedef std::vector<ovl_dirspec_t> ovl_dirspec_vec;
enum ovl_rootspec_flags : uint32_t {
none = 0,
// relative path (if possible)
relative = (1 << 0),
};
// forward declaration
struct ovl_entry_t;
typedef std::vector<ovl_entry_t> ovl_entry_vec;
enum struct ovl_entry_kind : uint32_t {
unknown = 0,
// entry may have it's own entries
directory,
// entry may NOT have it's own entries
// this applies to:
// - regular files
// - directories at maximum depth (!)
// - block and character devices
// - pipes (FIFO)
// - sockets
file,
};
struct ovl_entry_t {
ovl_entry_kind type;
int32_t root_id;
xxhash_t name_hash;
ovl_entry_vec children;
ovl_name_t name;
ovl_entry_t() {
root_id = -1;
type = ovl_entry_kind::unknown;
name_hash = 0;
children = ovl_entry_vec();
(void) memset(&name, 0, sizeof(name));
}
};
struct ovl_result {
ovl_path_vec roots;
ovl_entry_vec entries;
ovl_result() {
roots = ovl_path_vec();
entries = ovl_entry_vec();
}
};
bool arg_to_rootspec(const char * arg, ovl_dirspec_t * path, uint32_t flags = ovl_rootspec_flags::none);
bool is_empty_dir(int dirfd);
ovl_result process_overlay(ovl_dirspec_vec & roots, sort_mode sort = sort_mode::none, unsigned int depth = ovl_depth_max);
void list_overlay(const ovl_result & overlay, print_mode print = print_mode::normal);
int merge_overlay(const ovl_result & overlay, const ovl_dirspec_t & target);
#endif /* INCLUDE_OVERLAY_HH */