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

Side by Side Diff: udev-device.cc

Issue 6838011: adds a signal, fixes a crash, adds syslogging, and marshals disks to d-bus (Closed) Base URL: ssh://gitrw.chromium.org:9222/cros-disks.git@master
Patch Set: addresses code review comments Created 9 years, 8 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 | « main.cc ('k') | no next file » | 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) 2011 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2011 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 <base/string_number_conversions.h> 5 #include <base/string_number_conversions.h>
6 #include <base/string_util.h> 6 #include <base/string_util.h>
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <libudev.h> 8 #include <libudev.h>
9 #include <sys/statvfs.h> 9 #include <sys/statvfs.h>
10 #include <fstream> 10 #include <fstream>
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 return is_media_available; 103 return is_media_available;
104 } 104 }
105 105
106 std::vector<std::string> UdevDevice::GetMountedPaths() const { 106 std::vector<std::string> UdevDevice::GetMountedPaths() const {
107 const std::string dev_file = udev_device_get_devnode(dev_); 107 const std::string dev_file = udev_device_get_devnode(dev_);
108 std::ifstream fs("/proc/mounts"); 108 std::ifstream fs("/proc/mounts");
109 if (fs.is_open()) { 109 if (fs.is_open()) {
110 return ParseMountedPaths(dev_file, fs); 110 return ParseMountedPaths(dev_file, fs);
111 } 111 }
112 LOG(INFO) << "unable to parse /proc/mounts";
112 return std::vector<std::string>(); 113 return std::vector<std::string>();
113 } 114 }
114 115
115 std::vector<std::string> UdevDevice::ParseMountedPaths( 116 std::vector<std::string> UdevDevice::ParseMountedPaths(
116 const std::string& device_path, std::istream& stream) { 117 const std::string& device_path, std::istream& stream) {
117 std::vector<std::string> mounted_paths; 118 std::vector<std::string> mounted_paths;
118 std::string line; 119 std::string line;
119 while (std::getline(stream, line)) { 120 while (std::getline(stream, line)) {
120 std::vector<std::string> tokens; 121 std::vector<std::string> tokens;
121 SplitString(line, ' ', &tokens); 122 SplitString(line, ' ', &tokens);
(...skipping 16 matching lines...) Expand all
138 disk.set_is_media_available(IsMediaAvailable()); 139 disk.set_is_media_available(IsMediaAvailable());
139 disk.set_drive_model(GetProperty("ID_MODEL")); 140 disk.set_drive_model(GetProperty("ID_MODEL"));
140 disk.set_label(GetProperty("ID_FS_LABEL")); 141 disk.set_label(GetProperty("ID_FS_LABEL"));
141 disk.set_native_path(udev_device_get_syspath(dev_)); 142 disk.set_native_path(udev_device_get_syspath(dev_));
142 143
143 const char *dev_file = udev_device_get_devnode(dev_); 144 const char *dev_file = udev_device_get_devnode(dev_);
144 disk.set_device_file(dev_file); 145 disk.set_device_file(dev_file);
145 146
146 std::vector<std::string> mounted_paths = GetMountedPaths(); 147 std::vector<std::string> mounted_paths = GetMountedPaths();
147 disk.set_is_mounted(!mounted_paths.empty()); 148 disk.set_is_mounted(!mounted_paths.empty());
148 disk.set_mount_path(mounted_paths[0]); // TODO(benchan): multiple paths 149
150 if (!mounted_paths.empty()) {
151 // TODO(benchan): support multiple paths
152 disk.set_mount_path(mounted_paths[0]);
153 }
149 154
150 uint64 total_size, remaining_size; 155 uint64 total_size, remaining_size;
151 GetSizeInfo(&total_size, &remaining_size); 156 GetSizeInfo(&total_size, &remaining_size);
152 disk.set_device_capacity(total_size); 157 disk.set_device_capacity(total_size);
153 disk.set_bytes_remaining(remaining_size); 158 disk.set_bytes_remaining(remaining_size);
154 159
155 return disk; 160 return disk;
156 } 161 }
157 162
158 } // namespace cros_disks 163 } // namespace cros_disks
OLDNEW
« no previous file with comments | « main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698