libfstools: skip JFFS2 padding when BLOCKSIZE was given master
authorDaniel Golle <daniel@makrotopia.org>
Sun, 14 Jul 2024 18:21:09 +0000 (19:21 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 14 Jul 2024 18:40:03 +0000 (19:40 +0100)
When BLOCKSIZE is defined we call padjffs2 with the defined alignment
to pad towards. That results in one of more block of all-1s instead of
the expected 0xdeadc0de and ultimaltely breaks restoring configuration
as fstools won't look for a the GZ signature indicating the config
backup in this case.
Change that and also look for config backup when all-1s are used for
padding.

Fixes: ee54c6b ("libfstools: skip JFFS2 padding on block devices")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
libfstools/common.c
libfstools/fit.c
libfstools/rootdisk.c

index 6c513f0f9225abde555e492b0bd0bd8c38b88221..82362f7b59c115116031de342d3757b9d5a30213 100644 (file)
@@ -122,6 +122,7 @@ int block_volume_format(struct volume *v, uint64_t offset, const char *bdev)
 
        switch (volume_identify(v)) {
        case FS_DEADCODE:
+       case FS_NONE:
                /* skip padding */
                fd = open(v->blk, O_RDONLY);
                if (fd < 0) {
@@ -159,8 +160,6 @@ int block_volume_format(struct volume *v, uint64_t offset, const char *bdev)
                        ULOG_ERR("failed extracting config backup from %s\n", v->blk);
                        break;
                }
-               /* fall-through */
-       case FS_NONE:
 do_format:
                ULOG_INFO("overlay filesystem in %s has not been formatted yet\n", v->blk);
                if (use_f2fs(v, offset, bdev))
index b0da854a7623f087875bf233db53c5881124fc50..a8f0c6648ad30ac81821ec388a0505c444b4f32c 100644 (file)
@@ -3,6 +3,7 @@
 #include "common.h"
 
 #define BUFLEN 64
+#define DEVPATHSTR_SIZE 15
 
 static const char *const fit0 = "/dev/fit0";
 static const char *const fitrw = "/dev/fitrw";
@@ -15,7 +16,7 @@ struct devpath {
 struct fit_volume {
        struct volume v;
        union {
-               char devpathstr[16];
+               char devpathstr[DEVPATHSTR_SIZE+1];
                struct devpath devpath;
        } dev;
 };
@@ -79,7 +80,7 @@ static struct volume *fit_volume_find(char *name)
        if (!p)
                return NULL;
 
-       strcpy(p->dev.devpathstr, fname);
+       strncpy(p->dev.devpathstr, fname, DEVPATHSTR_SIZE);
        p->v.drv = &fit_driver;
        p->v.blk = p->dev.devpathstr;
        p->v.name = name;
index ba7d8c3727ba6c67123d544344dcfa215070becb..910899a141b82beeff4d58563723080ae4e3bfda 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/loop.h>
 
 #define ROOTDEV_OVERLAY_ALIGN  (64ULL * 1024ULL)
-#define F2FS_MINSIZE           (100ULL * 1024ULL * 1024ULL)
 
 struct squashfs_super_block {
        uint32_t s_magic;