OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS 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 #include "image-burner/image_burn_service.h" | 5 #include "image-burner/image_burn_service.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <glib.h> | 8 #include <glib.h> |
9 #include <zlib.h> | 9 #include <zlib.h> |
10 | 10 |
11 #include <base/basictypes.h> | 11 #include <base/basictypes.h> |
12 #include <base/file_util.h> | 12 #include <base/file_util.h> |
13 #include <base/logging.h> | 13 #include <base/logging.h> |
14 #include <chromeos/dbus/service_constants.h> | 14 #include <chromeos/dbus/service_constants.h> |
15 #include <cros/chromeos_cros_api.h> | 15 #include <cros/chromeos_cros_api.h> |
16 #include <cros/chromeos_mount.h> | 16 #include <cros/chromeos_mount.h> |
17 #include <dbus/dbus-glib-lowlevel.h> | 17 #include <dbus/dbus-glib-lowlevel.h> |
18 #include <rootdev/rootdev.h> | |
19 | 18 |
20 #include <fstream> | 19 #include <fstream> |
21 #include <string> | 20 #include <string> |
22 | 21 |
23 #include "image-burner/image_burner.h" | 22 #include "image-burner/image_burner.h" |
24 #include "image-burner/marshal.h" | 23 #include "image-burner/marshal.h" |
25 | 24 |
26 namespace imageburn { | 25 namespace imageburn { |
27 #include "image-burner/bindings/server.h" | 26 #include "image-burner/bindings/server.h" |
28 | 27 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 LOG(INFO) << (success ? "Burn complete" : "Burn failed"); | 162 LOG(INFO) << (success ? "Burn complete" : "Burn failed"); |
164 } else { | 163 } else { |
165 err = "Unable to unmount target path"; | 164 err = "Unable to unmount target path"; |
166 success = false; | 165 success = false; |
167 } | 166 } |
168 | 167 |
169 SendFinishedSignal(to_path, success, err.c_str()); | 168 SendFinishedSignal(to_path, success, err.c_str()); |
170 burning_ = false; | 169 burning_ = false; |
171 } | 170 } |
172 | 171 |
173 bool ImageBurnService::IsBootPath(const char* device_path) { | |
174 char boot_path[PATH_MAX]; | |
175 if (rootdev(boot_path, sizeof(boot_path), true, true)) { | |
176 LOG(ERROR) << "IsBootPath: rootdev failed to find the root device"; | |
177 return true; | |
178 } | |
179 | |
180 return (strncmp(device_path, boot_path, strlen(boot_path)) == 0); | |
181 } | |
182 | |
183 bool ImageBurnService::UnmountAndValidateDevice(const char* device_path) { | 172 bool ImageBurnService::UnmountAndValidateDevice(const char* device_path) { |
184 if (IsBootPath(device_path)) { | 173 if (chromeos::IsBootDevicePath(device_path)) { |
185 LOG(ERROR) << device_path << " is on root device"; | 174 LOG(ERROR) << device_path << " is on root device"; |
186 return false; | 175 return false; |
187 } | 176 } |
188 | 177 |
189 LOG(INFO) << "Unmounting " << device_path; | 178 LOG(INFO) << "Unmounting " << device_path; |
190 chromeos::MountStatus* status = chromeos::RetrieveMountInformation(); | 179 chromeos::MountStatus* status = chromeos::RetrieveMountInformation(); |
191 | 180 |
192 bool success = false; | 181 bool success = false; |
193 for (int i = 0; i < status->size; ++i) { | 182 for (int i = 0; i < status->size; ++i) { |
194 FilePath device_system_path | 183 FilePath device_system_path |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 fseek(from_file, -sizeof(result), SEEK_END); | 323 fseek(from_file, -sizeof(result), SEEK_END); |
335 if (fread(&result, 1, sizeof(result), from_file) != sizeof(result)) { | 324 if (fread(&result, 1, sizeof(result), from_file) != sizeof(result)) { |
336 result = 0; | 325 result = 0; |
337 } | 326 } |
338 fclose(from_file); | 327 fclose(from_file); |
339 return static_cast<int64>(result); | 328 return static_cast<int64>(result); |
340 } | 329 } |
341 | 330 |
342 } // namespace imageburn | 331 } // namespace imageburn |
343 | 332 |
OLD | NEW |