Skip to contentSkip to conversation

erofs-utils: fuse: support offset when read image

PATCH In review Li He 2 participants 4 messages Jul 11, 2022 Library code

lore
Share & tools
lore

Li He

author
#0 lore raw

PATCH 1/1 erofs-utils: fuse: support offset when read image

Add --offset to erofsfuse to skip bytes at the start of the image file.

---
 fuse/main.c            | 6 ++++++
 include/erofs/config.h | 3 +++
 lib/io.c               | 2 ++
 3 files changed, 11 insertions(+)
fuse/main.c +6 -0
index f4c2476..a2a6449 100644
@@ -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) {
include/erofs/config.h +3 -0
index 0d0916c..8b6f7db 100644
@@ -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;
lib/io.c +2 -0
index 9c663c5..524cfb4 100644
@@ -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;
Signature · 1 line
2.20.1
#1 lore raw

Hi He,

Quoted 3 lines · Li He

Add --offset to erofsfuse to skip bytes at the start of the image file.

Thanks for the patch! The patch roughly looks good to me, some nit as below..

Quoted 11 lines
---
 fuse/main.c            | 6 ++++++
 include/erofs/config.h | 3 +++
 lib/io.c               | 2 ++
 3 files changed, 11 insertions(+)
fuse/main.c +0 -0
index f4c2476..a2a6449 100644

fuse/main.c static struct fuse_operations erofs_ops = { · line 154

Quoted 4 lines
fuse/main.c +1 -0
@@ -151,6 +151,7 @@ static struct fuse_operations erofs_ops = {
 static struct options {
 	const char *disk;
 	const char *mountpoint;
+	u64 offset;

We can use cfg.c_offset directly instead it seems?

Quoted 12 lines
fuse/main.c +1 -0
 	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),

fuse/main.c static void usage(void) · line 175

Quoted 4 lines
fuse/main.c +1 -0
@@ -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"

need to update manpage as well...

Thanks,
Gao Xiang

Quoted 51 lines
fuse/main.c +3 -0
 	      "    --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) {
include/erofs/config.h +3 -0
index 0d0916c..8b6f7db 100644
@@ -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;
lib/io.c +2 -0
index 9c663c5..524cfb4 100644
@@ -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;
Signature · 1 line
2.20.1
author
#2 lore raw

PATCH 1/1 erofs-utils: fuse: support offset when read image

Add --offset to erofsfuse to skip bytes at the start of the image file.

---
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(+)
fuse/main.c +6 -0
index f4c2476..a2a6449 100644
@@ -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) {
include/erofs/config.h +3 -0
index 0d0916c..8b6f7db 100644
@@ -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;
lib/io.c +2 -0
index 9c663c5..524cfb4 100644
@@ -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;
man/erofsfuse.1 +3 -0
index 9db6827..1d47163 100644
@@ -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
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#3 lore raw
Quoted 6 lines · Li He

Add --offset to erofsfuse to skip bytes at the start of the image file.

---
We should add offset to fuse_operations so erofsfuse can parse it from command line. fuse_opt_parse can not parse cfg directly.

Oh, I forgot that, looks good to me now!

Thanks,
Gao Xiang