update_engine: Move ext2 tools to its own file in payload_generator.
update_engine doesn't need to understand about the rootfs filesystem
format, just how to apply the defined operations. This patch moves
the few ext2fs specific code the payload_generator and removes the
dependency on ext2fs from update_engine.
BUG=chromium:394184
TEST=FEATURES="test" emerge-link update_engine; sudo emerge update_engine
Change-Id: If750e4834d42bbeaeddc6eff7c4690dd916c73bf
Reviewed-on: https://chromium-review.googlesource.com/208992
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/payload_generator/ext2_utils.h b/payload_generator/ext2_utils.h
new file mode 100644
index 0000000..fff9cc4
--- /dev/null
+++ b/payload_generator/ext2_utils.h
@@ -0,0 +1,21 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_UTILS_H_
+#define UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_UTILS_H_
+
+#include <ext2fs/ext2fs.h>
+
+// Utility class to close a file system.
+class ScopedExt2fsCloser {
+ public:
+ explicit ScopedExt2fsCloser(ext2_filsys filsys) : filsys_(filsys) {}
+ ~ScopedExt2fsCloser() { ext2fs_close(filsys_); }
+
+ private:
+ ext2_filsys filsys_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedExt2fsCloser);
+};
+
+#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_UTILS_H_
diff --git a/payload_generator/metadata.cc b/payload_generator/metadata.cc
index d0ab82c..7ed1727 100644
--- a/payload_generator/metadata.cc
+++ b/payload_generator/metadata.cc
@@ -15,6 +15,7 @@
#include "update_engine/bzip.h"
#include "update_engine/extent_ranges.h"
#include "update_engine/payload_generator/delta_diff_generator.h"
+#include "update_engine/payload_generator/ext2_utils.h"
#include "update_engine/payload_generator/graph_utils.h"
#include "update_engine/payload_generator/metadata.h"
#include "update_engine/utils.h"
diff --git a/payload_generator/metadata_unittest.cc b/payload_generator/metadata_unittest.cc
index 14e21ae..dcce0c3 100644
--- a/payload_generator/metadata_unittest.cc
+++ b/payload_generator/metadata_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <ext2fs/ext2fs.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>