capture: implement directory structure capture

This commit is contained in:
2025-04-26 21:28:43 +01:00
parent d5df4d593f
commit 150b092d1b
18 changed files with 1737 additions and 32 deletions

View File

@@ -4,11 +4,13 @@
#include "pipeline.h"
#include "shadow-image.h"
#include "status.h"
#include "tag.h"
#include <blue/io/directory.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <blue/object/buffer.h>
#include <blue/object/string.h>
#include <stdlib.h>
#include <string.h>
@@ -600,6 +602,82 @@ const struct ec3_extent_info *ec3_image_ioctx_get_extent_info(
return b_buffer_ptr(image->io_extent_table);
}
enum ec3_status ec3_image_ioctx_get_string(
struct ec3_image_ioctx *image,
size_t key,
struct b_string *out)
{
enum ec3_status status = EC3_SUCCESS;
if (!image->io_stab) {
status = ec3_image_ioctx_open_tag_by_type(
image,
EC3_TAG_STAB,
0,
EC3_TAG_IO_READ,
&image->io_stab);
}
if (status != EC3_SUCCESS) {
return status;
}
if (!image->io_stab_buf) {
image->io_stab_buf = malloc(image->io_header.img_cluster_size);
if (!image->io_stab_buf) {
return EC3_ERR_NO_MEMORY;
}
}
size_t nr_clusters = 0;
ec3_tag_ioctx_get_nr_clusters(image->io_stab, &nr_clusters);
size_t max_key = nr_clusters * image->io_header.img_cluster_size;
if (key >= max_key) {
return EC3_ERR_OUT_OF_BOUNDS;
}
size_t cluster = key / image->io_header.img_cluster_size;
size_t byte = key % image->io_header.img_cluster_size;
size_t nr_read;
char *buf = image->io_stab_buf;
bool done = false;
while (!done) {
status = ec3_tag_ioctx_read_cluster(
image->io_stab,
cluster,
buf,
&nr_read);
if (status != EC3_SUCCESS) {
return status;
}
for (;;) {
char c = buf[byte];
if (c == 0) {
done = true;
break;
}
char s[] = {c, 0};
b_string_append_cstr(out, s);
byte++;
if (byte >= nr_read) {
byte = 0;
cluster++;
break;
}
}
}
return EC3_SUCCESS;
}
static uint64_t allocate_tag_id(struct ec3_image_ioctx *image)
{
uint64_t id = 0;