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

Side by Side Diff: src/platform/update_engine/utils.cc

Issue 1694025: AU: Update Downloader to support our image formats. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: fixes for review Created 10 years, 7 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
« no previous file with comments | « src/platform/update_engine/utils.h ('k') | src/platform/update_engine/utils_unittest.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium 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 "update_engine/utils.h" 5 #include "update_engine/utils.h"
6 #include <sys/mount.h> 6 #include <sys/mount.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <dirent.h> 9 #include <dirent.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return false; 290 return false;
291 return 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix); 291 return 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
292 } 292 }
293 293
294 bool StringHasPrefix(const std::string& str, const std::string& prefix) { 294 bool StringHasPrefix(const std::string& str, const std::string& prefix) {
295 if (prefix.size() > str.size()) 295 if (prefix.size() > str.size())
296 return false; 296 return false;
297 return 0 == str.compare(0, prefix.size(), prefix); 297 return 0 == str.compare(0, prefix.size(), prefix);
298 } 298 }
299 299
300 const std::string BootDevice() { 300 const string BootDevice() {
301 string proc_cmdline; 301 string proc_cmdline;
302 if (!ReadFileToString("/proc/cmdline", &proc_cmdline)) 302 if (!ReadFileToString("/proc/cmdline", &proc_cmdline))
303 return ""; 303 return "";
304 // look for "root=" in the command line 304 // look for "root=" in the command line
305 string::size_type pos = 0; 305 string::size_type pos = 0;
306 if (!StringHasPrefix(proc_cmdline, "root=")) { 306 if (!StringHasPrefix(proc_cmdline, "root=")) {
307 pos = proc_cmdline.find(" root=") + 1; 307 pos = proc_cmdline.find(" root=") + 1;
308 } 308 }
309 if (pos == string::npos) { 309 if (pos == string::npos) {
310 // can't find root= 310 // can't find root=
311 return ""; 311 return "";
312 } 312 }
313 // at this point, pos is the point in the string where "root=" starts 313 // at this point, pos is the point in the string where "root=" starts
314 string ret; 314 string ret;
315 pos += strlen("root="); // advance to the device name itself 315 pos += strlen("root="); // advance to the device name itself
316 while (pos < proc_cmdline.size()) { 316 while (pos < proc_cmdline.size()) {
317 char c = proc_cmdline[pos]; 317 char c = proc_cmdline[pos];
318 if (c == ' ') 318 if (c == ' ')
319 break; 319 break;
320 ret += c; 320 ret += c;
321 pos++; 321 pos++;
322 } 322 }
323 return ret; 323 return ret;
324 // TODO(adlr): use findfs to figure out UUID= or LABEL= filesystems 324 // TODO(adlr): use findfs to figure out UUID= or LABEL= filesystems
325 } 325 }
326 326
327 const string BootKernelDevice(const std::string& boot_device) {
328 // Currntly this assumes the last digit of the boot device is
329 // 3, 5, or 7, and changes it to 2, 4, or 6, respectively, to
330 // get the kernel device.
331 string ret = boot_device;
332 if (ret.empty())
333 return ret;
334 char last_char = ret[ret.size() - 1];
335 if (last_char == '3' || last_char == '5' || last_char == '7') {
336 ret[ret.size() - 1] = last_char - 1;
337 return ret;
338 }
339 return "";
340 }
341
327 bool MountFilesystem(const string& device, 342 bool MountFilesystem(const string& device,
328 const string& mountpoint, 343 const string& mountpoint,
329 unsigned long mountflags) { 344 unsigned long mountflags) {
330 int rc = mount(device.c_str(), mountpoint.c_str(), "ext3", mountflags, NULL); 345 int rc = mount(device.c_str(), mountpoint.c_str(), "ext3", mountflags, NULL);
331 if (rc < 0) { 346 if (rc < 0) {
332 string msg = ErrnoNumberAsString(errno); 347 string msg = ErrnoNumberAsString(errno);
333 LOG(ERROR) << "Unable to mount destination device: " << msg << ". " 348 LOG(ERROR) << "Unable to mount destination device: " << msg << ". "
334 << device << " on " << mountpoint; 349 << device << " on " << mountpoint;
335 return false; 350 return false;
336 } 351 }
(...skipping 10 matching lines...) Expand all
347 return "Unknown error."; 362 return "Unknown error.";
348 return error->message; 363 return error->message;
349 } 364 }
350 365
351 const char* const kStatefulPartition = "/mnt/stateful_partition"; 366 const char* const kStatefulPartition = "/mnt/stateful_partition";
352 367
353 } // namespace utils 368 } // namespace utils
354 369
355 } // namespace chromeos_update_engine 370 } // namespace chromeos_update_engine
356 371
OLDNEW
« no previous file with comments | « src/platform/update_engine/utils.h ('k') | src/platform/update_engine/utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698