diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-02-12 14:32:55 -0600 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-02-12 14:32:55 -0600 |
commit | 7cce0e9d14e7e94dd13bda65ebbffc019c38760c (patch) | |
tree | e5c8d701c0788bbee11209230075c75791defb1d /diskman | |
parent | 3e05b6d0691ba0b709e6b41eae90b6b76eb92a7c (diff) | |
download | horizon-7cce0e9d14e7e94dd13bda65ebbffc019c38760c.tar.gz horizon-7cce0e9d14e7e94dd13bda65ebbffc019c38760c.tar.bz2 horizon-7cce0e9d14e7e94dd13bda65ebbffc019c38760c.tar.xz horizon-7cce0e9d14e7e94dd13bda65ebbffc019c38760c.zip |
DiskMan: Add library usage sample
Diffstat (limited to 'diskman')
-rw-r--r-- | diskman/sample.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/diskman/sample.cc b/diskman/sample.cc new file mode 100644 index 0000000..9df17c7 --- /dev/null +++ b/diskman/sample.cc @@ -0,0 +1,31 @@ +#include "diskman/diskman.hh" +#include <iostream> + +using Horizon::DiskMan::Disk; +std::string label_name(Disk::Label label) { switch(label) { case Disk::APM: return "APM"; case Disk::MBR: return "MBR"; case Disk::GPT: return "GPT"; } return "Unknown"; } + +int main(void) { + Horizon::DiskMan::DiskMan diskMan; + auto disks = diskMan.find_disks(true, true, false); + std::cout << "Found " << std::to_string(disks.size()) << " disk(s):" << std::endl; + for(auto &disk : disks) { + std::cout << "==========================================" << std::endl; + std::cout << "Disk: " << disk.name() << " (" << disk.model() << ")"; + std::cout << " at " << disk.dev_path() << std::endl; + std::cout << std::to_string(disk.total_size()) << " MiB total"; + std::cout << " (" << std::to_string(disk.free_space()) << " MiB free; "; + std::cout << std::to_string(disk.contiguous_block()) << " MiB largest contiguous block)" << std::endl; + std::cout << "Label: " << (disk.has_label() ? label_name(disk.label()) : "No") << std::endl; + + if(disk.has_label()) { + std::cout << std::endl << "\tPartitions:" << std::endl; + for(auto &part : disk.partitions()) { + std::cout << "\t\t" << part.size() / 1048576 << " MiB (" << part.fstype(); + if(part.label().size() > 0) std::cout << ": " << part.label(); + std::cout << ")" << std::endl; + } + } + } + std::cout << "==========================================" << std::endl; + return 0; +} |