mount: fix sysupgrade handling for mainline overlayfs
authorFelix Fietkau <nbd@openwrt.org>
Mon, 1 Dec 2014 21:04:49 +0000 (22:04 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 1 Dec 2014 21:04:49 +0000 (22:04 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
libfstools/mount.c

index 970b9cfaf81fc3f2a23327f0664f6dfaf7312ff6..e095455eebe702c513833c5860c1768fec8f2133 100644 (file)
@@ -98,10 +98,13 @@ fopivot(char *rw_root, char *ro_root)
         */
        snprintf(lowerdir, sizeof(lowerdir), "lowerdir=/,upperdir=%s", rw_root);
        if (mount(overlay, "/mnt", "overlayfs", MS_NOATIME, lowerdir)) {
-               char upperdir[64], workdir[64];
+               char upperdir[64], workdir[64], upgrade[64], upgrade_dest[64];
+               struct stat st;
 
                snprintf(upperdir, sizeof(upperdir), "%s/upper", rw_root);
                snprintf(workdir, sizeof(workdir), "%s/work", rw_root);
+               snprintf(upgrade, sizeof(upgrade), "%s/sysupgrade.tgz", rw_root);
+               snprintf(upgrade_dest, sizeof(upgrade_dest), "%s/sysupgrade.tgz", upperdir);
                snprintf(lowerdir, sizeof(lowerdir), "lowerdir=/,upperdir=%s,workdir=%s",
                         upperdir, workdir);
 
@@ -115,6 +118,9 @@ fopivot(char *rw_root, char *ro_root)
                mkdir(upperdir, 0755);
                mkdir(workdir, 0755);
 
+               if (stat(upgrade, &st) == 0)
+                   rename(upgrade, upgrade_dest);
+
                /* Mainlined overlayfs has been renamed to "overlay", try that first */
                if (mount(overlay, "/mnt", "overlay", MS_NOATIME, lowerdir)) {
                        if (mount(overlay, "/mnt", "overlayfs", MS_NOATIME, lowerdir)) {