Merge "Move over to the C++ Fstab class" am: b6d5cd20d7 am: 4e8e70a949
am: f61f61a6a0
Change-Id: I90f0f0e1161463cef8542a586b53274ec5a2f5ee
diff --git a/Checkpoint.cpp b/Checkpoint.cpp
index 7a29514..633bd1f 100644
--- a/Checkpoint.cpp
+++ b/Checkpoint.cpp
@@ -39,6 +39,9 @@
using android::base::SetProperty;
using android::binder::Status;
+using android::fs_mgr::Fstab;
+using android::fs_mgr::ReadDefaultFstab;
+using android::fs_mgr::ReadFstabFromFile;
using android::hardware::hidl_string;
using android::hardware::boot::V1_0::BoolResult;
using android::hardware::boot::V1_0::IBootControl;
@@ -69,12 +72,13 @@
Status cp_supportsCheckpoint(bool& result) {
result = false;
- auto fstab_default = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
- fs_mgr_read_fstab_default(), fs_mgr_free_fstab};
- if (!fstab_default) return Status::fromExceptionCode(EINVAL, "Failed to get fstab");
+ Fstab fstab_default;
+ if (!ReadDefaultFstab(&fstab_default)) {
+ return Status::fromExceptionCode(EINVAL, "Failed to get fstab");
+ }
- for (int i = 0; i < fstab_default->num_entries; ++i) {
- if (fs_mgr_is_checkpoint(&fstab_default->recs[i])) {
+ for (const auto& entry : fstab_default) {
+ if (entry.fs_mgr_flags.checkpoint_blk || entry.fs_mgr_flags.checkpoint_fs) {
result = true;
return Status::ok();
}
@@ -112,32 +116,31 @@
// But we also need to get the matching fstab entries to see
// the original flags
std::string err_str;
- auto fstab_default = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
- fs_mgr_read_fstab_default(), fs_mgr_free_fstab};
- if (!fstab_default) return Status::fromExceptionCode(EINVAL, "Failed to get fstab");
+ Fstab fstab_default;
+ if (!ReadDefaultFstab(&fstab_default)) {
+ return Status::fromExceptionCode(EINVAL, "Failed to get fstab");
+ }
- auto mounts = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
- fs_mgr_read_fstab("/proc/mounts"), fs_mgr_free_fstab};
- if (!mounts) return Status::fromExceptionCode(EINVAL, "Failed to get /proc/mounts");
+ Fstab mounts;
+ if (!ReadFstabFromFile("/proc/mounts", &mounts)) {
+ return Status::fromExceptionCode(EINVAL, "Failed to get /proc/mounts");
+ }
// Walk mounted file systems
- for (int i = 0; i < mounts->num_entries; ++i) {
- const fstab_rec* mount_rec = &mounts->recs[i];
- const fstab_rec* fstab_rec =
- fs_mgr_get_entry_for_mount_point(fstab_default.get(), mount_rec->mount_point);
+ for (const auto& mount_rec : mounts) {
+ const auto fstab_rec = GetEntryForMountPoint(&fstab_default, mount_rec.mount_point);
if (!fstab_rec) continue;
- if (fs_mgr_is_checkpoint_fs(fstab_rec)) {
- if (!strcmp(fstab_rec->fs_type, "f2fs")) {
- std::string options = mount_rec->fs_options;
- options += ",checkpoint=enable";
- if (mount(mount_rec->blk_device, mount_rec->mount_point, "none",
+ if (fstab_rec->fs_mgr_flags.checkpoint_fs) {
+ if (fstab_rec->fs_type == "f2fs") {
+ std::string options = mount_rec.fs_options + ",checkpoint=enable";
+ if (mount(mount_rec.blk_device.c_str(), mount_rec.mount_point.c_str(), "none",
MS_REMOUNT | fstab_rec->flags, options.c_str())) {
return Status::fromExceptionCode(EINVAL, "Failed to remount");
}
}
- } else if (fs_mgr_is_checkpoint_blk(fstab_rec)) {
- if (!setBowState(mount_rec->blk_device, "2"))
+ } else if (fstab_rec->fs_mgr_flags.checkpoint_blk) {
+ if (!setBowState(mount_rec.blk_device, "2"))
return Status::fromExceptionCode(EINVAL, "Failed to set bow state");
}
}
@@ -194,36 +197,36 @@
}
Status cp_prepareCheckpoint() {
- auto fstab_default = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
- fs_mgr_read_fstab_default(), fs_mgr_free_fstab};
- if (!fstab_default) return Status::fromExceptionCode(EINVAL, "Failed to get fstab");
+ Fstab fstab_default;
+ if (!ReadDefaultFstab(&fstab_default)) {
+ return Status::fromExceptionCode(EINVAL, "Failed to get fstab");
+ }
- auto mounts = std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>{
- fs_mgr_read_fstab("/proc/mounts"), fs_mgr_free_fstab};
- if (!mounts) return Status::fromExceptionCode(EINVAL, "Failed to get /proc/mounts");
+ Fstab mounts;
+ if (!ReadFstabFromFile("/proc/mounts", &mounts)) {
+ return Status::fromExceptionCode(EINVAL, "Failed to get /proc/mounts");
+ }
- for (int i = 0; i < mounts->num_entries; ++i) {
- const fstab_rec* mount_rec = &mounts->recs[i];
- const fstab_rec* fstab_rec =
- fs_mgr_get_entry_for_mount_point(fstab_default.get(), mount_rec->mount_point);
+ for (const auto& mount_rec : mounts) {
+ const auto fstab_rec = GetEntryForMountPoint(&fstab_default, mount_rec.mount_point);
if (!fstab_rec) continue;
- if (fs_mgr_is_checkpoint_blk(fstab_rec)) {
+ if (fstab_rec->fs_mgr_flags.checkpoint_blk) {
android::base::unique_fd fd(
- TEMP_FAILURE_RETRY(open(mount_rec->mount_point, O_RDONLY | O_CLOEXEC)));
+ TEMP_FAILURE_RETRY(open(mount_rec.mount_point.c_str(), O_RDONLY | O_CLOEXEC)));
if (!fd) {
- PLOG(ERROR) << "Failed to open mount point" << mount_rec->mount_point;
+ PLOG(ERROR) << "Failed to open mount point" << mount_rec.mount_point;
continue;
}
struct fstrim_range range = {};
range.len = ULLONG_MAX;
if (ioctl(fd, FITRIM, &range)) {
- PLOG(ERROR) << "Failed to trim " << mount_rec->mount_point;
+ PLOG(ERROR) << "Failed to trim " << mount_rec.mount_point;
continue;
}
- setBowState(mount_rec->blk_device, "1");
+ setBowState(mount_rec.blk_device, "1");
}
}
return Status::ok();
diff --git a/FsCrypt.cpp b/FsCrypt.cpp
index 97f2619..e810d58 100644
--- a/FsCrypt.cpp
+++ b/FsCrypt.cpp
@@ -61,6 +61,7 @@
using android::base::StringPrintf;
using android::base::WriteStringToFile;
+using android::fs_mgr::GetEntryForMountPoint;
using android::vold::kEmptyAuthentication;
using android::vold::KeyBuffer;
@@ -276,12 +277,12 @@
}
static void get_data_file_encryption_modes(PolicyKeyRef* key_ref) {
- struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab_default, DATA_MNT_POINT);
- char const* contents_mode;
- char const* filenames_mode;
- fs_mgr_get_file_encryption_modes(rec, &contents_mode, &filenames_mode);
- key_ref->contents_mode = contents_mode;
- key_ref->filenames_mode = filenames_mode;
+ auto entry = GetEntryForMountPoint(&fstab_default, DATA_MNT_POINT);
+ if (entry == nullptr) {
+ return;
+ }
+ key_ref->contents_mode = entry->file_contents_mode;
+ key_ref->filenames_mode = entry->file_names_mode;
}
static bool ensure_policy(const PolicyKeyRef& key_ref, const std::string& path) {
diff --git a/IdleMaint.cpp b/IdleMaint.cpp
index d73b6d2..56fac4c 100644
--- a/IdleMaint.cpp
+++ b/IdleMaint.cpp
@@ -45,6 +45,8 @@
using android::base::StringPrintf;
using android::base::Timer;
using android::base::WriteStringToFile;
+using android::fs_mgr::Fstab;
+using android::fs_mgr::ReadDefaultFstab;
using android::hardware::Return;
using android::hardware::Void;
using android::hardware::health::storage::V1_0::IStorage;
@@ -102,48 +104,43 @@
}
static void addFromFstab(std::list<std::string>* paths, PathTypes path_type) {
- std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
- fs_mgr_free_fstab);
- struct fstab_rec* prev_rec = NULL;
+ Fstab fstab;
+ ReadDefaultFstab(&fstab);
- for (int i = 0; i < fstab->num_entries; i++) {
- auto fs_type = std::string(fstab->recs[i].fs_type);
- /* Skip raw partitions */
- if (fs_type == "emmc" || fs_type == "mtd") {
+ std::string previous_mount_point;
+ for (const auto& entry : fstab) {
+ // Skip raw partitions.
+ if (entry.fs_type == "emmc" || entry.fs_type == "mtd") {
continue;
}
- /* Skip read-only filesystems */
- if (fstab->recs[i].flags & MS_RDONLY) {
+ // Skip read-only filesystems
+ if (entry.flags & MS_RDONLY) {
continue;
}
- if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
- continue; /* Should we trim fat32 filesystems? */
+ if (entry.fs_mgr_flags.vold_managed) {
+ continue; // Should we trim fat32 filesystems?
}
- if (fs_mgr_is_notrim(&fstab->recs[i])) {
+ if (entry.fs_mgr_flags.no_trim) {
continue;
}
- /* Skip the multi-type partitions, which are required to be following each other.
- * See fs_mgr.c's mount_with_alternatives().
- */
- if (prev_rec && !strcmp(prev_rec->mount_point, fstab->recs[i].mount_point)) {
+ // Skip the multi-type partitions, which are required to be following each other.
+ // See fs_mgr.c's mount_with_alternatives().
+ if (entry.mount_point == previous_mount_point) {
continue;
}
if (path_type == PathTypes::kMountPoint) {
- paths->push_back(fstab->recs[i].mount_point);
+ paths->push_back(entry.mount_point);
} else if (path_type == PathTypes::kBlkDevice) {
std::string gc_path;
- if (std::string(fstab->recs[i].fs_type) == "f2fs" &&
- Realpath(
- android::vold::BlockDeviceForPath(std::string(fstab->recs[i].mount_point) + "/"),
- &gc_path)) {
- paths->push_back(std::string("/sys/fs/") + fstab->recs[i].fs_type + "/" +
- Basename(gc_path));
+ if (entry.fs_type == "f2fs" &&
+ Realpath(android::vold::BlockDeviceForPath(entry.mount_point + "/"), &gc_path)) {
+ paths->push_back("/sys/fs/" + entry.fs_type + "/" + Basename(gc_path));
}
}
- prev_rec = &fstab->recs[i];
+ previous_mount_point = entry.mount_point;
}
}
@@ -263,22 +260,21 @@
}
static void runDevGcFstab(void) {
- std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
- fs_mgr_free_fstab);
- struct fstab_rec* rec = NULL;
+ Fstab fstab;
+ ReadDefaultFstab(&fstab);
- for (int i = 0; i < fstab->num_entries; i++) {
- if (fs_mgr_has_sysfs_path(&fstab->recs[i])) {
- rec = &fstab->recs[i];
+ std::string path;
+ for (const auto& entry : fstab) {
+ if (!entry.sysfs_path.empty()) {
+ path = entry.sysfs_path;
break;
}
}
- if (!rec) {
+
+ if (path.empty()) {
return;
}
- std::string path;
- path.append(rec->sysfs_path);
path = path + "/manual_gc";
Timer timer;
diff --git a/MetadataCrypt.cpp b/MetadataCrypt.cpp
index d31419f..deb7194 100644
--- a/MetadataCrypt.cpp
+++ b/MetadataCrypt.cpp
@@ -49,6 +49,8 @@
#define TABLE_LOAD_RETRIES 10
#define DEFAULT_KEY_TARGET_TYPE "default-key"
+using android::fs_mgr::FstabEntry;
+using android::fs_mgr::GetEntryForMountPoint;
using android::vold::KeyBuffer;
static const std::string kDmNameUserdata = "userdata";
@@ -63,7 +65,7 @@
PLOG(ERROR) << "Failed to setexeccon";
return false;
}
- auto mount_rc = fs_mgr_do_mount(fstab_default, const_cast<char*>(mount_point),
+ auto mount_rc = fs_mgr_do_mount(&fstab_default, const_cast<char*>(mount_point),
const_cast<char*>(blk_device), nullptr,
android::vold::cp_needsCheckpoint());
if (setexeccon(nullptr)) {
@@ -106,12 +108,12 @@
LOG(INFO) << "Old Key deleted: " << dir;
}
-static bool read_key(struct fstab_rec const* data_rec, bool create_if_absent, KeyBuffer* key) {
- if (!data_rec->key_dir) {
+static bool read_key(const FstabEntry& data_rec, bool create_if_absent, KeyBuffer* key) {
+ if (data_rec.key_dir.empty()) {
LOG(ERROR) << "Failed to get key_dir";
return false;
}
- std::string key_dir = data_rec->key_dir;
+ std::string key_dir = data_rec.key_dir;
std::string sKey;
auto dir = key_dir + "/key";
LOG(DEBUG) << "key_dir/key: " << dir;
@@ -254,13 +256,14 @@
LOG(DEBUG) << "fscrypt_enable_crypto got unexpected starting state: " << encrypted_state;
return false;
}
- auto data_rec = fs_mgr_get_entry_for_mount_point(fstab_default, mount_point);
+
+ auto data_rec = GetEntryForMountPoint(&fstab_default, mount_point);
if (!data_rec) {
LOG(ERROR) << "Failed to get data_rec";
return false;
}
KeyBuffer key;
- if (!read_key(data_rec, needs_encrypt, &key)) return false;
+ if (!read_key(*data_rec, needs_encrypt, &key)) return false;
uint64_t nr_sec;
if (!get_number_of_sectors(data_rec->blk_device, &nr_sec)) return false;
std::string crypto_blkdev;
@@ -271,9 +274,8 @@
if (needs_encrypt) {
LOG(INFO) << "Beginning inplace encryption, nr_sec: " << nr_sec;
off64_t size_already_done = 0;
- auto rc =
- cryptfs_enable_inplace(const_cast<char*>(crypto_blkdev.c_str()), data_rec->blk_device,
- nr_sec, &size_already_done, nr_sec, 0, false);
+ auto rc = cryptfs_enable_inplace(crypto_blkdev.data(), data_rec->blk_device.data(), nr_sec,
+ &size_already_done, nr_sec, 0, false);
if (rc != 0) {
LOG(ERROR) << "Inplace crypto failed with code: " << rc;
return false;
@@ -286,6 +288,6 @@
}
LOG(DEBUG) << "Mounting metadata-encrypted filesystem:" << mount_point;
- mount_via_fs_mgr(data_rec->mount_point, crypto_blkdev.c_str());
+ mount_via_fs_mgr(data_rec->mount_point.c_str(), crypto_blkdev.c_str());
return true;
}
diff --git a/VoldUtil.cpp b/VoldUtil.cpp
index 4b980be..082f743 100644
--- a/VoldUtil.cpp
+++ b/VoldUtil.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include <linux/fs.h>
-#include <sys/ioctl.h>
+#include "VoldUtil.h"
-struct fstab* fstab_default;
+android::fs_mgr::Fstab fstab_default;
diff --git a/VoldUtil.h b/VoldUtil.h
index 782e36d..173c598 100644
--- a/VoldUtil.h
+++ b/VoldUtil.h
@@ -14,14 +14,11 @@
* limitations under the License.
*/
-#ifndef _VOLDUTIL_H
-#define _VOLDUTIL_H
+#pragma once
#include <fstab/fstab.h>
#include <sys/cdefs.h>
-extern struct fstab* fstab_default;
+extern android::fs_mgr::Fstab fstab_default;
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
-
-#endif
diff --git a/cryptfs.cpp b/cryptfs.cpp
index 41931de..400a616 100644
--- a/cryptfs.cpp
+++ b/cryptfs.cpp
@@ -77,6 +77,7 @@
using android::base::ParseUint;
using android::base::StringPrintf;
+using android::fs_mgr::GetEntryForMountPoint;
using namespace std::chrono_literals;
#define UNUSED __attribute__((unused))
@@ -404,7 +405,7 @@
return get_crypto_type().get_crypto_name();
}
-static uint64_t get_fs_size(char* dev) {
+static uint64_t get_fs_size(const char* dev) {
int fd, block_size;
struct ext4_super_block sb;
uint64_t len;
@@ -438,6 +439,22 @@
return len / 512;
}
+static void get_crypt_info(std::string* key_loc, std::string* real_blk_device) {
+ for (const auto& entry : fstab_default) {
+ if (!entry.fs_mgr_flags.vold_managed &&
+ (entry.fs_mgr_flags.crypt || entry.fs_mgr_flags.force_crypt ||
+ entry.fs_mgr_flags.force_fde_or_fbe || entry.fs_mgr_flags.file_encryption)) {
+ if (key_loc != nullptr) {
+ *key_loc = entry.key_loc;
+ }
+ if (real_blk_device != nullptr) {
+ *real_blk_device = entry.blk_device;
+ }
+ return;
+ }
+ }
+}
+
static int get_crypt_ftr_info(char** metadata_fname, off64_t* off) {
static int cached_data = 0;
static uint64_t cached_off = 0;
@@ -447,22 +464,24 @@
int rc = -1;
if (!cached_data) {
- fs_mgr_get_crypt_info(fstab_default, key_loc, real_blkdev, sizeof(key_loc));
+ std::string key_loc;
+ std::string real_blkdev;
+ get_crypt_info(&key_loc, &real_blkdev);
- if (!strcmp(key_loc, KEY_IN_FOOTER)) {
+ if (key_loc == KEY_IN_FOOTER) {
if (android::vold::GetBlockDevSize(real_blkdev, &cached_off) == android::OK) {
/* If it's an encrypted Android partition, the last 16 Kbytes contain the
* encryption info footer and key, and plenty of bytes to spare for future
* growth.
*/
- strlcpy(cached_metadata_fname, real_blkdev, sizeof(cached_metadata_fname));
+ strlcpy(cached_metadata_fname, real_blkdev.c_str(), sizeof(cached_metadata_fname));
cached_off -= CRYPT_FOOTER_OFFSET;
cached_data = 1;
} else {
- SLOGE("Cannot get size of block device %s\n", real_blkdev);
+ SLOGE("Cannot get size of block device %s\n", real_blkdev.c_str());
}
} else {
- strlcpy(cached_metadata_fname, key_loc, sizeof(cached_metadata_fname));
+ strlcpy(cached_metadata_fname, key_loc.c_str(), sizeof(cached_metadata_fname));
cached_off = 0;
cached_data = 1;
}
@@ -1595,9 +1614,9 @@
char ro_prop[PROPERTY_VALUE_MAX];
property_get("ro.crypto.readonly", ro_prop, "");
if (strlen(ro_prop) > 0 && std::stoi(ro_prop)) {
- struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab_default, DATA_MNT_POINT);
- if (rec) {
- rec->flags |= MS_RDONLY;
+ auto entry = GetEntryForMountPoint(&fstab_default, DATA_MNT_POINT);
+ if (entry != nullptr) {
+ entry->flags |= MS_RDONLY;
}
}
@@ -1614,7 +1633,7 @@
return -1;
}
bool needs_cp = android::vold::cp_needsCheckpoint();
- while ((mount_rc = fs_mgr_do_mount(fstab_default, DATA_MNT_POINT, crypto_blkdev, 0,
+ while ((mount_rc = fs_mgr_do_mount(&fstab_default, DATA_MNT_POINT, crypto_blkdev, 0,
needs_cp)) != 0) {
if (mount_rc == FS_MGR_DOMNT_BUSY) {
/* TODO: invoke something similar to
@@ -1677,7 +1696,6 @@
static int do_crypto_complete(const char* mount_point) {
struct crypt_mnt_ftr crypt_ftr;
char encrypted_state[PROPERTY_VALUE_MAX];
- char key_loc[PROPERTY_VALUE_MAX];
property_get("ro.crypto.state", encrypted_state, "");
if (strcmp(encrypted_state, "encrypted")) {
@@ -1691,7 +1709,8 @@
}
if (get_crypt_ftr_and_key(&crypt_ftr)) {
- fs_mgr_get_crypt_info(fstab_default, key_loc, 0, sizeof(key_loc));
+ std::string key_loc;
+ get_crypt_info(&key_loc, nullptr);
/*
* Only report this error if key_loc is a file and it exists.
@@ -1700,7 +1719,7 @@
* a "enter password" screen, or worse, a "press button to wipe the
* device" screen.
*/
- if ((key_loc[0] == '/') && (access("key_loc", F_OK) == -1)) {
+ if (!key_loc.empty() && key_loc[0] == '/' && (access("key_loc", F_OK) == -1)) {
SLOGE("master key file does not exist, aborting");
return CRYPTO_COMPLETE_NOT_ENCRYPTED;
} else {
@@ -1733,7 +1752,7 @@
const char* mount_point, const char* label) {
unsigned char decrypted_master_key[MAX_KEY_LEN];
char crypto_blkdev[MAXPATHLEN];
- char real_blkdev[MAXPATHLEN];
+ std::string real_blkdev;
char tmp_mount_point[64];
unsigned int orig_failed_decrypt_count;
int rc;
@@ -1757,12 +1776,12 @@
}
}
- fs_mgr_get_crypt_info(fstab_default, 0, real_blkdev, sizeof(real_blkdev));
+ get_crypt_info(nullptr, &real_blkdev);
// Create crypto block device - all (non fatal) code paths
// need it
- if (create_crypto_blk_dev(crypt_ftr, decrypted_master_key, real_blkdev, crypto_blkdev, label,
- 0)) {
+ if (create_crypto_blk_dev(crypt_ftr, decrypted_master_key, real_blkdev.c_str(), crypto_blkdev,
+ label, 0)) {
SLOGE("Error creating decrypted block device\n");
rc = -1;
goto errout;
@@ -1785,7 +1804,7 @@
* the footer, not the key. */
snprintf(tmp_mount_point, sizeof(tmp_mount_point), "%s/tmp_mnt", mount_point);
mkdir(tmp_mount_point, 0755);
- if (fs_mgr_do_mount(fstab_default, DATA_MNT_POINT, crypto_blkdev, tmp_mount_point)) {
+ if (fs_mgr_do_mount(&fstab_default, DATA_MNT_POINT, crypto_blkdev, tmp_mount_point)) {
SLOGE("Error temp mounting decrypted block device\n");
delete_crypto_blk_dev(label);
@@ -2122,14 +2141,15 @@
}
int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
- char crypto_blkdev[MAXPATHLEN], real_blkdev[MAXPATHLEN];
+ char crypto_blkdev[MAXPATHLEN];
+ std::string real_blkdev;
unsigned char decrypted_master_key[MAX_KEY_LEN];
int rc = -1, i;
struct crypt_mnt_ftr crypt_ftr;
struct crypt_persist_data* pdata;
char encrypted_state[PROPERTY_VALUE_MAX];
char lockid[32] = {0};
- char key_loc[PROPERTY_VALUE_MAX];
+ std::string key_loc;
int num_vols;
off64_t previously_encrypted_upto = 0;
bool rebootEncryption = false;
@@ -2172,22 +2192,20 @@
goto error_unencrypted;
}
- // TODO refactor fs_mgr_get_crypt_info to get both in one call
- fs_mgr_get_crypt_info(fstab_default, key_loc, 0, sizeof(key_loc));
- fs_mgr_get_crypt_info(fstab_default, 0, real_blkdev, sizeof(real_blkdev));
+ get_crypt_info(&key_loc, &real_blkdev);
/* Get the size of the real block device */
uint64_t nr_sec;
if (android::vold::GetBlockDev512Sectors(real_blkdev, &nr_sec) != android::OK) {
- SLOGE("Cannot get size of block device %s\n", real_blkdev);
+ SLOGE("Cannot get size of block device %s\n", real_blkdev.c_str());
goto error_unencrypted;
}
/* If doing inplace encryption, make sure the orig fs doesn't include the crypto footer */
- if (!strcmp(key_loc, KEY_IN_FOOTER)) {
+ if (key_loc == KEY_IN_FOOTER) {
uint64_t fs_size_sec, max_fs_size_sec;
- fs_size_sec = get_fs_size(real_blkdev);
- if (fs_size_sec == 0) fs_size_sec = get_f2fs_filesystem_size_sec(real_blkdev);
+ fs_size_sec = get_fs_size(real_blkdev.c_str());
+ if (fs_size_sec == 0) fs_size_sec = get_f2fs_filesystem_size_sec(real_blkdev.data());
max_fs_size_sec = nr_sec - (CRYPT_FOOTER_OFFSET / CRYPT_SECTOR_SIZE);
@@ -2260,7 +2278,7 @@
goto error_shutting_down;
}
- if (!strcmp(key_loc, KEY_IN_FOOTER)) {
+ if (key_loc == KEY_IN_FOOTER) {
crypt_ftr.fs_size = nr_sec - (CRYPT_FOOTER_OFFSET / CRYPT_SECTOR_SIZE);
} else {
crypt_ftr.fs_size = nr_sec;
@@ -2330,7 +2348,7 @@
}
decrypt_master_key(passwd, decrypted_master_key, &crypt_ftr, 0, 0);
- create_crypto_blk_dev(&crypt_ftr, decrypted_master_key, real_blkdev, crypto_blkdev,
+ create_crypto_blk_dev(&crypt_ftr, decrypted_master_key, real_blkdev.c_str(), crypto_blkdev,
CRYPTO_BLOCK_DEVICE, 0);
/* If we are continuing, check checksums match */
@@ -2347,7 +2365,7 @@
}
if (!rc) {
- rc = cryptfs_enable_all_volumes(&crypt_ftr, crypto_blkdev, real_blkdev,
+ rc = cryptfs_enable_all_volumes(&crypt_ftr, crypto_blkdev, real_blkdev.data(),
previously_encrypted_upto);
}
@@ -2893,6 +2911,6 @@
}
int cryptfs_isConvertibleToFBE() {
- struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab_default, DATA_MNT_POINT);
- return (rec && fs_mgr_is_convertible_to_fbe(rec)) ? 1 : 0;
+ auto entry = GetEntryForMountPoint(&fstab_default, DATA_MNT_POINT);
+ return entry && entry->fs_mgr_flags.force_fde_or_fbe;
}
diff --git a/main.cpp b/main.cpp
index 347c945..d4b1c38 100644
--- a/main.cpp
+++ b/main.cpp
@@ -50,6 +50,7 @@
struct selabel_handle* sehandle;
using android::base::StringPrintf;
+using android::fs_mgr::ReadDefaultFstab;
int main(int argc, char** argv) {
atrace_set_tracing_enabled(false);
@@ -216,8 +217,7 @@
bool* has_reserved) {
ATRACE_NAME("process_config");
- fstab_default = fs_mgr_read_fstab_default();
- if (!fstab_default) {
+ if (!ReadDefaultFstab(&fstab_default)) {
PLOG(ERROR) << "Failed to open default fstab";
return -1;
}
@@ -226,30 +226,29 @@
*has_adoptable = false;
*has_quota = false;
*has_reserved = false;
- for (int i = 0; i < fstab_default->num_entries; i++) {
- auto rec = &fstab_default->recs[i];
- if (fs_mgr_is_quota(rec)) {
+ for (const auto& entry : fstab_default) {
+ if (entry.fs_mgr_flags.quota) {
*has_quota = true;
}
- if (rec->reserved_size > 0) {
+ if (entry.reserved_size > 0) {
*has_reserved = true;
}
- if (fs_mgr_is_voldmanaged(rec)) {
- if (fs_mgr_is_nonremovable(rec)) {
+ if (entry.fs_mgr_flags.vold_managed) {
+ if (entry.fs_mgr_flags.nonremovable) {
LOG(WARNING) << "nonremovable no longer supported; ignoring volume";
continue;
}
- std::string sysPattern(rec->blk_device);
- std::string nickname(rec->label);
+ std::string sysPattern(entry.blk_device);
+ std::string nickname(entry.label);
int flags = 0;
- if (fs_mgr_is_encryptable(rec)) {
+ if (entry.is_encryptable()) {
flags |= android::vold::Disk::Flags::kAdoptable;
*has_adoptable = true;
}
- if (fs_mgr_is_noemulatedsd(rec) ||
+ if (entry.fs_mgr_flags.no_emulated_sd ||
android::base::GetBoolProperty("vold.debug.default_primary", false)) {
flags |= android::vold::Disk::Flags::kDefaultPrimary;
}