diff options
author | ThiƩbaud Weksteen <tweek@google.com> | 2020-10-27 11:51:16 +0100 |
---|---|---|
committer | ThiƩbaud Weksteen <tweek@google.com> | 2020-10-27 11:53:11 +0100 |
commit | cee2e4e90fc6cae5873b41009e23ca2ae13a6827 (patch) | |
tree | 362f0ca6a6a38676bb31ae007965d4db87ee5405 /boot_control_copy | |
parent | 7ebc9e6cd61d5b167ccccbea85f42387370f51a7 (diff) | |
download | extras-cee2e4e90fc6cae5873b41009e23ca2ae13a6827.tar.gz |
boot_control_copy: format files
Format *.cpp according to the new .clang-format-2. The following command
was used to generate this change:
$ find . \( -name \*.cpp -o -name \*.h \) -exec clang-format \
--style=file -i {} \;
Test: mm
Bug: 171699326
Change-Id: I0b5681b2c0b72770f327e6783eb90eb05250a7ac
Diffstat (limited to 'boot_control_copy')
l--------- | boot_control_copy/.clang-format | 1 | ||||
-rw-r--r-- | boot_control_copy/boot_control_copy.cpp | 122 | ||||
-rw-r--r-- | boot_control_copy/bootinfo.cpp | 49 | ||||
-rw-r--r-- | boot_control_copy/bootinfo.h | 8 |
4 files changed, 73 insertions, 107 deletions
diff --git a/boot_control_copy/.clang-format b/boot_control_copy/.clang-format new file mode 120000 index 00000000..fd0645fd --- /dev/null +++ b/boot_control_copy/.clang-format @@ -0,0 +1 @@ +../.clang-format-2
\ No newline at end of file diff --git a/boot_control_copy/boot_control_copy.cpp b/boot_control_copy/boot_control_copy.cpp index d8a5d180..11377856 100644 --- a/boot_control_copy/boot_control_copy.cpp +++ b/boot_control_copy/boot_control_copy.cpp @@ -14,11 +14,11 @@ * limitations under the License. */ -#include <sys/types.h> +#include <fcntl.h> #include <sys/stat.h> #include <sys/sysmacros.h> +#include <sys/types.h> #include <unistd.h> -#include <fcntl.h> #include <errno.h> #include <inttypes.h> @@ -26,31 +26,26 @@ #include <string.h> #include <fs_mgr.h> -#include <hardware/hardware.h> #include <hardware/boot_control.h> +#include <hardware/hardware.h> #include "bootinfo.h" -void module_init(boot_control_module_t *module) -{ -} +void module_init(boot_control_module_t* module) {} -unsigned module_getNumberSlots(boot_control_module_t *module) -{ +unsigned module_getNumberSlots(boot_control_module_t* module) { return 2; } -static bool get_dev_t_for_partition(const char *name, dev_t *out_device) -{ +static bool get_dev_t_for_partition(const char* name, dev_t* out_device) { int fd; struct stat statbuf; fd = boot_info_open_partition(name, NULL, O_RDONLY); - if (fd == -1) - return false; + if (fd == -1) return false; if (fstat(fd, &statbuf) != 0) { - fprintf(stderr, "WARNING: Error getting information about part %s: %s\n", - name, strerror(errno)); + fprintf(stderr, "WARNING: Error getting information about part %s: %s\n", name, + strerror(errno)); close(fd); return false; } @@ -59,14 +54,12 @@ static bool get_dev_t_for_partition(const char *name, dev_t *out_device) return true; } -unsigned module_getCurrentSlot(boot_control_module_t *module) -{ +unsigned module_getCurrentSlot(boot_control_module_t* module) { struct stat statbuf; dev_t system_a_dev, system_b_dev; if (stat("/system", &statbuf) != 0) { - fprintf(stderr, "WARNING: Error getting information about /system: %s\n", - strerror(errno)); + fprintf(stderr, "WARNING: Error getting information about /system: %s\n", strerror(errno)); return 0; } @@ -79,24 +72,22 @@ unsigned module_getCurrentSlot(boot_control_module_t *module) } else if (statbuf.st_dev == system_b_dev) { return 1; } else { - fprintf(stderr, "WARNING: Error determining current slot " + fprintf(stderr, + "WARNING: Error determining current slot " "(/system dev_t of %d:%d does not match a=%d:%d or b=%d:%d)\n", - major(statbuf.st_dev), minor(statbuf.st_dev), - major(system_a_dev), minor(system_a_dev), + major(statbuf.st_dev), minor(statbuf.st_dev), major(system_a_dev), minor(system_a_dev), major(system_b_dev), minor(system_b_dev)); return 0; } } -int module_markBootSuccessful(boot_control_module_t *module) -{ +int module_markBootSuccessful(boot_control_module_t* module) { return 0; } -#define COPY_BUF_SIZE (1024*1024) +#define COPY_BUF_SIZE (1024 * 1024) -static bool copy_data(int src_fd, int dst_fd, size_t num_bytes) -{ +static bool copy_data(int src_fd, int dst_fd, size_t num_bytes) { char copy_buf[COPY_BUF_SIZE]; size_t remaining; @@ -108,8 +99,7 @@ static bool copy_data(int src_fd, int dst_fd, size_t num_bytes) num_read = read(src_fd, copy_buf, num_to_read); } while (num_read == -1 && errno == EINTR); if (num_read <= 0) { - fprintf(stderr, "Error reading %zd bytes from source: %s\n", - num_to_read, strerror(errno)); + fprintf(stderr, "Error reading %zd bytes from source: %s\n", num_to_read, strerror(errno)); return false; } size_t num_to_write = num_read; @@ -120,8 +110,8 @@ static bool copy_data(int src_fd, int dst_fd, size_t num_bytes) num_written = write(dst_fd, copy_buf + offset, num_to_write); } while (num_written == -1 && errno == EINTR); if (num_written <= 0) { - fprintf(stderr, "Error writing %zd bytes to destination: %s\n", - num_to_write, strerror(errno)); + fprintf(stderr, "Error writing %zd bytes to destination: %s\n", num_to_write, + strerror(errno)); return false; } num_to_write -= num_written; @@ -132,15 +122,13 @@ static bool copy_data(int src_fd, int dst_fd, size_t num_bytes) return true; } -int module_setActiveBootSlot(boot_control_module_t *module, unsigned slot) -{ +int module_setActiveBootSlot(boot_control_module_t* module, unsigned slot) { BrilloBootInfo info; int src_fd, dst_fd; uint64_t src_size, dst_size; char src_name[32]; - if (slot >= 2) - return -EINVAL; + if (slot >= 2) return -EINVAL; if (!boot_info_load(&info)) { fprintf(stderr, "WARNING: Error loading boot-info. Resetting.\n"); @@ -154,9 +142,7 @@ int module_setActiveBootSlot(boot_control_module_t *module, unsigned slot) info.active_slot = slot; info.slot_info[slot].bootable = true; - snprintf(info.bootctrl_suffix, - sizeof(info.bootctrl_suffix), - "_%c", slot + 'a'); + snprintf(info.bootctrl_suffix, sizeof(info.bootctrl_suffix), "_%c", slot + 'a'); if (!boot_info_save(&info)) { fprintf(stderr, "Error saving boot-info.\n"); @@ -180,7 +166,8 @@ int module_setActiveBootSlot(boot_control_module_t *module, unsigned slot) if (src_size != dst_size) { fprintf(stderr, - "src (%" PRIu64 " bytes) and dst (%" PRIu64 " bytes) " + "src (%" PRIu64 " bytes) and dst (%" PRIu64 + " bytes) " "have different sizes.\n", src_size, dst_size); close(src_fd); @@ -195,8 +182,7 @@ int module_setActiveBootSlot(boot_control_module_t *module, unsigned slot) } if (fsync(dst_fd) != 0) { - fprintf(stderr, "Error calling fsync on destination: %s\n", - strerror(errno)); + fprintf(stderr, "Error calling fsync on destination: %s\n", strerror(errno)); return -errno; } @@ -205,12 +191,10 @@ int module_setActiveBootSlot(boot_control_module_t *module, unsigned slot) return 0; } -int module_setSlotAsUnbootable(struct boot_control_module *module, unsigned slot) -{ +int module_setSlotAsUnbootable(struct boot_control_module* module, unsigned slot) { BrilloBootInfo info; - if (slot >= 2) - return -EINVAL; + if (slot >= 2) return -EINVAL; if (!boot_info_load(&info)) { fprintf(stderr, "WARNING: Error loading boot-info. Resetting.\n"); @@ -232,12 +216,10 @@ int module_setSlotAsUnbootable(struct boot_control_module *module, unsigned slot return 0; } -int module_isSlotBootable(struct boot_control_module *module, unsigned slot) -{ +int module_isSlotBootable(struct boot_control_module* module, unsigned slot) { BrilloBootInfo info; - if (slot >= 2) - return -EINVAL; + if (slot >= 2) return -EINVAL; if (!boot_info_load(&info)) { fprintf(stderr, "WARNING: Error loading boot-info. Resetting.\n"); @@ -252,19 +234,16 @@ int module_isSlotBootable(struct boot_control_module *module, unsigned slot) return info.slot_info[slot].bootable; } -const char* module_getSuffix(boot_control_module_t *module, unsigned slot) -{ +const char* module_getSuffix(boot_control_module_t* module, unsigned slot) { static const char* suffix[2] = {"_a", "_b"}; - if (slot >= 2) - return NULL; + if (slot >= 2) return NULL; return suffix[slot]; } static struct hw_module_methods_t module_methods = { - .open = NULL, + .open = NULL, }; - /* This boot_control HAL implementation emulates A/B by copying the * contents of the boot partition of the requested slot to the boot * partition. It hence works with bootloaders that are not yet aware @@ -272,21 +251,22 @@ static struct hw_module_methods_t module_methods = { */ boot_control_module_t HAL_MODULE_INFO_SYM = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .module_api_version = BOOT_CONTROL_MODULE_API_VERSION_0_1, - .hal_api_version = HARDWARE_HAL_API_VERSION, - .id = BOOT_CONTROL_HARDWARE_MODULE_ID, - .name = "Copy Implementation of boot_control HAL", - .author = "The Android Open Source Project", - .methods = &module_methods, - }, - .init = module_init, - .getNumberSlots = module_getNumberSlots, - .getCurrentSlot = module_getCurrentSlot, - .markBootSuccessful = module_markBootSuccessful, - .setActiveBootSlot = module_setActiveBootSlot, - .setSlotAsUnbootable = module_setSlotAsUnbootable, - .isSlotBootable = module_isSlotBootable, - .getSuffix = module_getSuffix, + .common = + { + .tag = HARDWARE_MODULE_TAG, + .module_api_version = BOOT_CONTROL_MODULE_API_VERSION_0_1, + .hal_api_version = HARDWARE_HAL_API_VERSION, + .id = BOOT_CONTROL_HARDWARE_MODULE_ID, + .name = "Copy Implementation of boot_control HAL", + .author = "The Android Open Source Project", + .methods = &module_methods, + }, + .init = module_init, + .getNumberSlots = module_getNumberSlots, + .getCurrentSlot = module_getCurrentSlot, + .markBootSuccessful = module_markBootSuccessful, + .setActiveBootSlot = module_setActiveBootSlot, + .setSlotAsUnbootable = module_setSlotAsUnbootable, + .isSlotBootable = module_isSlotBootable, + .getSuffix = module_getSuffix, }; diff --git a/boot_control_copy/bootinfo.cpp b/boot_control_copy/bootinfo.cpp index 55319178..be3e97e2 100644 --- a/boot_control_copy/bootinfo.cpp +++ b/boot_control_copy/bootinfo.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ - #include <errno.h> #include <fcntl.h> #include <linux/fs.h> @@ -40,14 +39,12 @@ using android::fs_mgr::ReadFstabFromFile; // Open the appropriate fstab file and fallback to /fstab.device if // that's what's being used. -static bool open_fstab(Fstab* fstab) -{ +static bool open_fstab(Fstab* fstab) { return ReadDefaultFstab(fstab) || ReadFstabFromFile("/fstab.device", fstab); } -int boot_info_open_partition(const char *name, uint64_t *out_size, int flags) -{ - char *path; +int boot_info_open_partition(const char* name, uint64_t* out_size, int flags) { + char* path; int fd; // We can't use fs_mgr to look up |name| because fstab doesn't list @@ -79,13 +76,13 @@ int boot_info_open_partition(const char *name, uint64_t *out_size, int flags) path = strdup(record->blk_device.c_str()); } else { size_t trimmed_len, name_len; - const char *end_slash = strrchr(record->blk_device.c_str(), '/'); + const char* end_slash = strrchr(record->blk_device.c_str(), '/'); if (end_slash == NULL) { return -1; } trimmed_len = end_slash - record->blk_device.c_str() + 1; name_len = strlen(name); - path = static_cast<char *>(calloc(trimmed_len + name_len + 1, 1)); + path = static_cast<char*>(calloc(trimmed_len + name_len + 1, 1)); strncpy(path, record->blk_device.c_str(), trimmed_len); strncpy(path + trimmed_len, name, name_len); } @@ -120,63 +117,51 @@ int boot_info_open_partition(const char *name, uint64_t *out_size, int flags) // that BrilloBootInfo is laid out this way. #define BOOTINFO_OFFSET 2048 -bool boot_info_load(BrilloBootInfo *out_info) -{ +bool boot_info_load(BrilloBootInfo* out_info) { int fd; memset(out_info, '\0', sizeof(BrilloBootInfo)); fd = boot_info_open_partition("misc", NULL, O_RDONLY); - if (fd == -1) - return false; + if (fd == -1) return false; if (lseek(fd, BOOTINFO_OFFSET, SEEK_SET) != BOOTINFO_OFFSET) { close(fd); return false; } ssize_t num_read; do { - num_read = read(fd, (void*) out_info, sizeof(BrilloBootInfo)); + num_read = read(fd, (void*)out_info, sizeof(BrilloBootInfo)); } while (num_read == -1 && errno == EINTR); close(fd); - if (num_read != sizeof(BrilloBootInfo)) - return false; + if (num_read != sizeof(BrilloBootInfo)) return false; return true; } -bool boot_info_save(BrilloBootInfo *info) -{ +bool boot_info_save(BrilloBootInfo* info) { int fd; fd = boot_info_open_partition("misc", NULL, O_RDWR); - if (fd == -1) - return false; + if (fd == -1) return false; if (lseek(fd, BOOTINFO_OFFSET, SEEK_SET) != BOOTINFO_OFFSET) { close(fd); return false; } ssize_t num_written; do { - num_written = write(fd, (void*) info, sizeof(BrilloBootInfo)); + num_written = write(fd, (void*)info, sizeof(BrilloBootInfo)); } while (num_written == -1 && errno == EINTR); close(fd); - if (num_written != sizeof(BrilloBootInfo)) - return false; + if (num_written != sizeof(BrilloBootInfo)) return false; return true; } -bool boot_info_validate(BrilloBootInfo* info) -{ - if (info->magic[0] != 'B' || - info->magic[1] != 'C' || - info->magic[2] != 'c') - return false; - if (info->active_slot >= 2) - return false; +bool boot_info_validate(BrilloBootInfo* info) { + if (info->magic[0] != 'B' || info->magic[1] != 'C' || info->magic[2] != 'c') return false; + if (info->active_slot >= 2) return false; return true; } -void boot_info_reset(BrilloBootInfo* info) -{ +void boot_info_reset(BrilloBootInfo* info) { memset(info, '\0', sizeof(BrilloBootInfo)); info->magic[0] = 'B'; info->magic[1] = 'C'; diff --git a/boot_control_copy/bootinfo.h b/boot_control_copy/bootinfo.h index 4b36b2cd..3144b7d5 100644 --- a/boot_control_copy/bootinfo.h +++ b/boot_control_copy/bootinfo.h @@ -17,8 +17,8 @@ #ifndef BOOTINFO_H_ #define BOOTINFO_H_ -#include <stdint.h> #include <stdbool.h> +#include <stdint.h> typedef struct BrilloSlotInfo { uint8_t bootable : 1; @@ -46,8 +46,8 @@ typedef struct BrilloBootInfo { } BrilloBootInfo; // Loading and saving BrillBootInfo instances. -bool boot_info_load(BrilloBootInfo *out_info); -bool boot_info_save(BrilloBootInfo *info); +bool boot_info_load(BrilloBootInfo* out_info); +bool boot_info_save(BrilloBootInfo* info); // Returns non-zero if valid. bool boot_info_validate(BrilloBootInfo* info); @@ -56,7 +56,7 @@ void boot_info_reset(BrilloBootInfo* info); // Opens partition by |name|, e.g. "misc" or "boot_a" with |flags| // (e.g. O_RDONLY or O_RDWR) passed directly to open(2). Returns fd on // success and -1 on error. -int boot_info_open_partition(const char *name, uint64_t *out_size, int flags); +int boot_info_open_partition(const char* name, uint64_t* out_size, int flags); #if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 _Static_assert(sizeof(BrilloBootInfo) == 32, "BrilloBootInfo has wrong size"); |