diff options
author | Andres Morales <anmorales@google.com> | 2014-08-06 19:07:35 +0200 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-05 02:34:22 +0200 |
commit | 9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad (patch) | |
tree | 1d60fc74a6983fe4a1ef3f60e2d039857a18c2a1 /roots.cpp | |
parent | remove spurious parens from error message (diff) | |
parent | Erase PST partition if its marked to be erased. (diff) | |
download | android_bootable_recovery-9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad.tar android_bootable_recovery-9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad.tar.gz android_bootable_recovery-9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad.tar.bz2 android_bootable_recovery-9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad.tar.lz android_bootable_recovery-9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad.tar.xz android_bootable_recovery-9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad.tar.zst android_bootable_recovery-9dc71cfa5233789a50d8a9d2c9af87d0f106d4ad.zip |
Diffstat (limited to 'roots.cpp')
-rw-r--r-- | roots.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -39,6 +39,8 @@ static struct fstab *fstab = NULL; extern struct selabel_handle *sehandle; +static const char* PERSISTENT_PATH = "/persistent"; + void load_volume_table() { int i; @@ -264,6 +266,41 @@ int format_volume(const char* volume) { return -1; } +int erase_persistent_partition() { + Volume *v = volume_for_path(PERSISTENT_PATH); + if (v == NULL) { + // most devices won't have /persistent, so this is not an error. + return 0; + } + + int fd = open(v->blk_device, O_RDWR); + uint64_t size = get_file_size(fd); + if (size == 0) { + LOGE("failed to stat size of /persistent\n"); + close(fd); + return -1; + } + + char oem_unlock_enabled; + lseek(fd, size - 1, SEEK_SET); + read(fd, &oem_unlock_enabled, 1); + + if (oem_unlock_enabled) { + if (wipe_block_device(fd, size)) { + LOGE("error wiping /persistent: %s\n", strerror(errno)); + close(fd); + return -1; + } + + lseek(fd, size - 1, SEEK_SET); + write(fd, &oem_unlock_enabled, 1); + } + + close(fd); + + return (int) oem_unlock_enabled; +} + int setup_install_mounts() { if (fstab == NULL) { LOGE("can't set up install mounts: no fstab loaded\n"); |