Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: src/platform/update_engine/extent_mapper.cc

Issue 650199: AU: Extent Mapper class (Closed)
Patch Set: fixes for review Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/update_engine/extent_mapper.h ('k') | src/platform/update_engine/extent_mapper_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/update_engine/extent_mapper.cc
diff --git a/src/platform/update_engine/extent_mapper.cc b/src/platform/update_engine/extent_mapper.cc
new file mode 100755
index 0000000000000000000000000000000000000000..9546cfbaebfb2e0931c9cf051fdfd1f48d45f5e4
--- /dev/null
+++ b/src/platform/update_engine/extent_mapper.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2010 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.
+
+#include "update_engine/extent_mapper.h"
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <linux/fs.h>
+#include "update_engine/utils.h"
+
+using std::string;
+using std::vector;
+
+namespace chromeos_update_engine {
+
+namespace {
+const int kBlockSize = 4096;
+}
+
+bool ExtentsForFileFibmap(const std::string& path, std::vector<Extent>* out) {
+ CHECK(out);
+ // TODO(adlr): verify path is a file
+ struct stat stbuf;
+ int rc = stat(path.c_str(), &stbuf);
+ TEST_AND_RETURN_FALSE_ERRNO(rc == 0);
+ TEST_AND_RETURN_FALSE(S_ISREG(stbuf.st_mode));
+
+ int fd = open(path.c_str(), O_RDONLY, 0);
+ TEST_AND_RETURN_FALSE_ERRNO(fd >= 0);
+ ScopedFdCloser fd_closer(&fd);
+
+ // Get file size in blocks
+ rc = fstat(fd, &stbuf);
+ if (rc < 0) {
+ perror("fstat");
+ return false;
+ }
+ const int block_count = (stbuf.st_size + kBlockSize - 1) / kBlockSize;
+ Extent current;
+ current.set_start_block(0);
+ current.set_num_blocks(0);
+
+ for (int i = 0; i < block_count; i++) {
+ unsigned int block = i;
+ rc = ioctl(fd, FIBMAP, &block);
+ TEST_AND_RETURN_FALSE_ERRNO(rc == 0);
+
+ // Add next block to extents
+ if (current.num_blocks() == 0) {
+ // We're starting a new extent
+ current.set_start_block(block);
+ current.set_num_blocks(1);
+ continue;
+ }
+ if ((current.start_block() + current.num_blocks()) == block) {
+ // We're continuing the last extent
+ current.set_num_blocks(current.num_blocks() + 1);
+ continue;
+ }
+ // We're starting a new extent and keeping the current one
+ out->push_back(current);
+ current.set_start_block(block);
+ current.set_num_blocks(1);
+ continue;
+ }
+
+ if (current.num_blocks() > 0)
+ out->push_back(current);
+
+ return true;
+}
+
+} // namespace chromeos_update_engine
« no previous file with comments | « src/platform/update_engine/extent_mapper.h ('k') | src/platform/update_engine/extent_mapper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698