From 246c18caf5193e2243dfcbf434e6340039b64f8c Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 9 Oct 2015 11:52:00 -0700 Subject: [PATCH] Switch fs_mgr_verity.c to C++. This is the minimal change just to keep it building, and doesn't attempt to clean up any of the code. Change-Id: I975710322ae33d8946497df25bf85b2fe28976a4 --- fs_mgr/Android.mk | 2 +- fs_mgr/fs_mgr_priv.h | 4 ++++ fs_mgr/fs_mgr_priv_verity.h | 7 +++++++ fs_mgr/{fs_mgr_verity.c => fs_mgr_verity.cpp} | 18 ++++++++---------- 4 files changed, 20 insertions(+), 11 deletions(-) rename fs_mgr/{fs_mgr_verity.c => fs_mgr_verity.cpp} (98%) diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk index 5e6c6f94f..8b09f53fb 100644 --- a/fs_mgr/Android.mk +++ b/fs_mgr/Android.mk @@ -3,7 +3,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES:= fs_mgr.c fs_mgr_verity.c fs_mgr_fstab.c +LOCAL_SRC_FILES:= fs_mgr.c fs_mgr_verity.cpp fs_mgr_fstab.c LOCAL_SRC_FILES += fs_mgr_format.c fs_mgr_slotselect.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \ diff --git a/fs_mgr/fs_mgr_priv.h b/fs_mgr/fs_mgr_priv.h index 367ab6e28..ba0e097b0 100644 --- a/fs_mgr/fs_mgr_priv.h +++ b/fs_mgr/fs_mgr_priv.h @@ -20,6 +20,8 @@ #include #include +__BEGIN_DECLS + #define INFO(x...) KLOG_INFO("fs_mgr", x) #define WARNING(x...) KLOG_WARNING("fs_mgr", x) #define ERROR(x...) KLOG_ERROR("fs_mgr", x) @@ -86,4 +88,6 @@ int fs_mgr_set_blk_ro(const char *blockdev); int fs_mgr_update_for_slotselect(struct fstab *fstab); +__END_DECLS + #endif /* __CORE_FS_MGR_PRIV_H */ diff --git a/fs_mgr/fs_mgr_priv_verity.h b/fs_mgr/fs_mgr_priv_verity.h index f90e59683..cd673f386 100644 --- a/fs_mgr/fs_mgr_priv_verity.h +++ b/fs_mgr/fs_mgr_priv_verity.h @@ -14,7 +14,14 @@ * limitations under the License. */ +#include + #define FS_MGR_SETUP_VERITY_DISABLED -2 #define FS_MGR_SETUP_VERITY_FAIL -1 #define FS_MGR_SETUP_VERITY_SUCCESS 0 + +__BEGIN_DECLS + int fs_mgr_setup_verity(struct fstab_rec *fstab); + +__END_DECLS diff --git a/fs_mgr/fs_mgr_verity.c b/fs_mgr/fs_mgr_verity.cpp similarity index 98% rename from fs_mgr/fs_mgr_verity.c rename to fs_mgr/fs_mgr_verity.cpp index eddc3e4f8..961f3c601 100644 --- a/fs_mgr/fs_mgr_verity.c +++ b/fs_mgr/fs_mgr_verity.cpp @@ -40,6 +40,7 @@ #include "ext4_sb.h" #include "squashfs_utils.h" +#include "fs_mgr.h" #include "fs_mgr_priv.h" #include "fs_mgr_priv_verity.h" @@ -74,18 +75,15 @@ struct verity_state { extern struct fs_info info; -static RSAPublicKey *load_key(char *path) +static RSAPublicKey *load_key(const char *path) { - FILE *f; - RSAPublicKey *key; - - key = malloc(sizeof(RSAPublicKey)); + RSAPublicKey* key = static_cast(malloc(sizeof(RSAPublicKey))); if (!key) { ERROR("Can't malloc key\n"); return NULL; } - f = fopen(path, "r"); + FILE* f = fopen(path, "r"); if (!f) { ERROR("Can't open '%s'\n", path); free(key); @@ -275,7 +273,7 @@ static int read_verity_metadata(uint64_t device_size, char *block_device, char * #endif if (magic_number != VERITY_METADATA_MAGIC_NUMBER) { - ERROR("Couldn't find verity metadata at offset %"PRIu64"!\n", device_size); + ERROR("Couldn't find verity metadata at offset %" PRIu64 "!\n", device_size); goto out; } @@ -314,7 +312,7 @@ static int read_verity_metadata(uint64_t device_size, char *block_device, char * } // get the table + null terminator - *table = malloc(table_length + 1); + *table = static_cast(malloc(table_length + 1)); if (!*table) { ERROR("Couldn't allocate memory for verity table!\n"); goto out; @@ -887,7 +885,7 @@ out: int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) { - _Alignas(struct dm_ioctl) char buffer[DM_BUF_SIZE]; + alignas(dm_ioctl) char buffer[DM_BUF_SIZE]; bool use_state = true; char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)]; char *mount_point; @@ -989,7 +987,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab) { int verity_table_length = 0; uint64_t device_size = 0; - _Alignas(struct dm_ioctl) char buffer[DM_BUF_SIZE]; + alignas(dm_ioctl) char buffer[DM_BUF_SIZE]; struct dm_ioctl *io = (struct dm_ioctl *) buffer; char *mount_point = basename(fstab->mount_point);