// Gets slot_suffix from either the kernel cmdline / firmware or the
// misc partition. Sets |out_suffix| on success and returns 0. Returns
// -1 if slot_suffix could not be determined.
static int get_active_slot_suffix(struct fstab *fstab, char *out_suffix,
                                  size_t suffix_len)
{
    char propbuf[PROPERTY_VALUE_MAX];

    // Get the suffix from the kernel commandline (note that we don't
    // allow the empty suffix). On bootloaders natively supporting A/B
    // we'll hit this path every time so don't bother logging it.
    property_get("ro.boot.slot_suffix", propbuf, "");
    if (propbuf[0] != '\0') {
        strncpy(out_suffix, propbuf, suffix_len);
        return 0;
    }

    // If we couldn't get the suffix from the kernel cmdline, try the
    // the misc partition.
    if (get_active_slot_suffix_from_misc(fstab, out_suffix, suffix_len) == 0) {
        INFO("Using slot suffix \"%s\" from misc\n", out_suffix);
        return 0;
    }

    ERROR("Error determining slot_suffix\n");

    return -1;
}
// Gets slot_suffix from either the kernel cmdline / firmware, the
// misc partition or built-in fallback.
static void get_active_slot_suffix(struct fstab *fstab, char *out_suffix,
                                   size_t suffix_len)
{
    char propbuf[PROPERTY_VALUE_MAX];

    // Get the suffix from the kernel commandline (note that we don't
    // allow the empty suffix). On bootloaders natively supporting A/B
    // we'll hit this path every time so don't bother logging it.
    property_get("ro.boot.slot_suffix", propbuf, "");
    if (propbuf[0] != '\0') {
        strncpy(out_suffix, propbuf, suffix_len);
        return;
    }

    // If we couldn't get the suffix from the kernel cmdline, try the
    // the misc partition.
    if (get_active_slot_suffix_from_misc(fstab, out_suffix, suffix_len) == 0) {
        INFO("Using slot suffix \"%s\" from misc\n", out_suffix);
        return;
    }

    // If that didn't work, fall back to _a. The reasoning here is
    // that since the fstab has the slotselect option set (otherwise
    // we wouldn't end up here) we must assume that partitions are
    // indeed set up for A/B. This corner-case is important because we
    // may be on this codepath on newly provisioned A/B devices where
    // misc isn't set up properly (it's just zeroes) and the
    // bootloader does not (yet) natively support A/B.
    //
    // Why '_a'? Because that's what system/extras/boot_control_copy
    // is using and since the bootloader isn't A/B aware we assume
    // slots are set up this way.
    WARNING("Could not determine slot suffix, falling back to \"_a\"\n");
    strncpy(out_suffix, "_a", suffix_len);
    return;
}