David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 1 | /* |
| 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 Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 17 | #include <stdio.h> |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 18 | |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 19 | #include <string> |
| 20 | |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 21 | #include "fs_mgr.h" |
| 22 | #include "fs_mgr_priv.h" |
| 23 | |
Tom Cherry | 211a4a5 | 2017-09-25 16:04:30 +0000 | [diff] [blame] | 24 | // Returns "_a" or "_b" based on androidboot.slot_suffix in kernel cmdline, or an empty string |
| 25 | // if that parameter does not exist. |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 26 | std::string fs_mgr_get_slot_suffix() { |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 27 | std::string ab_suffix; |
| 28 | |
Tom Cherry | 211a4a5 | 2017-09-25 16:04:30 +0000 | [diff] [blame] | 29 | fs_mgr_get_boot_config("slot_suffix", &ab_suffix); |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 30 | return ab_suffix; |
| 31 | } |
| 32 | |
| 33 | // Updates |fstab| for slot_suffix. Returns true on success, false on error. |
| 34 | bool fs_mgr_update_for_slotselect(struct fstab *fstab) { |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 35 | int n; |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 36 | std::string ab_suffix; |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 37 | |
| 38 | for (n = 0; n < fstab->num_entries; n++) { |
| 39 | if (fstab->recs[n].fs_mgr_flags & MF_SLOTSELECT) { |
| 40 | char *tmp; |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 41 | if (ab_suffix.empty()) { |
| 42 | ab_suffix = fs_mgr_get_slot_suffix(); |
Bowgo Tsai | ec19cf6 | 2017-11-09 22:26:04 +0800 | [diff] [blame] | 43 | // Return false if failed to get ab_suffix when MF_SLOTSELECT is specified. |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 44 | if (ab_suffix.empty()) return false; |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 45 | } |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 46 | if (asprintf(&tmp, "%s%s", fstab->recs[n].blk_device, ab_suffix.c_str()) > 0) { |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 47 | free(fstab->recs[n].blk_device); |
| 48 | fstab->recs[n].blk_device = tmp; |
| 49 | } else { |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 50 | return false; |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | } |
Bowgo Tsai | 87d0836 | 2017-04-05 00:02:33 +0800 | [diff] [blame] | 54 | return true; |
David Zeuthen | 227ef3c | 2015-09-03 12:23:12 -0400 | [diff] [blame] | 55 | } |