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
|
/*
* Copyright (C) 2009 Karel Zak <kzak@redhat.com>
*
* This file may be redistributed under the terms of the
* GNU Lesser General Public License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <blkid.h>
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
int main(int argc, char *argv[])
{
int fd, rc;
char *devname;
blkid_probe pr;
blkid_topology tp;
if (argc < 2) {
fprintf(stderr, "usage: %s <device> "
"-- prints topology details about the device\n",
program_invocation_short_name);
return EXIT_FAILURE;
}
devname = argv[1];
fd = open(devname, O_RDONLY);
if (fd < 0)
err(EXIT_FAILURE, "%s: open() failed", devname);
pr = blkid_new_probe();
if (!pr)
err(EXIT_FAILURE, "faild to allocate a new libblkid probe");
if (blkid_probe_set_device(pr, fd, 0, 0) != 0)
err(EXIT_FAILURE, "failed to assign device to libblkid probe");
/*
* Binary interface
*/
tp = blkid_probe_get_topology(pr);
if (tp) {
printf("----- binary interface:\n");
printf("\talignment offset : %lu\n",
blkid_topology_get_alignment_offset(tp));
printf("\tminimum io size : %lu\n",
blkid_topology_get_minimum_io_size(tp));
printf("\toptimal io size : %lu\n",
blkid_topology_get_optimal_io_size(tp));
}
/*
* NAME=value interface
*/
/* enable topology probing */
blkid_probe_enable_topology(pr, TRUE);
/* disable superblocks probing (enabled by default) */
blkid_probe_enable_superblocks(pr, FALSE);
rc = blkid_do_fullprobe(pr);
if (rc == -1)
errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname);
else if (rc == 1)
warnx("%s: missing topology information", devname);
else {
int i, nvals = blkid_probe_numof_values(pr);
printf("----- NAME=value interface (values: %d):\n", nvals);
for (i = 0; i < nvals; i++) {
const char *name, *data;
blkid_probe_get_value(pr, i, &name, &data, NULL);
printf("\t%s = %s\n", name, data);
}
}
return EXIT_SUCCESS;
}
|