Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13a66050 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

fs_mgr: overlay: split out fs_mgr_overlayfs_create_scratch()

Reduce some complexity in fs_mgr_overlayfs_setup_scratch()

Test: adb-remount-test.sh
Bug: 119885423
Change-Id: Idb769991f6342739c75654b1d42ab8f8633cbadf
parent d14eb573
Loading
Loading
Loading
Loading
+21 −9
Original line number Original line Diff line number Diff line
@@ -674,11 +674,11 @@ bool fs_mgr_overlayfs_make_scratch(const std::string& scratch_device, const std:
    return true;
    return true;
}
}


// Create and mount kScratchMountPoint storage if we have logical partitions
bool fs_mgr_overlayfs_create_scratch(const fstab* fstab, std::string* scratch_device,
bool fs_mgr_overlayfs_setup_scratch(const fstab* fstab, bool* change) {
                                     bool* partition_exists, bool* change) {
    if (fs_mgr_overlayfs_already_mounted(kScratchMountPoint, false)) return true;
    *scratch_device = fs_mgr_overlayfs_scratch_device();
    auto scratch_device = fs_mgr_overlayfs_scratch_device();
    *partition_exists = fs_mgr_rw_access(*scratch_device);
    auto partition_create = !fs_mgr_rw_access(scratch_device);
    auto partition_create = !*partition_exists;
    auto slot_number = fs_mgr_overlayfs_slot_number();
    auto slot_number = fs_mgr_overlayfs_slot_number();
    auto super_device = fs_mgr_overlayfs_super_device(slot_number);
    auto super_device = fs_mgr_overlayfs_super_device(slot_number);
    if (!fs_mgr_rw_access(super_device)) return false;
    if (!fs_mgr_rw_access(super_device)) return false;
@@ -690,9 +690,9 @@ bool fs_mgr_overlayfs_setup_scratch(const fstab* fstab, bool* change) {
    }
    }
    const auto partition_name = android::base::Basename(kScratchMountPoint);
    const auto partition_name = android::base::Basename(kScratchMountPoint);
    auto partition = builder->FindPartition(partition_name);
    auto partition = builder->FindPartition(partition_name);
    auto partition_exists = partition != nullptr;
    *partition_exists = partition != nullptr;
    auto changed = false;
    auto changed = false;
    if (!partition_exists) {
    if (!*partition_exists) {
        partition = builder->AddPartition(partition_name, LP_PARTITION_ATTR_NONE);
        partition = builder->AddPartition(partition_name, LP_PARTITION_ATTR_NONE);
        if (!partition) {
        if (!partition) {
            LERROR << "create " << partition_name;
            LERROR << "create " << partition_name;
@@ -728,7 +728,7 @@ bool fs_mgr_overlayfs_setup_scratch(const fstab* fstab, bool* change) {
                }
                }
                if (!partition_create) DestroyLogicalPartition(partition_name, 10s);
                if (!partition_create) DestroyLogicalPartition(partition_name, 10s);
                changed = true;
                changed = true;
                partition_exists = false;
                *partition_exists = false;
            }
            }
        }
        }
    }
    }
@@ -745,11 +745,23 @@ bool fs_mgr_overlayfs_setup_scratch(const fstab* fstab, bool* change) {


    if (changed || partition_create) {
    if (changed || partition_create) {
        if (!CreateLogicalPartition(super_device, slot_number, partition_name, true, 0s,
        if (!CreateLogicalPartition(super_device, slot_number, partition_name, true, 0s,
                                    &scratch_device))
                                    scratch_device))
            return false;
            return false;


        if (change) *change = true;
        if (change) *change = true;
    }
    }
    return true;
}

// Create and mount kScratchMountPoint storage if we have logical partitions
bool fs_mgr_overlayfs_setup_scratch(const fstab* fstab, bool* change) {
    if (fs_mgr_overlayfs_already_mounted(kScratchMountPoint, false)) return true;

    std::string scratch_device;
    bool partition_exists;
    if (!fs_mgr_overlayfs_create_scratch(fstab, &scratch_device, &partition_exists, change)) {
        return false;
    }


    // If the partition exists, assume first that it can be mounted.
    // If the partition exists, assume first that it can be mounted.
    auto mnt_type = fs_mgr_overlayfs_scratch_mount_type();
    auto mnt_type = fs_mgr_overlayfs_scratch_mount_type();