diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-05-22 08:07:16 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-05-22 08:07:16 -0500 |
commit | a9b35213d330faa3fc551c9a8c3524d519d8466b (patch) | |
tree | 15272832efd7f1e5615f4fe755dddd7be2a9999d /diskman | |
parent | 8fa9807ef3ac66ec5f47a804c7b3819dc59f7ab7 (diff) | |
download | horizon-a9b35213d330faa3fc551c9a8c3524d519d8466b.tar.gz horizon-a9b35213d330faa3fc551c9a8c3524d519d8466b.tar.bz2 horizon-a9b35213d330faa3fc551c9a8c3524d519d8466b.tar.xz horizon-a9b35213d330faa3fc551c9a8c3524d519d8466b.zip |
DiskMan: Add Partition::node method
Diffstat (limited to 'diskman')
-rw-r--r-- | diskman/man/Horizon::DiskMan::Partition.3 | 10 | ||||
-rw-r--r-- | diskman/partition.cc | 3 | ||||
-rw-r--r-- | diskman/partition.hh | 4 |
3 files changed, 16 insertions, 1 deletions
diff --git a/diskman/man/Horizon::DiskMan::Partition.3 b/diskman/man/Horizon::DiskMan::Partition.3 index 78d3748..99d1915 100644 --- a/diskman/man/Horizon::DiskMan::Partition.3 +++ b/diskman/man/Horizon::DiskMan::Partition.3 @@ -11,6 +11,9 @@ .Fo Partition::size .Fc .Ft const std::string +.Fo Partition::node +.Fc +.Ft const std::string .Fo Partition::fs_type .Fc .Ft const std::string @@ -26,6 +29,10 @@ The function provides the size of the partition. .Pp The +.Fn Partition::node +function provides the device node of the partition. +.Pp +The .Fn Partition::fs_type and .Fn Partition::fs_label @@ -37,7 +44,8 @@ The function returns the size of the partition in bytes. .Pp The -.Fn Partition::fs_type +.Fn Partition::node , +.Fn Partition::fs_type , and .Fn Partition::fs_label functions return the requested information as std::string. diff --git a/diskman/partition.cc b/diskman/partition.cc index 9aa5d22..323cd30 100644 --- a/diskman/partition.cc +++ b/diskman/partition.cc @@ -33,6 +33,7 @@ Partition::Partition(Disk &d, void *creation, int type) { } char *name = fdisk_partname(d.node().c_str(), fdisk_partition_get_partno(part) + 1); + this->_node = std::string(name); char *value; value = blkid_get_tag_value(nullptr, "TYPE", name); if(value != nullptr) { @@ -56,6 +57,8 @@ Partition::Partition(Disk &d, void *creation, int type) { if(value != nullptr) this->_label = std::string(value); value = udev_device_get_property_value(dev, "ID_PART_ENTRY_SIZE"); if(value != nullptr) this->_size = strtoull(value, nullptr, 10) * 512; + value = udev_device_get_property_value(dev, "DEVNAME"); + if(value != nullptr) this->_node = std::string(value); break; } default: diff --git a/diskman/partition.hh b/diskman/partition.hh index 93090d8..8e6274b 100644 --- a/diskman/partition.hh +++ b/diskman/partition.hh @@ -29,6 +29,8 @@ public: const std::string fstype() const { return this->_fs_type; } /*! Retrieve the label of the file system on this partition. */ const std::string label() const { return this->_label; } + /*! Retrieve the device node of this partition (for example, /dev/sda1). */ + const std::string node() const { return this->_node; } private: /*! The size of the partition, in bytes. */ uint64_t _size; @@ -36,6 +38,8 @@ private: std::string _fs_type; /*! The label of the file system on this partition (if any) */ std::string _label; + /*! The device node of this partition. */ + std::string _node; Partition(Disk &d, void *creation, int type); friend class Disk; }; |