summaryrefslogtreecommitdiff
path: root/boot_control_copy
diff options
context:
space:
mode:
authorDavid Zeuthen <zeuthen@google.com>2015-09-23 14:07:10 -0400
committerDavid Zeuthen <zeuthen@google.com>2015-09-23 14:16:03 -0400
commit3af8b53ae8cd70abaca17b7d9140ee12a14486b8 (patch)
tree03722d698f6f6e38ed165f31ec0ca094797507fa /boot_control_copy
parent34cee2b8a68c6df87b1abe4f2ef7957dc717044d (diff)
downloadextras-3af8b53ae8cd70abaca17b7d9140ee12a14486b8.tar.gz
boot_control_copy: Fix getCurrentSlot().
The getCurrentSlot() method wasn't returning the right value if setActiveBootSlot() was called with another slot since last reboot. Instead of peeking in the misc partition, just look at the dev_t for /system and compare it with the dev_t for system_a and system_b. Bug: 24201805 Change-Id: I601ab5e355e0f423637e6867d0afda97f68b57fd
Diffstat (limited to 'boot_control_copy')
-rw-r--r--boot_control_copy/boot_control_copy.c51
1 files changed, 41 insertions, 10 deletions
diff --git a/boot_control_copy/boot_control_copy.c b/boot_control_copy/boot_control_copy.c
index a5deb5a6..644e7de8 100644
--- a/boot_control_copy/boot_control_copy.c
+++ b/boot_control_copy/boot_control_copy.c
@@ -39,21 +39,52 @@ unsigned module_getNumberSlots(boot_control_module_t *module)
return 2;
}
+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 (fstat(fd, &statbuf) != 0) {
+ fprintf(stderr, "WARNING: Error getting information about part %s: %s\n",
+ name, strerror(errno));
+ close(fd);
+ return false;
+ }
+ close(fd);
+ *out_device = statbuf.st_rdev;
+ return true;
+}
+
unsigned module_getCurrentSlot(boot_control_module_t *module)
{
- BrilloBootInfo info;
+ struct stat statbuf;
+ dev_t system_a_dev, system_b_dev;
- if (!boot_info_load(&info)) {
- fprintf(stderr, "WARNING: Error loading boot-info. Resetting.\n");
- boot_info_reset(&info);
- } else {
- if (!boot_info_validate(&info)) {
- fprintf(stderr, "WARNING: boot-info is invalid. Resetting.\n");
- boot_info_reset(&info);
- }
+ if (stat("/system", &statbuf) != 0) {
+ fprintf(stderr, "WARNING: Error getting information about /system: %s\n",
+ strerror(errno));
+ return 0;
}
- return info.active_slot;
+ if (!get_dev_t_for_partition("system_a", &system_a_dev) ||
+ !get_dev_t_for_partition("system_b", &system_b_dev))
+ return 0;
+
+ if (statbuf.st_dev == system_a_dev) {
+ return 0;
+ } else if (statbuf.st_dev == system_b_dev) {
+ return 1;
+ } else {
+ 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(system_b_dev), minor(system_b_dev));
+ return 0;
+ }
}
int module_markBootSuccessful(boot_control_module_t *module)