2025-02-23 20:52:59 +00:00
|
|
|
#if 0
|
|
|
|
|
#include "bin.h"
|
|
|
|
|
#include "chunk-table.h"
|
2024-11-02 11:17:36 +00:00
|
|
|
#include "commands.h"
|
2025-02-23 20:52:59 +00:00
|
|
|
#include "misc.h"
|
|
|
|
|
#include "pipeline.h"
|
|
|
|
|
#include "status.h"
|
|
|
|
|
#include "string-table.h"
|
|
|
|
|
#include "write.h"
|
2024-11-02 11:17:36 +00:00
|
|
|
|
|
|
|
|
#include <blue/cmd.h>
|
2025-02-23 20:52:59 +00:00
|
|
|
#include <blue/io/directory.h>
|
|
|
|
|
#include <blue/term/print.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
2024-11-02 11:17:36 +00:00
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 65536
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
OPT_OUTPATH,
|
|
|
|
|
OPT_OUTPATH_PATH,
|
|
|
|
|
|
2025-02-23 20:52:59 +00:00
|
|
|
OPT_IDENT,
|
|
|
|
|
OPT_IDENT_VAL,
|
|
|
|
|
|
|
|
|
|
OPT_DIRECTORY,
|
|
|
|
|
OPT_DIRECTORY_PATH,
|
2024-11-02 11:17:36 +00:00
|
|
|
|
|
|
|
|
OPT_TAGGED_DIRECTORY,
|
|
|
|
|
OPT_TAGGED_DIRECTORY_TAG,
|
|
|
|
|
OPT_TAGGED_DIRECTORY_PATH,
|
|
|
|
|
|
|
|
|
|
OPT_VERBOSE,
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-23 20:52:59 +00:00
|
|
|
static enum ec3_status capture_directory(
|
|
|
|
|
struct ec3_writer *writer,
|
|
|
|
|
struct chunk_table *chunk_tab,
|
|
|
|
|
uint64_t id,
|
|
|
|
|
const char *cpath)
|
|
|
|
|
{
|
|
|
|
|
b_path *path = b_path_create_from_cstr(cpath);
|
|
|
|
|
b_directory *dir;
|
|
|
|
|
b_status status = b_directory_open(NULL, path, &dir);
|
|
|
|
|
b_path_release(path);
|
|
|
|
|
|
|
|
|
|
if (!B_OK(status)) {
|
|
|
|
|
return EC3_ERR_NO_ENTRY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ec3_tag_writer *volu;
|
|
|
|
|
enum ec3_status s2 = ec3_writer_create_tag(
|
|
|
|
|
writer,
|
|
|
|
|
EC3_TAG_WRITER_BUFFERED,
|
|
|
|
|
EC3_TAG_VOLU,
|
|
|
|
|
id,
|
|
|
|
|
0,
|
|
|
|
|
&volu);
|
|
|
|
|
if (s2 != EC3_SUCCESS) {
|
|
|
|
|
b_directory_release(dir);
|
|
|
|
|
return s2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct string_table *stab = ec3_writer_get_strings(writer);
|
|
|
|
|
|
|
|
|
|
b_directory_iterator it;
|
|
|
|
|
b_directory_iterator_begin(dir, &it, B_DIRECTORY_ITERATE_PARENT_FIRST);
|
|
|
|
|
while (b_directory_iterator_is_valid(&it)) {
|
|
|
|
|
printf("%s\n", b_path_ptr(it.filepath));
|
|
|
|
|
size_t key = string_table_get(stab, it.filename);
|
|
|
|
|
b_directory_iterator_next(&it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ec3_tag_writer_finish(volu);
|
|
|
|
|
|
|
|
|
|
b_directory_release(dir);
|
|
|
|
|
return EC3_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-02 11:17:36 +00:00
|
|
|
static int capture(
|
|
|
|
|
const b_command *self,
|
|
|
|
|
const b_arglist *opt,
|
|
|
|
|
const b_array *args)
|
|
|
|
|
{
|
2025-02-23 20:52:59 +00:00
|
|
|
const char *out_path = NULL;
|
|
|
|
|
b_arglist_get_string(opt, OPT_OUTPATH, OPT_OUTPATH_PATH, 0, &out_path);
|
|
|
|
|
|
|
|
|
|
FILE *outp = fopen(out_path, "wb");
|
|
|
|
|
if (!outp) {
|
|
|
|
|
b_err("cannot open '%s'", out_path);
|
|
|
|
|
b_i("reason: %s", strerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ec3_status status = EC3_SUCCESS;
|
|
|
|
|
|
|
|
|
|
uint64_t ident = 0;
|
|
|
|
|
const char *ident_str;
|
|
|
|
|
b_arglist_get_string(opt, OPT_IDENT, OPT_IDENT_VAL, 0, &ident_str);
|
|
|
|
|
if (ident_str) {
|
|
|
|
|
status = ec3_identifier_from_string(ident_str, &ident);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status != EC3_SUCCESS) {
|
|
|
|
|
b_err("'%s' is not a valid container identifier", ident_str);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ec3_writer *writer = NULL;
|
|
|
|
|
struct ec3_parameters param = {
|
|
|
|
|
.p_outp = outp,
|
|
|
|
|
.p_cluster_size = EC3_CLUSTER_16K,
|
|
|
|
|
.p_compression_func = EC3_COMPRESSION_ZSTD,
|
|
|
|
|
.p_ident = ident,
|
|
|
|
|
};
|
|
|
|
|
status = ec3_writer_create(¶m, &writer);
|
|
|
|
|
|
|
|
|
|
if (status != EC3_SUCCESS) {
|
|
|
|
|
b_err("cannot initialise EC3 writer");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t ctab_id, cdat_id;
|
|
|
|
|
ec3_identifier_from_string("_CHKTAB0", &ctab_id);
|
|
|
|
|
ec3_identifier_from_string("_CHKDAT0", &cdat_id);
|
|
|
|
|
|
|
|
|
|
struct ec3_tag_writer *ctab, *cdat;
|
|
|
|
|
status = ec3_writer_create_tag(
|
|
|
|
|
writer,
|
|
|
|
|
EC3_TAG_WRITER_BUFFERED,
|
|
|
|
|
EC3_TAG_CTAB,
|
|
|
|
|
ctab_id,
|
|
|
|
|
0,
|
|
|
|
|
&ctab);
|
|
|
|
|
|
|
|
|
|
if (status != EC3_SUCCESS) {
|
|
|
|
|
b_err("cannot initialise EC3 writer");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = ec3_writer_create_tag(
|
|
|
|
|
writer,
|
|
|
|
|
EC3_TAG_WRITER_BUFFERED,
|
|
|
|
|
EC3_TAG_CDAT,
|
|
|
|
|
cdat_id,
|
|
|
|
|
0,
|
|
|
|
|
&cdat);
|
|
|
|
|
|
|
|
|
|
if (status != EC3_SUCCESS) {
|
|
|
|
|
b_err("cannot initialise EC3 writer");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct chunk_table chunk_tab;
|
|
|
|
|
#if 0
|
|
|
|
|
chunk_table_init_write(
|
|
|
|
|
ctab,
|
|
|
|
|
cdat,
|
|
|
|
|
ec3_get_cluster_size(param.p_cluster_size),
|
|
|
|
|
&chunk_tab);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
uint64_t next_auto_id = 0;
|
|
|
|
|
|
|
|
|
|
b_arglist_iterator it = {0};
|
|
|
|
|
b_arglist_foreach_filtered(&it, opt, OPT_DIRECTORY, OPT_DIRECTORY_PATH)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\n", it.value->val_str);
|
|
|
|
|
|
|
|
|
|
status = capture_directory(
|
|
|
|
|
writer,
|
|
|
|
|
&chunk_tab,
|
|
|
|
|
next_auto_id,
|
|
|
|
|
it.value->val_str);
|
|
|
|
|
next_auto_id++;
|
|
|
|
|
|
|
|
|
|
if (status != EC3_SUCCESS) {
|
|
|
|
|
b_err("an error occurred while writing to the "
|
|
|
|
|
"container");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0;; i++) {
|
|
|
|
|
b_arglist_option *option = NULL;
|
|
|
|
|
b_status err = b_arglist_get_option(
|
|
|
|
|
opt,
|
|
|
|
|
OPT_TAGGED_DIRECTORY,
|
|
|
|
|
i,
|
|
|
|
|
&option);
|
|
|
|
|
if (!option) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b_arglist_value *tag = NULL, *path = NULL;
|
|
|
|
|
err = b_arglist_option_get_value(
|
|
|
|
|
option,
|
|
|
|
|
OPT_TAGGED_DIRECTORY_TAG,
|
|
|
|
|
0,
|
|
|
|
|
&tag);
|
|
|
|
|
err = b_arglist_option_get_value(
|
|
|
|
|
option,
|
|
|
|
|
OPT_TAGGED_DIRECTORY_PATH,
|
|
|
|
|
0,
|
|
|
|
|
&path);
|
|
|
|
|
|
|
|
|
|
printf("%s:%s\n", tag->val_str, path->val_str);
|
|
|
|
|
|
|
|
|
|
uint64_t id = 0;
|
|
|
|
|
status = ec3_identifier_from_string(tag->val_str, &id);
|
|
|
|
|
|
|
|
|
|
if (status != EC3_SUCCESS) {
|
|
|
|
|
b_err("'%s' is not a valid tag identifier", id);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = capture_directory(
|
|
|
|
|
writer,
|
|
|
|
|
&chunk_tab,
|
|
|
|
|
id,
|
|
|
|
|
path->val_str);
|
|
|
|
|
|
|
|
|
|
if (status != EC3_SUCCESS) {
|
|
|
|
|
b_err("an error occurred while writing to the "
|
|
|
|
|
"container");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ec3_tag_writer_finish(ctab);
|
|
|
|
|
ec3_tag_writer_finish(cdat);
|
|
|
|
|
ec3_writer_finish(writer);
|
|
|
|
|
|
|
|
|
|
fclose(outp);
|
|
|
|
|
|
2024-11-02 11:17:36 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
B_COMMAND(CMD_CAPTURE, CMD_ROOT)
|
|
|
|
|
{
|
|
|
|
|
B_COMMAND_NAME("capture");
|
|
|
|
|
B_COMMAND_SHORT_NAME('Z');
|
|
|
|
|
B_COMMAND_DESC(
|
|
|
|
|
"capture one or more directories into an ec3 container. each "
|
|
|
|
|
"directory specified will be stored in a separate volume "
|
|
|
|
|
"within "
|
|
|
|
|
"the created container.");
|
|
|
|
|
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
|
|
|
|
B_COMMAND_FUNCTION(capture);
|
|
|
|
|
|
|
|
|
|
B_COMMAND_HELP_OPTION();
|
|
|
|
|
|
2025-02-23 20:52:59 +00:00
|
|
|
B_COMMAND_OPTION(OPT_IDENT)
|
|
|
|
|
{
|
|
|
|
|
B_OPTION_SHORT_NAME('I');
|
|
|
|
|
B_OPTION_LONG_NAME("ident");
|
|
|
|
|
B_OPTION_DESC(
|
|
|
|
|
"the string or number to use as the container "
|
|
|
|
|
"identifier");
|
|
|
|
|
|
|
|
|
|
B_OPTION_ARG(OPT_IDENT_VAL)
|
|
|
|
|
{
|
|
|
|
|
B_ARG_NAME("value");
|
|
|
|
|
B_ARG_NR_VALUES(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-02 11:17:36 +00:00
|
|
|
B_COMMAND_OPTION(OPT_OUTPATH)
|
|
|
|
|
{
|
|
|
|
|
B_OPTION_SHORT_NAME('o');
|
|
|
|
|
B_OPTION_LONG_NAME("out");
|
|
|
|
|
B_OPTION_DESC("the path to save the new file to.");
|
|
|
|
|
|
|
|
|
|
B_OPTION_ARG(OPT_OUTPATH_PATH)
|
|
|
|
|
{
|
|
|
|
|
B_ARG_NAME("path");
|
|
|
|
|
B_ARG_NR_VALUES(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 20:52:59 +00:00
|
|
|
B_COMMAND_OPTION(OPT_DIRECTORY)
|
2024-11-02 11:17:36 +00:00
|
|
|
{
|
2025-02-23 20:52:59 +00:00
|
|
|
B_OPTION_SHORT_NAME('d');
|
|
|
|
|
B_OPTION_LONG_NAME("directory");
|
|
|
|
|
B_OPTION_DESC(
|
2024-11-02 11:17:36 +00:00
|
|
|
"a directory to add to the container. a volume "
|
|
|
|
|
"will be created "
|
|
|
|
|
"within the container to store the specified "
|
|
|
|
|
"directory.");
|
|
|
|
|
|
2025-02-23 20:52:59 +00:00
|
|
|
B_OPTION_ARG(OPT_DIRECTORY_PATH)
|
|
|
|
|
{
|
|
|
|
|
B_ARG_NAME("path");
|
|
|
|
|
B_ARG_NR_VALUES(1);
|
|
|
|
|
}
|
2024-11-02 11:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
B_COMMAND_OPTION(OPT_TAGGED_DIRECTORY)
|
|
|
|
|
{
|
|
|
|
|
B_OPTION_SHORT_NAME('D');
|
|
|
|
|
B_OPTION_LONG_NAME("tagged-directory");
|
|
|
|
|
B_OPTION_DESC(
|
|
|
|
|
"a file to add to the container, with an associated "
|
|
|
|
|
"tag. a disk "
|
|
|
|
|
"image will be created within the container to store "
|
|
|
|
|
"the specified "
|
|
|
|
|
"directory. the tag must be either: (a) a 64-bit "
|
|
|
|
|
"hexadecimal "
|
|
|
|
|
"number; or (b) a string of no more than 8 "
|
|
|
|
|
"characters.");
|
|
|
|
|
|
|
|
|
|
B_OPTION_ARG(OPT_TAGGED_DIRECTORY_TAG)
|
|
|
|
|
{
|
|
|
|
|
B_ARG_NAME("tag");
|
|
|
|
|
B_ARG_NR_VALUES(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
B_OPTION_ARG(OPT_TAGGED_DIRECTORY_PATH)
|
|
|
|
|
{
|
|
|
|
|
B_ARG_NAME("path");
|
|
|
|
|
B_ARG_NR_VALUES(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
B_COMMAND_OPTION(OPT_VERBOSE)
|
|
|
|
|
{
|
|
|
|
|
B_OPTION_SHORT_NAME('v');
|
|
|
|
|
B_OPTION_LONG_NAME("verbose");
|
|
|
|
|
B_OPTION_DESC(
|
|
|
|
|
"show detailed output logs. this option can be "
|
|
|
|
|
"specified multiple "
|
|
|
|
|
"times to increase the level of output.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
B_COMMAND_USAGE()
|
|
|
|
|
{
|
|
|
|
|
B_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
2025-02-23 20:52:59 +00:00
|
|
|
B_COMMAND_USAGE_OPT(OPT_DIRECTORY);
|
2024-11-02 11:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
B_COMMAND_USAGE()
|
|
|
|
|
{
|
|
|
|
|
B_COMMAND_USAGE_OPT(OPT_OUTPATH);
|
|
|
|
|
B_COMMAND_USAGE_OPT(OPT_TAGGED_DIRECTORY);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-23 20:52:59 +00:00
|
|
|
#endif
|