libfstools: use variable for overlay mount-point
authorRafał Miłecki <rafal@milecki.pl>
Tue, 4 Jan 2022 22:17:30 +0000 (23:17 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 11 Jan 2022 17:52:54 +0000 (18:52 +0100)
This avoids duplicating path over and over.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
libfstools/overlay.c

index 26f0d6e49b911b9aae75f0fd4c23d340af2899b5..67903372d567602cac20fbab0fdc64cbabc1acde 100644 (file)
@@ -344,16 +344,16 @@ jffs2_switch(struct volume *v)
        return 0;
 }
 
-static int overlay_mount_fs(struct volume *v)
+static int overlay_mount_fs(struct volume *v, const char *overlay_mp)
 {
        char *fstype = overlay_fs_name(volume_identify(v));
 
-       if (mkdir("/tmp/overlay", 0755)) {
+       if (mkdir(overlay_mp, 0755)) {
                ULOG_ERR("failed to mkdir /tmp/overlay: %m\n");
                return -1;
        }
 
-       if (mount(v->blk, "/tmp/overlay", fstype,
+       if (mount(v->blk, overlay_mp, fstype,
 #ifdef OVL_MOUNT_FULL_ACCESS_TIME
                MS_RELATIME,
 #else
@@ -415,6 +415,7 @@ int fs_state_set(const char *dir, enum fs_state state)
 
 int mount_overlay(struct volume *v)
 {
+       const char *overlay_mp = "/tmp/overlay";
        char *mp, *fs_name;
        int err;
 
@@ -427,7 +428,7 @@ int mount_overlay(struct volume *v)
                return -1;
        }
 
-       err = overlay_mount_fs(v);
+       err = overlay_mount_fs(v, overlay_mp);
        if (err)
                return err;
 
@@ -435,21 +436,21 @@ int mount_overlay(struct volume *v)
         * Check for extroot config in overlay (rootfs_data) and if present then
         * prefer it over rootfs_data.
         */
-       if (!mount_extroot("/tmp/overlay")) {
+       if (!mount_extroot(overlay_mp)) {
                ULOG_INFO("switched to extroot\n");
                return 0;
        }
 
-       switch(fs_state_get("/tmp/overlay")) {
+       switch (fs_state_get(overlay_mp)) {
        case FS_STATE_UNKNOWN:
-               fs_state_set("/tmp/overlay", FS_STATE_PENDING);
-               if (fs_state_get("/tmp/overlay") != FS_STATE_PENDING) {
+               fs_state_set(overlay_mp, FS_STATE_PENDING);
+               if (fs_state_get(overlay_mp) != FS_STATE_PENDING) {
                        ULOG_ERR("unable to set filesystem state\n");
                        break;
                }
        case FS_STATE_PENDING:
                ULOG_INFO("overlay filesystem has not been fully initialized yet\n");
-               overlay_delete("/tmp/overlay", true);
+               overlay_delete(overlay_mp, true);
                break;
        case FS_STATE_READY:
                break;