#include "components/storage_monitor/storage_monitor_linux.h"
#include <mntent.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
#include <limits>
#include <list>
#include <memory>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/not_fatal_until.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "components/storage_monitor/media_storage_util.h"
#include "components/storage_monitor/removable_device_constants.h"
#include "components/storage_monitor/storage_info.h"
#include "components/storage_monitor/udev_util_linux.h"
#include "device/udev_linux/scoped_udev.h"
namespace storage_monitor {
MountPointDeviceMap;
namespace {
const char kBlockSubsystemKey[] = …;
const char kDiskDeviceTypeKey[] = …;
const char kFsUUID[] = …;
const char kLabel[] = …;
const char kModel[] = …;
const char kModelID[] = …;
const char kRemovableSysAttr[] = …;
const char kSerialShort[] = …;
const char kSizeSysAttr[] = …;
const char kVendor[] = …;
const char kVendorID[] = …;
std::string MakeDeviceUniqueId(struct udev_device* device) { … }
uint64_t GetDeviceStorageSize(const base::FilePath& device_path,
struct udev_device* device) { … }
std::unique_ptr<StorageInfo> GetDeviceInfo(const base::FilePath& device_path,
const base::FilePath& mount_point) { … }
void BounceMtabUpdateToStorageMonitorTaskRunner(
scoped_refptr<base::SequencedTaskRunner> storage_monitor_task_runner,
const MtabWatcherLinux::UpdateMtabCallback& callback,
const MtabWatcherLinux::MountPointDeviceMap& new_mtab) { … }
std::unique_ptr<MtabWatcherLinux> CreateMtabWatcherLinuxOnMtabWatcherTaskRunner(
const base::FilePath& mtab_path,
scoped_refptr<base::SequencedTaskRunner> storage_monitor_task_runner,
const MtabWatcherLinux::UpdateMtabCallback& callback) { … }
StorageMonitor::EjectStatus EjectPathOnBlockingTaskRunner(
const base::FilePath& path,
const base::FilePath& device) { … }
}
StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path)
: … { … }
StorageMonitorLinux::~StorageMonitorLinux() { … }
void StorageMonitorLinux::Init() { … }
bool StorageMonitorLinux::GetStorageInfoForPath(
const base::FilePath& path,
StorageInfo* device_info) const { … }
void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest(
const GetDeviceInfoCallback& get_device_info_callback) { … }
void StorageMonitorLinux::EjectDevice(
const std::string& device_id,
base::OnceCallback<void(EjectStatus)> callback) { … }
void StorageMonitorLinux::OnMtabWatcherCreated(
std::unique_ptr<MtabWatcherLinux> watcher) { … }
void StorageMonitorLinux::UpdateMtab(const MountPointDeviceMap& new_mtab) { … }
bool StorageMonitorLinux::IsDeviceAlreadyMounted(
const base::FilePath& mount_device) const { … }
void StorageMonitorLinux::HandleDeviceMountedMultipleTimes(
const base::FilePath& mount_device,
const base::FilePath& mount_point) { … }
void StorageMonitorLinux::AddNewMount(
const base::FilePath& mount_device,
std::unique_ptr<StorageInfo> storage_info) { … }
StorageMonitor* StorageMonitor::CreateInternal() { … }
}