-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecure_erase_file_main.cc
44 lines (37 loc) · 1.43 KB
/
secure_erase_file_main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2017 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "secure_erase_file/secure_erase_file.h"
#include <sysexits.h>
#include <base/command_line.h>
#include <base/logging.h>
#include <brillo/flag_helper.h>
#include <brillo/syslog_logging.h>
int main(int argc, const char* const argv[]) {
DEFINE_bool(zero_out, false,
"Use WRITEZERO instead of BLKSECDISCARD, which is more widely "
"supported but less secure.");
brillo::FlagHelper::Init(argc, argv, "Secure erase tool.");
brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderr |
brillo::kLogHeader);
base::CommandLine::Init(argc, argv);
base::CommandLine::StringVector files =
base::CommandLine::ForCurrentProcess()->GetArgs();
if (files.size() < 1) {
LOG(WARNING) << "At least one file argument must be provided.";
return EX_USAGE;
}
// Use a status variable to erase all the files we possibly can, then drop
// caches. We still return an error if any files have failed so that external
// scripts can react accordingly.
bool ok = true;
for (const auto& file : files) {
if (FLAGS_zero_out) {
ok &= secure_erase_file::ZeroFile(base::FilePath(file));
} else {
ok &= secure_erase_file::SecureErase(base::FilePath(file));
}
}
ok &= secure_erase_file::DropCaches();
return ok ? 0 : EX_IOERR;
}