Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / components / storage_monitor / udev_util_linux.cc
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/storage_monitor/udev_util_linux.h"
6
7 #include "base/files/file_path.h"
8
9 void UdevDeleter::operator()(struct udev* udev) {
10   udev_unref(udev);
11 }
12
13 void UdevDeviceDeleter::operator()(struct udev_device* device) {
14   udev_device_unref(device);
15 }
16
17 std::string GetUdevDevicePropertyValue(struct udev_device* udev_device,
18                                        const char* key) {
19   const char* value = udev_device_get_property_value(udev_device, key);
20   return value ? value : std::string();
21 }
22
23 bool GetUdevDevicePropertyValueByPath(const base::FilePath& device_path,
24                                       const char* key,
25                                       std::string* result) {
26   ScopedUdevObject udev(udev_new());
27   if (!udev.get())
28     return false;
29   ScopedUdevDeviceObject device(udev_device_new_from_syspath(
30       udev.get(), device_path.value().c_str()));
31   if (!device.get())
32     return false;
33   *result = GetUdevDevicePropertyValue(device.get(), key);
34   return true;
35 }