summaryrefslogtreecommitdiff
path: root/diskman/man/Horizon::DiskMan::Disk::label.3
blob: f15452e7f1ff87c2c31012f122404c7c01788b93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
.Dd May 15, 2020
.Dt Horizon::DiskMan::Disk::label 3
.Os "Adélie Linux"
.Sh NAME
.Nm Horizon::DiskMan::Disk::has_label ,
.Nm Horizon::DiskMan::Disk::label
.Nd retrieve labeling information for a disk
.Sh SYNOPSIS
.In diskman/disk.hh
.Cm using Horizon::DiskMan::Disk;
.Ft bool
.Fo Disk::has_label
.Fc
.Ft enum Label
.Fo Disk::label
.Fc
.Sh DESCRIPTION
The
.Fn Disk::has_label
function returns whether a given disk has a label written to it.  Note that
even if
.Fn 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
.Xr Horizon::DiskMan::Disk::has_fs 3
function to determine if a file system is present without a label) before
considering the disk empty.
.Pp
The
.Fn Disk::label
function returns the type of label present on the disk.  Calling this
function is only valid if
.Fn Disk::has_label
returns true.
.Sh RETURN VALUES
The
.Fn Disk::has_label
function returns a boolean which determines whether a given disk has a
recognised disk label written to it.
.Pp
The
.Fn Disk::label
functions returns a value of type enum Disk::Label, which contains at least
the following values:
.Bl -tag -width Ds
.It GPT
GUID Partition Table.
.It MBR
Master Boot Record.
.It APM
Apple Partition Map.
.It Unknown
Unknown disk label type.
.El
.Sh EXAMPLES
The following is a simple utility that prints the label type of every
labelled disk present on the system:
.Bd -literal -offset ident
#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;
}
.Ed
.Sh SEE ALSO
.Xr Horizon::DiskMan::Disk 3 ,
.Xr Horizon::DiskMan::DiskMan 3 ,
.Xr Horizon::DiskMan::Partition 3 .
.Sh HISTORY
The DiskMan library first appeared in Horizon 0.9.
.Sh AUTHORS
.An A. Wilcox
.Aq awilfox@adelielinux.org