OSDN Git Service

Merge "libfec: add a function to disable verity" am: c3788283d7 am: 964746605c
authorSami Tolvanen <samitolvanen@google.com>
Tue, 20 Oct 2015 21:38:10 +0000 (21:38 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Tue, 20 Oct 2015 21:38:10 +0000 (21:38 +0000)
am: 42ca2c65b4

* commit '42ca2c65b4a14ef2817e017d1203a2c3ca7a0e44':
  libfec: add a function to disable verity

libfec/fec_verity.cpp
libfec/include/fec/io.h

index eaf56b4..7537530 100644 (file)
@@ -602,3 +602,40 @@ int verity_parse_header(fec_handle *f, uint64_t offset)
 
     return 0;
 }
+
+int fec_verity_set_status(struct fec_handle *f, bool enabled)
+{
+    check(f);
+
+    if (!(f->mode & O_RDWR)) {
+        error("cannot update verity magic: read-only handle");
+        errno = EBADF;
+        return -1;
+    }
+
+    verity_info *v = &f->verity;
+
+    if (!v->metadata_start) {
+        error("cannot update verity magic: no metadata found");
+        errno = EINVAL;
+        return -1;
+    }
+
+    if (v->disabled == !enabled) {
+        return 0; /* nothing to do */
+    }
+
+    uint32_t magic = enabled ? VERITY_MAGIC : VERITY_MAGIC_DISABLE;
+
+    if (!raw_pwrite(f, &magic, sizeof(magic), v->metadata_start)) {
+        error("failed to update verity magic to %08x: %s", magic,
+            strerror(errno));
+        return -1;
+    }
+
+    warn("updated verity magic to %08x (%s)", magic,
+        enabled ? "enabled" : "disabled");
+    v->disabled = !enabled;
+
+    return 0;
+}
index 5a9decb..1a077f3 100644 (file)
@@ -90,6 +90,8 @@ extern int fec_open(struct fec_handle **f, const char *path, int mode,
 
 extern int fec_close(struct fec_handle *f);
 
+extern int fec_verity_set_status(struct fec_handle *f, bool enabled);
+
 extern int fec_verity_get_metadata(struct fec_handle *f,
         struct fec_verity_metadata *data);
 
@@ -177,6 +179,10 @@ namespace fec {
             return get_ecc_metadata(data) && data.valid;
         }
 
+        bool set_verity_status(bool enabled) {
+            return !fec_verity_set_status(handle_.get(), enabled);
+        }
+
     private:
         handle handle_;
     };