blob: f610b8675d522204404e294faa04f83510458651 [file] [log] [blame]
Ben Chance7ee542011-04-12 17:02:49 -07001// 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
3// found in the LICENSE file.
4
5#ifndef CHOS_DISKS_UDEV_DEVICE_H_
6#define CROS_DISKS_UDEV_DEVICE_H_
7
8#include <base/basictypes.h>
9#include <iostream>
10#include <string>
11#include <vector>
12
13#include "disk.h"
14
15struct udev_device;
16
17namespace cros_disks {
18
19// A utility class that helps query information about a udev device.
20class UdevDevice {
21 public:
22
23 explicit UdevDevice(struct udev_device *dev);
24 ~UdevDevice();
25
26 // Gets the string value of a device attribute.
27 std::string GetAttribute(const char *key) const;
28
29 // Checks if the value of a device attribute represents a Boolean true.
30 bool IsAttributeTrue(const char *key) const;
31
32 // Checks if a device attribute exists.
33 bool HasAttribute(const char *key) const;
34
35 // Gets the string value of a device property.
36 std::string GetProperty(const char *key) const;
37
38 // Checks if the value of a device property represents a Boolean true.
39 bool IsPropertyTrue(const char *key) const;
40
41 // Checks if a device property exists.
42 bool HasProperty(const char *key) const;
43
44 // Gets the total and remaining capacity of the device.
45 void GetSizeInfo(uint64 *total_size, uint64 *remaining_size) const;
46
47 // Checks if any media is available in the device.
48 bool IsMediaAvailable() const;
49
Ben Chanf51ff002011-04-25 12:41:57 -070050 // Gets the mount paths for the device.
51 std::vector<std::string> GetMountPaths() const;
Ben Chance7ee542011-04-12 17:02:49 -070052
Ben Chanf51ff002011-04-25 12:41:57 -070053 // Gets the mount paths for a given device path.
54 static std::vector<std::string> GetMountPaths(
55 const std::string& device_path);
56
57 // Gets the mount paths for an input stream that has the
Ben Chance7ee542011-04-12 17:02:49 -070058 // same format as /proc/mounts
Ben Chanf51ff002011-04-25 12:41:57 -070059 static std::vector<std::string> ParseMountPaths(
Ben Chance7ee542011-04-12 17:02:49 -070060 const std::string& device_path, std::istream& stream);
61
62 // Returns a Disk object based on the device information.
63 Disk ToDisk() const;
64
65 private:
66
67 bool IsValueBooleanTrue(const char *value) const;
68
69 mutable struct udev_device *dev_;
70};
71
72} // namespace cros_disks
73
74#endif // CROS_DISKS_UDEV_DEVICE_H_