OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ | 5 #ifndef CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ |
6 #define CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ | 6 #define CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 enum FormatEvent { | 49 enum FormatEvent { |
50 FORMAT_STARTED, | 50 FORMAT_STARTED, |
51 FORMAT_COMPLETED | 51 FORMAT_COMPLETED |
52 }; | 52 }; |
53 | 53 |
54 // Used to house an instance of each found mount device. | 54 // Used to house an instance of each found mount device. |
55 class Disk { | 55 class Disk { |
56 public: | 56 public: |
57 Disk(const std::string& device_path, | 57 Disk(const std::string& device_path, |
| 58 // The path to the mount point of this device. Empty if not mounted. |
| 59 // (e.g. /media/removable/VOLUME) |
58 const std::string& mount_path, | 60 const std::string& mount_path, |
| 61 // Whether the device is mounted in read-only mode by the policy. |
| 62 // Valid only when the device mounted and mount_path_ is non-empty. |
| 63 bool write_disabled_by_policy, |
59 const std::string& system_path, | 64 const std::string& system_path, |
60 const std::string& file_path, | 65 const std::string& file_path, |
61 const std::string& device_label, | 66 const std::string& device_label, |
62 const std::string& drive_label, | 67 const std::string& drive_label, |
63 const std::string& vendor_id, | 68 const std::string& vendor_id, |
64 const std::string& vendor_name, | 69 const std::string& vendor_name, |
65 const std::string& product_id, | 70 const std::string& product_id, |
66 const std::string& product_name, | 71 const std::string& product_name, |
67 const std::string& fs_uuid, | 72 const std::string& fs_uuid, |
68 const std::string& system_path_prefix, | 73 const std::string& system_path_prefix, |
69 DeviceType device_type, | 74 DeviceType device_type, |
70 uint64_t total_size_in_bytes, | 75 uint64_t total_size_in_bytes, |
71 bool is_parent, | 76 bool is_parent, |
72 bool is_read_only, | 77 bool is_read_only_hardware, |
73 bool has_media, | 78 bool has_media, |
74 bool on_boot_device, | 79 bool on_boot_device, |
75 bool on_removable_device, | 80 bool on_removable_device, |
76 bool is_hidden); | 81 bool is_hidden); |
77 Disk(const Disk& other); | 82 Disk(const Disk& other); |
78 ~Disk(); | 83 ~Disk(); |
79 | 84 |
80 // The path of the device, used by devicekit-disks. | 85 // The path of the device, used by devicekit-disks. |
81 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1) | 86 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1) |
82 const std::string& device_path() const { return device_path_; } | 87 const std::string& device_path() const { return device_path_; } |
83 | 88 |
84 // The path to the mount point of this device. Will be empty if not mounted. | 89 // The path to the mount point of this device. Will be empty if not mounted. |
85 // (e.g. /media/removable/VOLUME) | 90 // (e.g. /media/removable/VOLUME) |
86 const std::string& mount_path() const { return mount_path_; } | 91 const std::string& mount_path() const { return mount_path_; } |
87 | 92 |
88 // The path of the device according to the udev system. | 93 // The path of the device according to the udev system. |
89 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1) | 94 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1) |
90 const std::string& system_path() const { return system_path_; } | 95 const std::string& system_path() const { return system_path_; } |
91 | 96 |
92 // The path of the device according to filesystem. | 97 // The path of the device according to filesystem. |
93 // (e.g. /dev/sdb) | 98 // (e.g. /dev/sdb) |
94 const std::string& file_path() const { return file_path_; } | 99 const std::string& file_path() const { return file_path_; } |
95 | 100 |
96 // Device's label. | 101 // Device's label. |
(...skipping 26 matching lines...) Expand all Loading... |
123 | 128 |
124 // Device type. | 129 // Device type. |
125 DeviceType device_type() const { return device_type_; } | 130 DeviceType device_type() const { return device_type_; } |
126 | 131 |
127 // Total size of the device in bytes. | 132 // Total size of the device in bytes. |
128 uint64_t total_size_in_bytes() const { return total_size_in_bytes_; } | 133 uint64_t total_size_in_bytes() const { return total_size_in_bytes_; } |
129 | 134 |
130 // Is the device is a parent device (i.e. sdb rather than sdb1). | 135 // Is the device is a parent device (i.e. sdb rather than sdb1). |
131 bool is_parent() const { return is_parent_; } | 136 bool is_parent() const { return is_parent_; } |
132 | 137 |
| 138 // Whether the user can write to the device. True if read-only. |
| 139 bool is_read_only() const { |
| 140 return is_read_only_hardware_ || write_disabled_by_policy_; |
| 141 } |
| 142 |
133 // Is the device read only. | 143 // Is the device read only. |
134 bool is_read_only() const { return is_read_only_; } | 144 bool is_read_only_hardware() const { return is_read_only_hardware_; } |
135 | 145 |
136 // Does the device contains media. | 146 // Does the device contains media. |
137 bool has_media() const { return has_media_; } | 147 bool has_media() const { return has_media_; } |
138 | 148 |
139 // Is the device on the boot device. | 149 // Is the device on the boot device. |
140 bool on_boot_device() const { return on_boot_device_; } | 150 bool on_boot_device() const { return on_boot_device_; } |
141 | 151 |
142 // Is the device on the removable device. | 152 // Is the device on the removable device. |
143 bool on_removable_device() const { return on_removable_device_; } | 153 bool on_removable_device() const { return on_removable_device_; } |
144 | 154 |
145 // Shoud the device be shown in the UI, or automounted. | 155 // Shoud the device be shown in the UI, or automounted. |
146 bool is_hidden() const { return is_hidden_; } | 156 bool is_hidden() const { return is_hidden_; } |
147 | 157 |
148 void set_mount_path(const std::string& mount_path) { | 158 void set_mount_path(const std::string& mount_path) { |
149 mount_path_ = mount_path; | 159 mount_path_ = mount_path; |
150 } | 160 } |
151 | 161 |
152 void set_read_only(bool is_read_only) { is_read_only_ = is_read_only; } | 162 void set_write_disabled_by_policy(bool disable) { |
| 163 write_disabled_by_policy_ = disable; |
| 164 } |
153 | 165 |
154 void clear_mount_path() { mount_path_.clear(); } | 166 void clear_mount_path() { mount_path_.clear(); } |
155 | 167 |
156 private: | 168 private: |
157 std::string device_path_; | 169 std::string device_path_; |
158 std::string mount_path_; | 170 std::string mount_path_; |
| 171 bool write_disabled_by_policy_; |
159 std::string system_path_; | 172 std::string system_path_; |
160 std::string file_path_; | 173 std::string file_path_; |
161 std::string device_label_; | 174 std::string device_label_; |
162 std::string drive_label_; | 175 std::string drive_label_; |
163 std::string vendor_id_; | 176 std::string vendor_id_; |
164 std::string vendor_name_; | 177 std::string vendor_name_; |
165 std::string product_id_; | 178 std::string product_id_; |
166 std::string product_name_; | 179 std::string product_name_; |
167 std::string fs_uuid_; | 180 std::string fs_uuid_; |
168 std::string system_path_prefix_; | 181 std::string system_path_prefix_; |
169 DeviceType device_type_; | 182 DeviceType device_type_; |
170 uint64_t total_size_in_bytes_; | 183 uint64_t total_size_in_bytes_; |
171 bool is_parent_; | 184 bool is_parent_; |
172 bool is_read_only_; | 185 bool is_read_only_hardware_; |
173 bool has_media_; | 186 bool has_media_; |
174 bool on_boot_device_; | 187 bool on_boot_device_; |
175 bool on_removable_device_; | 188 bool on_removable_device_; |
176 bool is_hidden_; | 189 bool is_hidden_; |
177 }; | 190 }; |
178 typedef std::map<std::string, std::unique_ptr<Disk>> DiskMap; | 191 typedef std::map<std::string, std::unique_ptr<Disk>> DiskMap; |
179 | 192 |
180 // A struct to store information about mount point. | 193 // A struct to store information about mount point. |
181 struct MountPointInfo { | 194 struct MountPointInfo { |
182 // Device's path. | 195 // Device's path. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 328 |
316 // Returns a pointer to the global DiskMountManager instance. | 329 // Returns a pointer to the global DiskMountManager instance. |
317 // Initialize() should already have been called. | 330 // Initialize() should already have been called. |
318 static DiskMountManager* GetInstance(); | 331 static DiskMountManager* GetInstance(); |
319 }; | 332 }; |
320 | 333 |
321 } // namespace disks | 334 } // namespace disks |
322 } // namespace chromeos | 335 } // namespace chromeos |
323 | 336 |
324 #endif // CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ | 337 #endif // CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ |
OLD | NEW |