aboutsummaryrefslogtreecommitdiffstats
path: root/roots.cpp
diff options
context:
space:
mode:
authorAndres Morales <anmorales@google.com>2014-08-05 19:49:09 -0700
committerAndres Morales <anmorales@google.com>2014-08-06 09:58:55 -0700
commitee19387905650cab5da7dd97ada5502cd17ac93d (patch)
tree46f1c336bce478470cf2b45511f7a55c61db5021 /roots.cpp
parenta91ecc59b2753a3dcc93b2619559a980074e77bd (diff)
downloadbootable_recovery-ee19387905650cab5da7dd97ada5502cd17ac93d.zip
bootable_recovery-ee19387905650cab5da7dd97ada5502cd17ac93d.tar.gz
bootable_recovery-ee19387905650cab5da7dd97ada5502cd17ac93d.tar.bz2
Erase PST partition if its marked to be erased.
We need to wipe the challenges on this partition if OEM unlock is enabled, as this is a signal that the user has opted out of factory reset protection. go/factory-reset Bug: 16633064 Change-Id: Icb8f1433bf99ca57813f5b72d5a3dd15fa94a263
Diffstat (limited to 'roots.cpp')
-rw-r--r--roots.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/roots.cpp b/roots.cpp
index 8f99019..61798f4 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -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");