bootctrl: run clang-format
Bug: 156694052 Signed-off-by: Fernando Lugo <flugo@google.com> Change-Id: I003fb99e96bcee2d745365992b3c8d4a3816f818
This commit is contained in:
parent
fa50bf6c7c
commit
2b75765719
5 changed files with 53 additions and 54 deletions
|
@ -18,10 +18,10 @@
|
|||
|
||||
#include "GptUtils.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <log/log.h>
|
||||
#include <android-base/file.h>
|
||||
#include <errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <log/log.h>
|
||||
#include <zlib.h>
|
||||
|
||||
namespace android {
|
||||
|
@ -32,8 +32,7 @@ namespace implementation {
|
|||
|
||||
namespace {
|
||||
|
||||
static int ValidateGptHeader(gpt_header *gpt)
|
||||
{
|
||||
static int ValidateGptHeader(gpt_header *gpt) {
|
||||
if (gpt->signature != GPT_SIGNATURE) {
|
||||
ALOGE("invalid gpt signature 0x%lx\n", gpt->signature);
|
||||
return -1;
|
||||
|
@ -52,12 +51,11 @@ static int ValidateGptHeader(gpt_header *gpt)
|
|||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {}
|
||||
|
||||
int GptUtils::Load(void)
|
||||
{
|
||||
int GptUtils::Load(void) {
|
||||
fd = open(dev_path.c_str(), O_RDWR);
|
||||
if (fd < 0) {
|
||||
ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno);
|
||||
|
@ -102,20 +100,19 @@ int GptUtils::Load(void)
|
|||
}
|
||||
|
||||
if (ValidateGptHeader(&gpt_backup)) {
|
||||
ALOGW("error validating gpt backup\n"); // just warn about it, not fail
|
||||
ALOGW("error validating gpt backup\n"); // just warn about it, not fail
|
||||
}
|
||||
|
||||
// Create map <partition name, gpt_entry pointer>
|
||||
auto get_name = [](const uint16_t *efi_name) {
|
||||
char name[37] = {};
|
||||
for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i)
|
||||
name[i] = efi_name[i];
|
||||
for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i];
|
||||
return std::string(name);
|
||||
};
|
||||
|
||||
for (auto const &e: entry_array) {
|
||||
for (auto const &e : entry_array) {
|
||||
if (e.name[0] == 0)
|
||||
break; // stop at the first partition with no name
|
||||
break; // stop at the first partition with no name
|
||||
std::string s = get_name(e.name);
|
||||
entries[s] = const_cast<gpt_entry *>(&e);
|
||||
}
|
||||
|
@ -123,19 +120,17 @@ int GptUtils::Load(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
gpt_entry *GptUtils::GetPartitionEntry(std::string name)
|
||||
{
|
||||
return entries.find(name) != entries.end() ? entries[name] : nullptr;
|
||||
gpt_entry *GptUtils::GetPartitionEntry(std::string name) {
|
||||
return entries.find(name) != entries.end() ? entries[name] : nullptr;
|
||||
}
|
||||
|
||||
int GptUtils::Sync(void)
|
||||
{
|
||||
int GptUtils::Sync(void) {
|
||||
if (!fd)
|
||||
return -1;
|
||||
|
||||
// calculate crc and check if we need to update gpt
|
||||
gpt_primary.entries_crc32 = crc32(0, reinterpret_cast<uint8_t *>(entry_array.data()),
|
||||
entry_array.size() * sizeof(gpt_entry));
|
||||
entry_array.size() * sizeof(gpt_entry));
|
||||
|
||||
// save old crc
|
||||
uint32_t crc = gpt_primary.crc32;
|
||||
|
@ -143,7 +138,7 @@ int GptUtils::Sync(void)
|
|||
|
||||
gpt_primary.crc32 = crc32(0, reinterpret_cast<uint8_t *>(&gpt_primary), sizeof gpt_primary);
|
||||
if (crc == gpt_primary.crc32)
|
||||
return 0; // nothing to do (no changes)
|
||||
return 0; // nothing to do (no changes)
|
||||
|
||||
ALOGI("updating GPT\n");
|
||||
|
||||
|
@ -161,7 +156,7 @@ int GptUtils::Sync(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
//update GPT backup entries and backup
|
||||
// update GPT backup entries and backup
|
||||
lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET);
|
||||
ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry));
|
||||
if (ret < 0) {
|
||||
|
@ -184,8 +179,7 @@ int GptUtils::Sync(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
GptUtils::~GptUtils()
|
||||
{
|
||||
GptUtils::~GptUtils() {
|
||||
if (fd) {
|
||||
Sync();
|
||||
close(fd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue