Hi Yong!

On 2025/3/24 10:28, Sheng Yong wrote:
From: Sheng Yong <shengyo...@xiaomi.com>

When attempting to use an archive file, such as APEX on android,
as a file-backed mount source, it fails because EROFS image within
the archive file does not start at offset 0. As a result, a loop
device is still needed to attach the image file at an appropriate
offset first.

To address this issue, this patch parses the `source' parameter in
EROFS to accept a start offset for the file-backed mount. The format
is `/path/to/archive_file:offs', where `offs' represents the start
offset. EROFS will add this offset before performing read requests.

Signed-off-by: Sheng Yong <shengyo...@xiaomi.com>
Signed-off-by: Wang Shuai <wangshua...@xiaomi.com>

Sorry for late reply. Yeah, that is a great feature.

---

...

@@ -411,6 +412,31 @@ static bool erofs_fc_set_dax_mode(struct fs_context *fc, 
unsigned int mode)
  #endif
  }
+static loff_t erofs_fc_parse_source(struct fs_context *fc,
+                                   struct fs_parameter *param)
+{
+       const char *devname = param->string;
+       const char *fofs_start __maybe_unused;
+       loff_t fofs = 0;
+
+       if (!devname || !*devname)
+               return invalfc(fc, "Empty source");
+
+#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
+       fofs_start = strchr(devname, ':');
+       if (!fofs_start)
+               goto out;
+       if (kstrtoll(fofs_start + 1, 0, &fofs) < 0)
+               return invalfc(fc, "Invalid filebacked offset %s", fofs_start);
+       fc->source = kstrndup(devname, fofs_start - devname, GFP_KERNEL);
+       return fofs;
+out:
+#endif
+       fc->source = devname;
+       param->string = NULL;
+       return fofs;
+}

Could we just add a new mount option for this, and apply this feature
for both file-backed mounts and bdev-based mounts?

Twist source option is not quite clean on my side.



+
  static int erofs_fc_parse_param(struct fs_context *fc,
                                struct fs_parameter *param)
  {
@@ -507,6 +533,11 @@ static int erofs_fc_parse_param(struct fs_context *fc,
                errorfc(fc, "%s option not supported", 
erofs_fs_parameters[opt].name);
  #endif
                break;
+       case Opt_source:
+               sbi->dif0.fofs = erofs_fc_parse_source(fc, param);
+               if (sbi->dif0.fofs < 0)
+                       return -EINVAL;
+               break;
        }
        return 0;
  }
@@ -697,6 +728,10 @@ static int erofs_fc_get_tree(struct fs_context *fc)
                file = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0);
                if (IS_ERR(file))
                        return PTR_ERR(file);
+               if (sbi->dif0.fofs + PAGE_SIZE >= 
i_size_read(file_inode(file))) {
+                       fput(file);
+                       return invalf(fc, "Start offset too large");
+               }

I guess we need to verify the offset is block-aligned too.

Thanks,
Gao Xiang

Reply via email to