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

Side by Side Diff: chromeos/disks/disk_mount_manager.cc

Issue 2440443003: Preserve the hardware read-only flag in Disk object. (Closed)
Patch Set: Put the right value at Disk object construction. Created 4 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
« no previous file with comments | « chromeos/disks/disk_mount_manager.h ('k') | chromeos/disks/disk_mount_manager_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) 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 #include "chromeos/disks/disk_mount_manager.h" 5 #include "chromeos/disks/disk_mount_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // from CrosDisksClientImpl::OnMountCompleted. 361 // from CrosDisksClientImpl::OnMountCompleted.
362 // The disk should be treated as read-only when: 362 // The disk should be treated as read-only when:
363 // - the read-only option was passed when issuing mount command 363 // - the read-only option was passed when issuing mount command
364 // - or the device hardware is read-only. 364 // - or the device hardware is read-only.
365 // |source_path| should be same as |disk->device_path| because 365 // |source_path| should be same as |disk->device_path| because
366 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a 366 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a
367 // source path when mounting a device. 367 // source path when mounting a device.
368 AccessModeMap::iterator it = access_modes_.find(entry.source_path()); 368 AccessModeMap::iterator it = access_modes_.find(entry.source_path());
369 if (it != access_modes_.end() && 369 if (it != access_modes_.end() &&
370 it->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY) { 370 it->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY) {
371 disk->set_read_only(true); 371 disk->set_write_disabled_by_policy(true);
372 } 372 }
373 disk->set_mount_path(mount_info.mount_path); 373 disk->set_mount_path(mount_info.mount_path);
374 } 374 }
375 } 375 }
376 // Observers may read the values of disks_. So notify them after tweaking 376 // Observers may read the values of disks_. So notify them after tweaking
377 // values of disks_. 377 // values of disks_.
378 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); 378 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info);
379 } 379 }
380 380
381 // Callback for UnmountPath. 381 // Callback for UnmountPath.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 return; 462 return;
463 463
464 LOG(WARNING) << "Found disk " << disk_info.device_path(); 464 LOG(WARNING) << "Found disk " << disk_info.device_path();
465 // Delete previous disk info for this path: 465 // Delete previous disk info for this path:
466 bool is_new = true; 466 bool is_new = true;
467 DiskMap::iterator iter = disks_.find(disk_info.device_path()); 467 DiskMap::iterator iter = disks_.find(disk_info.device_path());
468 if (iter != disks_.end()) { 468 if (iter != disks_.end()) {
469 disks_.erase(iter); 469 disks_.erase(iter);
470 is_new = false; 470 is_new = false;
471 } 471 }
472
473 // If the device was mounted by the instance, apply recorded parameter.
474 // Otherwise, default to false.
475 // Lookup by |device_path| which we pass to cros-disks when mounting a
476 // device in |VolumeManager::OnDiskEvent()|.
477 AccessModeMap::iterator access_mode =
hashimoto 2016/10/21 08:39:59 nit: You can do auto access_mode = access_modes_
yamaguchi 2016/10/21 08:53:03 Done.
478 access_modes_.find(disk_info.device_path());
479 bool write_disabled_by_policy = access_mode != access_modes_.end()
480 && access_mode->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY;
472 Disk* disk = new Disk(disk_info.device_path(), 481 Disk* disk = new Disk(disk_info.device_path(),
473 disk_info.mount_path(), 482 disk_info.mount_path(),
483 write_disabled_by_policy,
474 disk_info.system_path(), 484 disk_info.system_path(),
475 disk_info.file_path(), 485 disk_info.file_path(),
476 disk_info.label(), 486 disk_info.label(),
477 disk_info.drive_label(), 487 disk_info.drive_label(),
478 disk_info.vendor_id(), 488 disk_info.vendor_id(),
479 disk_info.vendor_name(), 489 disk_info.vendor_name(),
480 disk_info.product_id(), 490 disk_info.product_id(),
481 disk_info.product_name(), 491 disk_info.product_name(),
482 disk_info.uuid(), 492 disk_info.uuid(),
483 FindSystemPathPrefix(disk_info.system_path()), 493 FindSystemPathPrefix(disk_info.system_path()),
484 disk_info.device_type(), 494 disk_info.device_type(),
485 disk_info.total_size_in_bytes(), 495 disk_info.total_size_in_bytes(),
486 disk_info.is_drive(), 496 disk_info.is_drive(),
487 disk_info.is_read_only(), 497 disk_info.is_read_only(),
488 disk_info.has_media(), 498 disk_info.has_media(),
489 disk_info.on_boot_device(), 499 disk_info.on_boot_device(),
490 disk_info.on_removable_device(), 500 disk_info.on_removable_device(),
491 disk_info.is_hidden()); 501 disk_info.is_hidden());
492 // If the device was mounted by the instance, apply recorded parameter.
493 // Lookup by |device_path| which we pass to cros-disks when mounting a
494 // device in |VolumeManager::OnDiskEvent()|.
495 AccessModeMap::iterator access_mode =
496 access_modes_.find(disk->device_path());
497 if (access_mode != access_modes_.end()) {
498 disk->set_read_only(access_mode->second ==
499 chromeos::MOUNT_ACCESS_MODE_READ_ONLY);
500 }
501 disks_.insert( 502 disks_.insert(
502 std::make_pair(disk_info.device_path(), base::WrapUnique(disk))); 503 std::make_pair(disk_info.device_path(), base::WrapUnique(disk)));
503 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); 504 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk);
504 } 505 }
505 506
506 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are 507 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are
507 // enumerated. 508 // enumerated.
508 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { 509 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) {
509 std::set<std::string> current_device_set(devices.begin(), devices.end()); 510 std::set<std::string> current_device_set(devices.begin(), devices.end());
510 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { 511 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 674
674 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; 675 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_;
675 676
676 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); 677 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl);
677 }; 678 };
678 679
679 } // namespace 680 } // namespace
680 681
681 DiskMountManager::Disk::Disk(const std::string& device_path, 682 DiskMountManager::Disk::Disk(const std::string& device_path,
682 const std::string& mount_path, 683 const std::string& mount_path,
684 bool write_disabled_by_policy,
683 const std::string& system_path, 685 const std::string& system_path,
684 const std::string& file_path, 686 const std::string& file_path,
685 const std::string& device_label, 687 const std::string& device_label,
686 const std::string& drive_label, 688 const std::string& drive_label,
687 const std::string& vendor_id, 689 const std::string& vendor_id,
688 const std::string& vendor_name, 690 const std::string& vendor_name,
689 const std::string& product_id, 691 const std::string& product_id,
690 const std::string& product_name, 692 const std::string& product_name,
691 const std::string& fs_uuid, 693 const std::string& fs_uuid,
692 const std::string& system_path_prefix, 694 const std::string& system_path_prefix,
693 DeviceType device_type, 695 DeviceType device_type,
694 uint64_t total_size_in_bytes, 696 uint64_t total_size_in_bytes,
695 bool is_parent, 697 bool is_parent,
696 bool is_read_only, 698 bool is_read_only_hardware,
697 bool has_media, 699 bool has_media,
698 bool on_boot_device, 700 bool on_boot_device,
699 bool on_removable_device, 701 bool on_removable_device,
700 bool is_hidden) 702 bool is_hidden)
701 : device_path_(device_path), 703 : device_path_(device_path),
702 mount_path_(mount_path), 704 mount_path_(mount_path),
705 write_disabled_by_policy_(write_disabled_by_policy),
703 system_path_(system_path), 706 system_path_(system_path),
704 file_path_(file_path), 707 file_path_(file_path),
705 device_label_(device_label), 708 device_label_(device_label),
706 drive_label_(drive_label), 709 drive_label_(drive_label),
707 vendor_id_(vendor_id), 710 vendor_id_(vendor_id),
708 vendor_name_(vendor_name), 711 vendor_name_(vendor_name),
709 product_id_(product_id), 712 product_id_(product_id),
710 product_name_(product_name), 713 product_name_(product_name),
711 fs_uuid_(fs_uuid), 714 fs_uuid_(fs_uuid),
712 system_path_prefix_(system_path_prefix), 715 system_path_prefix_(system_path_prefix),
713 device_type_(device_type), 716 device_type_(device_type),
714 total_size_in_bytes_(total_size_in_bytes), 717 total_size_in_bytes_(total_size_in_bytes),
715 is_parent_(is_parent), 718 is_parent_(is_parent),
716 is_read_only_(is_read_only), 719 is_read_only_hardware_(is_read_only_hardware),
717 has_media_(has_media), 720 has_media_(has_media),
718 on_boot_device_(on_boot_device), 721 on_boot_device_(on_boot_device),
719 on_removable_device_(on_removable_device), 722 on_removable_device_(on_removable_device),
720 is_hidden_(is_hidden) {} 723 is_hidden_(is_hidden) {}
721 724
722 DiskMountManager::Disk::Disk(const Disk& other) = default; 725 DiskMountManager::Disk::Disk(const Disk& other) = default;
723 726
724 DiskMountManager::Disk::~Disk() {} 727 DiskMountManager::Disk::~Disk() {}
725 728
726 bool DiskMountManager::AddDiskForTest(std::unique_ptr<Disk> disk) { 729 bool DiskMountManager::AddDiskForTest(std::unique_ptr<Disk> disk) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 VLOG(1) << "DiskMountManager Shutdown completed"; 797 VLOG(1) << "DiskMountManager Shutdown completed";
795 } 798 }
796 799
797 // static 800 // static
798 DiskMountManager* DiskMountManager::GetInstance() { 801 DiskMountManager* DiskMountManager::GetInstance() {
799 return g_disk_mount_manager; 802 return g_disk_mount_manager;
800 } 803 }
801 804
802 } // namespace disks 805 } // namespace disks
803 } // namespace chromeos 806 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/disks/disk_mount_manager.h ('k') | chromeos/disks/disk_mount_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698