cryptohome: Add Tune2Fs for adding features

Adds a function to call tune2fs to add features to filesystems.
This will be used to add features to per-user filesystems.

BUG=b:172344853
TEST=use with dmcrypt lvm cryptohome, check filesystem features.

Change-Id: I8c5291ca18f8678d32e1e846119683cf8551a1bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2590692
Reviewed-by: Leo Lai <cylai@google.com>
Tested-by: Sarthak Kukreti <sarthakkukreti@chromium.org>
Commit-Queue: Sarthak Kukreti <sarthakkukreti@chromium.org>
diff --git a/cryptohome/mock_platform.h b/cryptohome/mock_platform.h
index f374988..ed134b8 100644
--- a/cryptohome/mock_platform.h
+++ b/cryptohome/mock_platform.h
@@ -374,6 +374,10 @@
                uint64_t),
               (override));
   MOCK_METHOD(bool,
+              Tune2Fs,
+              (const base::FilePath&, const std::vector<std::string>&),
+              (override));
+  MOCK_METHOD(bool,
               ResizeFilesystem,
               (const base::FilePath&, uint64_t),
               (override));
diff --git a/cryptohome/platform.cc b/cryptohome/platform.cc
index 9299842..a8c78b7 100644
--- a/cryptohome/platform.cc
+++ b/cryptohome/platform.cc
@@ -1365,14 +1365,19 @@
     return false;
   }
 
+  // Tune the formatted filesystem:
+  // -c 0: Disable max mount count checking.
+  // -i 0: Disable filesystem checking.
+  return Tune2Fs(file, {"-c", "0", "-i", "0"});
+}
+
+bool Platform::Tune2Fs(const base::FilePath& file,
+                       const std::vector<std::string>& opts) {
   brillo::ProcessImpl tune_process;
   tune_process.AddArg("/sbin/tune2fs");
-  // Disable max mount count checking.
-  tune_process.AddArg("-c");
-  tune_process.AddArg("0");
-  // Disable filesystem checking.
-  tune_process.AddArg("-i");
-  tune_process.AddArg("0");
+  for (const auto& arg : opts)
+    tune_process.AddArg(arg);
+
   tune_process.AddArg(file.value());
 
   // Close unused file descriptors in child process.
@@ -1381,7 +1386,7 @@
   // Avoid polluting the parent process' stdout.
   tune_process.RedirectOutput("/dev/null");
 
-  rc = tune_process.Run();
+  int rc = tune_process.Run();
   if (rc != 0) {
     LOG(ERROR) << "Can't tune ext4: " << file.value() << ", error: " << rc;
     return false;
diff --git a/cryptohome/platform.h b/cryptohome/platform.h
index 5b54cd2..787891a 100644
--- a/cryptohome/platform.h
+++ b/cryptohome/platform.h
@@ -872,6 +872,15 @@
                           const std::vector<std::string>& opts,
                           uint64_t blocks);
 
+  // Tunes ext4 filesystem, adding features if needed.
+  // Returns true if formatting succeeded.
+  //
+  // Paratemers
+  //   file - Path to the file or device to be formatted.
+  //   opts - format opts.
+  virtual bool Tune2Fs(const base::FilePath& file,
+                       const std::vector<std::string>& opts);
+
   // Resizes the file to blocks.
   // Returns true if resize succeeded.
   //