As a global variable, `oci_cfg->layer_index` is currently default initialized to 0, which carries a specific semantic meaning. Consequently, the current mkfs.erofs command only mistakenly constructs layer 0 of the OCI image when invoked without explicitly specifying the `layer=` option. Moreover, it becomes impossible to specify the image's digest via the `blob=` option, erroneously resulting in EINVAL.
This patch addresses the issue by initializing `oci_cfg->layer_index` to the invalid value -1. Signed-off-by: Yifan Zhao <[email protected]> --- mkfs/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mkfs/main.c b/mkfs/main.c index 5710948..22201d3 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -757,6 +757,8 @@ static int mkfs_parse_oci_options(struct ocierofs_config *oci_cfg, char *options if (!options_str) return 0; + oci_cfg->layer_index = -1; + opt = options_str; q = strchr(opt, ','); if (q) -- 2.43.0
