Use random data for benchmark instead of zeros.

If we always write zeros, we're leaving a giant pile of known
plaintext at an almost deterministic location on newly formatted
volumes.  To avoid this, repeat a 64K chunk of random data.

Bug: 22816936
Change-Id: Iedc067a519bd676a93b9d74ea4f9f77c84c8461c
diff --git a/bench/benchgen.py b/bench/benchgen.py
index 077336c..77262c4 100644
--- a/bench/benchgen.py
+++ b/bench/benchgen.py
@@ -159,6 +159,8 @@
 #include <algorithm>
 #include <string>
 
+#include <Utils.h>
+
 namespace android {
 namespace vold {
 
@@ -262,35 +264,32 @@
 return 0;
 }
 
-static status_t CreateFile(const char* name, size_t len) {
-    status_t res = -1;
-    int in = -1;
+static status_t CreateFile(const char* name, int len) {
+    int chunk = std::min(len, 65536);
     int out = -1;
+    std::string buf;
 
-    if ((in = TEMP_FAILURE_RETRY(open("/dev/zero", O_RDONLY))) < 0) {
-        PLOG(ERROR) << "Failed to open";
-        goto done;
+    if (android::vold::ReadRandomBytes(chunk, buf) != OK) {
+        LOG(ERROR) << "Failed to read random data";
+        return -EIO;
     }
     if ((out = TEMP_FAILURE_RETRY(open(name, O_WRONLY|O_CREAT|O_TRUNC))) < 0) {
         PLOG(ERROR) << "Failed to open " << name;
-        goto done;
+        return -errno;
     }
 
-    char buf[65536];
     while (len > 0) {
-        int n = read(in, buf, std::min(len, sizeof(buf)));
-        if (write(out, buf, n) != n) {
+        int n = write(out, buf.c_str(), std::min(len, chunk));
+        if (n < 0) {
             PLOG(ERROR) << "Failed to write";
-            goto done;
+            close(out);
+            return -errno;
         }
         len -= n;
     }
 
-    res = 0;
-done:
-    close(in);
     close(out);
-    return res;
+    return OK;
 }
 
 static status_t BenchmarkCreate() {