Horizon::DiskMan::Disk::label(3)

NAME
Horizon::DiskMan::Disk::has_label, Horizon::DiskMan::Disk::label - retrieve labeling information for a disk

SYNOPSIS
#include <diskman/disk.hh>
using Horizon::DiskMan::Disk;
bool
Disk::has_label();
enum Label
Disk::label();

DESCRIPTION
The Disk::has_label() function returns whether a given disk has a label written to it. Note that even if Disk::has_label() returns false, the disk may still have a label. The DiskMan library is not able to detect and read every type of disk label in the wild. For maximal safety, you may wish to read the first few sectors of the disk (and use the Horizon::DiskMan::Disk::has_fs(3) function to determine if a file system is present without a label) before considering the disk empty.

The Disk::label() function returns the type of label present on the disk. Calling this function is only valid if Disk::has_label() returns true.

RETURN VALUES
The Disk::has_label() function returns a boolean which determines whether a given disk has a recognised disk label written to it.

The Disk::label() functions returns a value of type enum Disk::Label, which contains at least the following values:

GPT GUID Partition Table.

MBR Master Boot Record.

APM Apple Partition Map.

Unknown
    Unknown disk label type.

EXAMPLES
The following is a simple utility that prints the label type of every labelled disk present on the system:

    #include <diskman/diskman.hh>
    #include <iostream>
    using Horizon::DiskMan::Disk;
    using Horizon::DiskMan::DiskMan;
    const 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) {
        DiskMan dm;
        auto disks = dm.find_disks(false, false, false);
        for(auto &disk : disks) {
            std::cout << "Disk: " << disk.name() << std::endl;
            std::cout << "Label: " << (disk.has_label() ? label_name(disk.label()) : "No") << std::endl;
            std::cout << std::endl;
        }
        return 0;
    }

SEE ALSO
Horizon::DiskMan::Disk(3), Horizon::DiskMan::DiskMan(3), Horizon::DiskMan::Partition(3).

HISTORY
The DiskMan library first appeared in Horizon 0.9.

AUTHORS
A. Wilcox <awilfox@adelielinux.org>