Home | History | Annotate | Download | only in fs_mgr
      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 
     17 #include <stdio.h>
     18 
     19 #include <string>
     20 
     21 #include "fs_mgr.h"
     22 #include "fs_mgr_priv.h"
     23 
     24 // Returns "_a" or "_b" based on androidboot.slot_suffix in kernel cmdline, or an empty string
     25 // if that parameter does not exist.
     26 std::string fs_mgr_get_slot_suffix() {
     27     std::string ab_suffix;
     28 
     29     fs_mgr_get_boot_config("slot_suffix", &ab_suffix);
     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) {
     35     int n;
     36     std::string ab_suffix;
     37 
     38     for (n = 0; n < fstab->num_entries; n++) {
     39         if (fstab->recs[n].fs_mgr_flags & MF_SLOTSELECT) {
     40             char *tmp;
     41             if (ab_suffix.empty()) {
     42                 ab_suffix = fs_mgr_get_slot_suffix();
     43                 // Return false if failed to get ab_suffix when MF_SLOTSELECT is specified.
     44                 if (ab_suffix.empty()) return false;
     45             }
     46             if (asprintf(&tmp, "%s%s", fstab->recs[n].blk_device, ab_suffix.c_str()) > 0) {
     47                 free(fstab->recs[n].blk_device);
     48                 fstab->recs[n].blk_device = tmp;
     49             } else {
     50                 return false;
     51             }
     52         }
     53     }
     54     return true;
     55 }
     56