From: Li He <lihe@uniontech.com>
To: hsiangkao@linux.alibaba.com
Cc: linux-erofs@lists.ozlabs.org
Subject: [PATCH] erofs-utils: fuse: support offset when read image
Date: Mon, 11 Jul 2022 16:54:59 +0800 [thread overview]
Message-ID: <20220711085459.19730-1-lihe@uniontech.com> (raw)
In-Reply-To: <YsuejqlGUUp3cC4S@B-P7TQMD6M-0146.local>
Add --offset to erofsfuse to skip bytes at the start of the image file.
Signed-off-by: Li He <lihe@uniontech.com>
---
We should add offset to fuse_operations so erofsfuse can parse it from
command line. fuse_opt_parse can not parse cfg directly.
Changes since v0
+ Add manpage for erofsfuse offset option
fuse/main.c | 6 ++++++
include/erofs/config.h | 3 +++
lib/io.c | 2 ++
man/erofsfuse.1 | 3 +++
4 files changed, 14 insertions(+)
diff --git a/fuse/main.c b/fuse/main.c
index f4c2476..a2a6449 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -151,6 +151,7 @@ static struct fuse_operations erofs_ops = {
static struct options {
const char *disk;
const char *mountpoint;
+ u64 offset;
unsigned int debug_lvl;
bool show_help;
bool odebug;
@@ -158,6 +159,7 @@ static struct options {
#define OPTION(t, p) { t, offsetof(struct options, p), 1 }
static const struct fuse_opt option_spec[] = {
+ OPTION("--offset=%lu", offset),
OPTION("--dbglevel=%u", debug_lvl),
OPTION("--help", show_help),
FUSE_OPT_KEY("--device=", 1),
@@ -170,6 +172,7 @@ static void usage(void)
fputs("usage: [options] IMAGE MOUNTPOINT\n\n"
"Options:\n"
+ " --offset=# # bytes to skip when read 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
@@ -190,6 +193,7 @@ static void usage(void)
static void erofsfuse_dumpcfg(void)
{
erofs_dump("disk: %s\n", fusecfg.disk);
+ erofs_dump("offset: %lu\n", fusecfg.offset);
erofs_dump("mountpoint: %s\n", fusecfg.mountpoint);
erofs_dump("dbglevel: %u\n", cfg.c_dbg_lvl);
}
@@ -279,6 +283,8 @@ int main(int argc, char *argv[])
if (fusecfg.odebug && cfg.c_dbg_lvl < EROFS_DBG)
cfg.c_dbg_lvl = EROFS_DBG;
+ cfg.c_offset = fusecfg.offset;
+
erofsfuse_dumpcfg();
ret = dev_open_ro(fusecfg.disk);
if (ret) {
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 0d0916c..8b6f7db 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -73,6 +73,9 @@ struct erofs_configure {
char *fs_config_file;
char *block_list_file;
#endif
+
+ /* offset when read mutli partiton image */
+ u64 c_offset;
};
extern struct erofs_configure cfg;
diff --git a/lib/io.c b/lib/io.c
index 9c663c5..524cfb4 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -261,6 +261,8 @@ int dev_read(int device_id, void *buf, u64 offset, size_t len)
if (cfg.c_dry_run)
return 0;
+ offset += cfg.c_offset;
+
if (!buf) {
erofs_err("buf is NULL");
return -EINVAL;
diff --git a/man/erofsfuse.1 b/man/erofsfuse.1
index 9db6827..1d47163 100644
--- a/man/erofsfuse.1
+++ b/man/erofsfuse.1
@@ -26,6 +26,9 @@ warning messages.
.BI "\-\-device=" path
Specify an extra device to be used together.
You may give multiple `--device' options in the correct order.
+.TP
+.BI "\-\-offset=" #
+Specify offset bytes to skip when read image file. The default is 0.
.SS "FUSE options:"
.TP
\fB-d -o\fR debug
--
2.20.1
next prev parent reply other threads:[~2022-07-11 8:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 2:47 [PATCH] erofs-utils: fuse: support offset when read image Li He
2022-07-11 3:52 ` Gao Xiang
2022-07-11 8:54 ` Li He [this message]
2022-07-11 9:51 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220711085459.19730-1-lihe@uniontech.com \
--to=lihe@uniontech.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.