blob: 0a113b47eab035fd961cbe708c53a8ab3bac0066 [file] [log] [blame]
David Zeuthen227ef3c2015-09-03 12:23:12 -04001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
David Zeuthen227ef3c2015-09-03 12:23:12 -040017#include <stdio.h>
David Zeuthen227ef3c2015-09-03 12:23:12 -040018
Bowgo Tsai87d08362017-04-05 00:02:33 +080019#include <string>
20
David Zeuthen227ef3c2015-09-03 12:23:12 -040021#include "fs_mgr.h"
22#include "fs_mgr_priv.h"
23
Tom Cherry211a4a52017-09-25 16:04:30 +000024// Returns "_a" or "_b" based on androidboot.slot_suffix in kernel cmdline, or an empty string
25// if that parameter does not exist.
Bowgo Tsai87d08362017-04-05 00:02:33 +080026std::string fs_mgr_get_slot_suffix() {
Bowgo Tsai87d08362017-04-05 00:02:33 +080027 std::string ab_suffix;
28
Tom Cherry211a4a52017-09-25 16:04:30 +000029 fs_mgr_get_boot_config("slot_suffix", &ab_suffix);
Bowgo Tsai87d08362017-04-05 00:02:33 +080030 return ab_suffix;
31}
32
33// Updates |fstab| for slot_suffix. Returns true on success, false on error.
34bool fs_mgr_update_for_slotselect(struct fstab *fstab) {
David Zeuthen227ef3c2015-09-03 12:23:12 -040035 int n;
Bowgo Tsai87d08362017-04-05 00:02:33 +080036 std::string ab_suffix;
David Zeuthen227ef3c2015-09-03 12:23:12 -040037
38 for (n = 0; n < fstab->num_entries; n++) {
39 if (fstab->recs[n].fs_mgr_flags & MF_SLOTSELECT) {
40 char *tmp;
Bowgo Tsai87d08362017-04-05 00:02:33 +080041 if (ab_suffix.empty()) {
42 ab_suffix = fs_mgr_get_slot_suffix();
Bowgo Tsaiec19cf62017-11-09 22:26:04 +080043 // Return false if failed to get ab_suffix when MF_SLOTSELECT is specified.
Bowgo Tsai87d08362017-04-05 00:02:33 +080044 if (ab_suffix.empty()) return false;
David Zeuthen227ef3c2015-09-03 12:23:12 -040045 }
Bowgo Tsai87d08362017-04-05 00:02:33 +080046 if (asprintf(&tmp, "%s%s", fstab->recs[n].blk_device, ab_suffix.c_str()) > 0) {
David Zeuthen227ef3c2015-09-03 12:23:12 -040047 free(fstab->recs[n].blk_device);
48 fstab->recs[n].blk_device = tmp;
49 } else {
Bowgo Tsai87d08362017-04-05 00:02:33 +080050 return false;
David Zeuthen227ef3c2015-09-03 12:23:12 -040051 }
52 }
53 }
Bowgo Tsai87d08362017-04-05 00:02:33 +080054 return true;
David Zeuthen227ef3c2015-09-03 12:23:12 -040055}