diff options
author | David Zeuthen <zeuthen@google.com> | 2015-09-24 16:25:32 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-09-24 16:25:32 +0000 |
commit | 133143c56f336eef6545ef99f4c874dba6637ea6 (patch) | |
tree | 16efacfb78ad73a1126366d5c1297c47b3977d11 /boot_control_copy | |
parent | 8ed1c5101b2081784dcece041cf47f765896ef58 (diff) | |
parent | 3af8b53ae8cd70abaca17b7d9140ee12a14486b8 (diff) | |
download | extras-133143c56f336eef6545ef99f4c874dba6637ea6.tar.gz |
Merge "boot_control_copy: Fix getCurrentSlot()."
Diffstat (limited to 'boot_control_copy')
-rw-r--r-- | boot_control_copy/boot_control_copy.c | 51 |
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) |