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
This commit is contained in:
parent
20642ae71a
commit
d46687ee5d
2 changed files with 28 additions and 30 deletions
|
@ -31,6 +31,8 @@
|
|||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <Utils.h>
|
||||
|
||||
namespace android {
|
||||
namespace vold {
|
||||
|
||||
|
@ -4024,35 +4026,32 @@ free(buf);
|
|||
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() {
|
||||
|
|
|
@ -159,6 +159,8 @@ with open("BenchmarkGen.h", 'w') as bench:
|
|||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <Utils.h>
|
||||
|
||||
namespace android {
|
||||
namespace vold {
|
||||
|
||||
|
@ -262,35 +264,32 @@ free(buf);
|
|||
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() {
|
||||
|
|
Loading…
Reference in a new issue