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

Side by Side Diff: filesystem_copier_action.h

Issue 3712003: AU: Verify source rootfs/kernel hashes before applying delta. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: verify source partitions only for new updates Created 10 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « download_action.cc ('k') | filesystem_copier_action.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__ 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
7 7
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10
10 #include <string> 11 #include <string>
11 #include <vector> 12 #include <vector>
13
12 #include <gio/gio.h> 14 #include <gio/gio.h>
13 #include <glib.h> 15 #include <glib.h>
16 #include <gtest/gtest_prod.h> // for FRIEND_TEST
17
14 #include "update_engine/action.h" 18 #include "update_engine/action.h"
15 #include "update_engine/install_plan.h" 19 #include "update_engine/install_plan.h"
20 #include "update_engine/omaha_hash_calculator.h"
16 21
17 // This action will only do real work if it's a delta update. It will 22 // This action will only do real work if it's a delta update. It will
18 // copy the root partition to install partition, and then terminate. 23 // copy the root partition to install partition, and then terminate.
19 24
20 namespace chromeos_update_engine { 25 namespace chromeos_update_engine {
21 26
22 class FilesystemCopierAction; 27 class FilesystemCopierAction;
23 28
24 template<> 29 template<>
25 class ActionTraits<FilesystemCopierAction> { 30 class ActionTraits<FilesystemCopierAction> {
26 public: 31 public:
27 // Takes the install plan as input 32 // Takes the install plan as input
28 typedef InstallPlan InputObjectType; 33 typedef InstallPlan InputObjectType;
29 // Passes the install plan as output 34 // Passes the install plan as output
30 typedef InstallPlan OutputObjectType; 35 typedef InstallPlan OutputObjectType;
31 }; 36 };
32 37
33 class FilesystemCopierAction : public Action<FilesystemCopierAction> { 38 class FilesystemCopierAction : public Action<FilesystemCopierAction> {
34 public: 39 public:
35 explicit FilesystemCopierAction(bool copying_kernel_install_path) 40 explicit FilesystemCopierAction(bool copying_kernel_install_path)
36 : copying_kernel_install_path_(copying_kernel_install_path), 41 : copying_kernel_install_path_(copying_kernel_install_path),
37 src_stream_(NULL), 42 src_stream_(NULL),
38 dst_stream_(NULL), 43 dst_stream_(NULL),
39 canceller_(NULL), 44 canceller_(NULL),
40 read_in_flight_(false), 45 read_in_flight_(false),
41 buffer_valid_size_(0) {} 46 buffer_valid_size_(0),
47 filesystem_size_(kint64max) {}
42 typedef ActionTraits<FilesystemCopierAction>::InputObjectType 48 typedef ActionTraits<FilesystemCopierAction>::InputObjectType
43 InputObjectType; 49 InputObjectType;
44 typedef ActionTraits<FilesystemCopierAction>::OutputObjectType 50 typedef ActionTraits<FilesystemCopierAction>::OutputObjectType
45 OutputObjectType; 51 OutputObjectType;
46 void PerformAction(); 52 void PerformAction();
47 void TerminateProcessing(); 53 void TerminateProcessing();
48 54
49 // Used for testing, so we can copy from somewhere other than root 55 // Used for testing, so we can copy from somewhere other than root
50 void set_copy_source(const std::string& path) { 56 void set_copy_source(const std::string& path) {
51 copy_source_ = path; 57 copy_source_ = path;
52 } 58 }
53 59
54 // Debugging/logging 60 // Debugging/logging
55 static std::string StaticType() { return "FilesystemCopierAction"; } 61 static std::string StaticType() { return "FilesystemCopierAction"; }
56 std::string Type() const { return StaticType(); } 62 std::string Type() const { return StaticType(); }
57 63
58 private: 64 private:
65 friend class FilesystemCopierActionTest;
66 FRIEND_TEST(FilesystemCopierActionTest, RunAsRootDetermineFilesystemSizeTest);
67
59 // Callback from glib when the copy operation is done. 68 // Callback from glib when the copy operation is done.
60 void AsyncReadyCallback(GObject *source_object, GAsyncResult *res); 69 void AsyncReadyCallback(GObject *source_object, GAsyncResult *res);
61 static void StaticAsyncReadyCallback(GObject *source_object, 70 static void StaticAsyncReadyCallback(GObject *source_object,
62 GAsyncResult *res, 71 GAsyncResult *res,
63 gpointer user_data) { 72 gpointer user_data) {
64 reinterpret_cast<FilesystemCopierAction*>(user_data)->AsyncReadyCallback( 73 reinterpret_cast<FilesystemCopierAction*>(user_data)->AsyncReadyCallback(
65 source_object, res); 74 source_object, res);
66 } 75 }
67 76
68 // Cleans up all the variables we use for async operations and tells 77 // Cleans up all the variables we use for async operations and tells
69 // the ActionProcessor we're done w/ success as passed in. 78 // the ActionProcessor we're done w/ success as passed in.
70 // was_cancelled should be true if TerminateProcessing() was called. 79 // was_cancelled should be true if TerminateProcessing() was called.
71 void Cleanup(bool success, bool was_cancelled); 80 void Cleanup(bool success, bool was_cancelled);
72 81
82 // Determine, if possible, the source file system size to avoid copying the
83 // whole partition. Currently this supports only the root file system assuming
84 // it's ext3-compatible.
85 void DetermineFilesystemSize(int fd);
86
87 // Returns the number of bytes to read based on the size of the buffer and the
88 // filesystem size.
89 int64_t GetBytesToRead();
90
73 // If true, this action is copying to the kernel_install_path from 91 // If true, this action is copying to the kernel_install_path from
74 // the install plan, otherwise it's copying just to the install_path. 92 // the install plan, otherwise it's copying just to the install_path.
75 const bool copying_kernel_install_path_; 93 const bool copying_kernel_install_path_;
76 94
77 // The path to copy from. If empty (the default), the source is from the 95 // The path to copy from. If empty (the default), the source is from the
78 // passed in InstallPlan. 96 // passed in InstallPlan.
79 std::string copy_source_; 97 std::string copy_source_;
80 98
81 // If non-NULL, these are GUnixInputStream objects for the opened 99 // If non-NULL, these are GUnixInputStream objects for the opened
82 // source/destination partitions. 100 // source/destination partitions.
83 GInputStream* src_stream_; 101 GInputStream* src_stream_;
84 GOutputStream* dst_stream_; 102 GOutputStream* dst_stream_;
85 103
86 // If non-NULL, the cancellable object for the in-flight async call. 104 // If non-NULL, the cancellable object for the in-flight async call.
87 GCancellable* canceller_; 105 GCancellable* canceller_;
88 106
89 // True if we're waiting on a read to complete; false if we're 107 // True if we're waiting on a read to complete; false if we're
90 // waiting on a write. 108 // waiting on a write.
91 bool read_in_flight_; 109 bool read_in_flight_;
92 110
93 // The buffer for storing data we read/write. 111 // The buffer for storing data we read/write.
94 std::vector<char> buffer_; 112 std::vector<char> buffer_;
95 113
96 // Number of valid elements in buffer_. 114 // Number of valid elements in buffer_.
97 std::vector<char>::size_type buffer_valid_size_; 115 std::vector<char>::size_type buffer_valid_size_;
98 116
99 // The install plan we're passed in via the input pipe. 117 // The install plan we're passed in via the input pipe.
100 InstallPlan install_plan_; 118 InstallPlan install_plan_;
101 119
120 // Calculates the hash of the copied data.
121 OmahaHashCalculator hasher_;
122
123 // Copies and hashes this many bytes from the head of the input stream. This
124 // field is initialized when the action is started and decremented as more
125 // bytes get copied.
126 int64_t filesystem_size_;
127
102 DISALLOW_COPY_AND_ASSIGN(FilesystemCopierAction); 128 DISALLOW_COPY_AND_ASSIGN(FilesystemCopierAction);
103 }; 129 };
104 130
105 } // namespace chromeos_update_engine 131 } // namespace chromeos_update_engine
106 132
107 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__ 133 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
OLDNEW
« no previous file with comments | « download_action.cc ('k') | filesystem_copier_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698