summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@google.com>2018-08-03 16:55:37 -0700
committerandroid-build-merger <android-build-merger@google.com>2018-08-03 16:55:37 -0700
commitb7b419541b1df5d3450252749e8f760b5edc3bbe (patch)
treef4f514e478e91ff49ca25b2b81179f241f5f2182
parent2abec98856588bb135d0b0e487313c2faff3622e (diff)
parentcb114c36d89edb4f3f45f517cafba51bcc2d730f (diff)
downloadvold-temp_p_merge.tar.gz
Merge "secdiscard: should pin_file to avoid moving blocks in F2FS"temp_p_merge
am: cb114c36d8 Change-Id: I3376ce6a9844d26c4e5658fc95477b8d6c9c0afe
-rw-r--r--secdiscard.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/secdiscard.cpp b/secdiscard.cpp
index f9532ea5..60834e89 100644
--- a/secdiscard.cpp
+++ b/secdiscard.cpp
@@ -57,7 +57,33 @@ int main(int argc, const char * const argv[]) {
usage(argv[0]);
return -1;
}
+
for (auto const &target: options.targets) {
+// F2FS-specific ioctl
+// It requires the below kernel commit merged in v4.16-rc1.
+// 1ad71a27124c ("f2fs: add an ioctl to disable GC for specific file")
+// In android-4.4,
+// 56ee1e817908 ("f2fs: updates on v4.16-rc1")
+// In android-4.9,
+// 2f17e34672a8 ("f2fs: updates on v4.16-rc1")
+// In android-4.14,
+// ce767d9a55bc ("f2fs: updates on v4.16-rc1")
+#ifndef F2FS_IOC_SET_PIN_FILE
+#ifndef F2FS_IOCTL_MAGIC
+#define F2FS_IOCTL_MAGIC 0xf5
+#endif
+#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32)
+#define F2FS_IOC_GET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 14, __u32)
+#endif
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(
+ target.c_str(), O_WRONLY, 0)));
+ if (fd == -1) {
+ LOG(ERROR) << "Secure discard open failed for: " << target;
+ return 0;
+ }
+ __u32 set = 1;
+ ioctl(fd, F2FS_IOC_SET_PIN_FILE, &set);
+
LOG(DEBUG) << "Securely discarding '" << target << "' unlink=" << options.unlink;
if (!secdiscard_path(target)) {
LOG(ERROR) << "Secure discard failed for: " << target;
@@ -67,6 +93,8 @@ int main(int argc, const char * const argv[]) {
PLOG(ERROR) << "Unable to unlink: " << target;
}
}
+ set = 0;
+ ioctl(fd, F2FS_IOC_SET_PIN_FILE, &set);
LOG(DEBUG) << "Discarded: " << target;
}
return 0;