Skip to content

Commit

Permalink
extrect: Sync upstream changes[231217]
Browse files Browse the repository at this point in the history
1.extract: support `--offset` option
2.fuse_win: add `--version` option
3.Optimize code

Signed-off-by: sekaiacg <[email protected]>
  • Loading branch information
sekaiacg committed Dec 21, 2023
1 parent 4c9bfe0 commit 2356594
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
24 changes: 19 additions & 5 deletions extract/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <getopt.h>
#include <erofs/io.h>
#include <erofs/compress.h>
#include "../lib/compressor.h"
#include <erofs/config.h>
#include <erofs/print.h>
#include <sys/time.h>
Expand All @@ -23,12 +24,12 @@ using namespace skkk;
static inline void get_available_compressors(string &ret) {
int i = 0;
bool comma = false;
const char *s;
const struct erofs_algorithm *s;

while ((s = z_erofs_list_available_compressors(&i)) != nullptr) {
if (comma)
ret.append(", ");
ret.append(s);
ret.append(s->name);
comma = true;
}
}
Expand All @@ -39,6 +40,7 @@ static inline void usage() {
BROWN "usage: [options]" COLOR_NONE "\n"
" " GREEN2_BOLD "-h, --help" COLOR_NONE " " BROWN "Display this help and exit" COLOR_NONE "\n"
" " GREEN2_BOLD "-i, --image=[FILE]" COLOR_NONE " " BROWN "Image file" COLOR_NONE "\n"
" " GREEN2_BOLD "--offset=#" COLOR_NONE " " BROWN "skip # bytes at the beginning of IMAGE" COLOR_NONE "\n"
" " GREEN2_BOLD "-p" COLOR_NONE " " BROWN "Print all entrys" COLOR_NONE "\n"
" " GREEN2_BOLD "-P, --print=X" COLOR_NONE " " BROWN "Print the target of path X" COLOR_NONE "\n"
" " GREEN2_BOLD "-x" COLOR_NONE " " BROWN "Extract all items" COLOR_NONE "\n"
Expand Down Expand Up @@ -69,6 +71,7 @@ static struct option arg_options[] = {
{"help", no_argument, nullptr, 'h'},
{"version", no_argument, nullptr, 'V'},
{"image", required_argument, nullptr, 'i'},
{"offset", required_argument, nullptr, 2},
{"outdir", required_argument, nullptr, 'o'},
{"print", required_argument, nullptr, 'P'},
{"overwrite", no_argument, nullptr, 'f'},
Expand Down Expand Up @@ -137,10 +140,11 @@ static int parseAndCheckExtractCfg(int argc, char **argv) {
LOGCD("targetConfigRecurse=%d", eo->targetConfigRecurse);
break;
case 'T':
eo->useMultiThread = true;
if (optarg) {
unsigned int n = strtoul(optarg, nullptr, 10);
if (n > 0) {
char *endPtr;
uint64_t n = strtoull(optarg, &endPtr, 0);
if (*endPtr == '\0') {
eo->useMultiThread = true;
eo->threadNum = n;
}
}
Expand All @@ -149,6 +153,16 @@ static int parseAndCheckExtractCfg(int argc, char **argv) {
eo->extractOnlyConfAndSeLabel = true;
LOGCD("extractOnlyConfAndSeLabel=%d", eo->extractOnlyConfAndSeLabel);
break;
case 2:
if (optarg) {
char *endPtr;
uint64_t n = strtoull(optarg, &endPtr, 0);
if (*endPtr == '\0') {
sbi.diskoffset = n;
LOGCD("offset=%lu", sbi.diskoffset);
}
}
break;
default:
usage();
print_version();
Expand Down
18 changes: 11 additions & 7 deletions fuse/main_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ static struct options {
u64 offset;
unsigned int debug_lvl;
bool show_help;
bool show_version;
bool odebug;
} fusecfg;

Expand All @@ -209,6 +210,7 @@ static const struct fuse_opt option_spec[] = {
OPTION("--offset=%lu", offset),
OPTION("--dbglevel=%u", debug_lvl),
OPTION("--help", show_help),
OPTION("--version", show_version),
FUSE_OPT_KEY("--device=", 1),
FUSE_OPT_END
};
Expand All @@ -219,15 +221,17 @@ static void usage(void)

fputs("usage: [options] IMAGE MOUNTPOINT\n\n"
"Options:\n"
" --offset=# skip # bytes when reading IMAGE\n"
" --offset=# skip # bytes at the beginning of IMAGE\n"
" --dbglevel=# set output message level to # (maximum 9)\n"
" --device=# specify an extra device to be used together\n"
#if FUSE_MAJOR_VERSION < 3
" --help display this help and exit\n"
" --version display erofsfuse version\n"
#endif
"\n", stderr);

#if FUSE_MAJOR_VERSION >= 3
fputs("\nFUSE options:\n", stderr);
fuse_cmdline_help();
#else
fuse_opt_add_arg(&args, ""); /* progname */
Expand Down Expand Up @@ -270,10 +274,10 @@ static int optional_opt_func(void *data, const char *arg, int key,
case FUSE_OPT_KEY_OPT:
if (!strcmp(arg, "-d"))
fusecfg.odebug = true;
break;
default:
DBG_BUGON(1);
break;
if (!strcmp(arg, "-h"))
fusecfg.show_help = true;
if (!strcmp(arg, "-V"))
fusecfg.show_version = true;
}
return 1;
}
Expand Down Expand Up @@ -323,14 +327,14 @@ int main(int argc, char *argv[])
if (ret)
goto err;

if (fusecfg.show_help || !fusecfg.mountpoint)
if (fusecfg.show_help || fusecfg.show_version || !fusecfg.mountpoint)
usage();
cfg.c_dbg_lvl = fusecfg.debug_lvl;

if (fusecfg.odebug && cfg.c_dbg_lvl < EROFS_DBG)
cfg.c_dbg_lvl = EROFS_DBG;

cfg.c_offset = fusecfg.offset;
sbi.diskoffset = fusecfg.offset;

erofsfuse_dumpcfg();
ret = dev_open_ro(&sbi, fusecfg.disk);
Expand Down

0 comments on commit 2356594

Please sign in to comment.