~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to shlibs/blkid/samples/topology.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
3
 
 *
4
 
 * This file may be redistributed under the terms of the
5
 
 * GNU Lesser General Public License.
6
 
 */
7
 
 
8
 
#include <stdio.h>
9
 
#include <stdlib.h>
10
 
#include <sys/types.h>
11
 
#include <sys/stat.h>
12
 
#include <fcntl.h>
13
 
#include <err.h>
14
 
#include <errno.h>
15
 
 
16
 
#include <blkid.h>
17
 
 
18
 
#include "c.h"
19
 
 
20
 
int main(int argc, char *argv[])
21
 
{
22
 
        int rc;
23
 
        char *devname;
24
 
        blkid_probe pr;
25
 
        blkid_topology tp;
26
 
 
27
 
        if (argc < 2) {
28
 
                fprintf(stderr, "usage: %s <device>  "
29
 
                                "-- prints topology details about the device\n",
30
 
                                program_invocation_short_name);
31
 
                return EXIT_FAILURE;
32
 
        }
33
 
 
34
 
        devname = argv[1];
35
 
        pr = blkid_new_probe_from_filename(devname);
36
 
        if (!pr)
37
 
                err(EXIT_FAILURE, "%s: faild to create a new libblkid probe",
38
 
                                devname);
39
 
        /*
40
 
         * Binary interface
41
 
         */
42
 
        tp = blkid_probe_get_topology(pr);
43
 
        if (tp) {
44
 
                printf("----- binary interface:\n");
45
 
                printf("\talignment offset     : %lu\n",
46
 
                                blkid_topology_get_alignment_offset(tp));
47
 
                printf("\tminimum io size      : %lu\n",
48
 
                                blkid_topology_get_minimum_io_size(tp));
49
 
                printf("\toptimal io size      : %lu\n",
50
 
                                blkid_topology_get_optimal_io_size(tp));
51
 
                printf("\tlogical sector size  : %lu\n",
52
 
                                blkid_topology_get_logical_sector_size(tp));
53
 
                printf("\tphysical sector size : %lu\n",
54
 
                                blkid_topology_get_physical_sector_size(tp));
55
 
        }
56
 
 
57
 
        /*
58
 
         * NAME=value interface
59
 
         */
60
 
 
61
 
        /* enable topology probing */
62
 
        blkid_probe_enable_topology(pr, TRUE);
63
 
 
64
 
        /* disable superblocks probing (enabled by default) */
65
 
        blkid_probe_enable_superblocks(pr, FALSE);
66
 
 
67
 
        rc = blkid_do_fullprobe(pr);
68
 
        if (rc == -1)
69
 
                errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname);
70
 
        else if (rc == 1)
71
 
                warnx("%s: missing topology information", devname);
72
 
        else {
73
 
                int i, nvals = blkid_probe_numof_values(pr);
74
 
 
75
 
                printf("----- NAME=value interface (values: %d):\n", nvals);
76
 
 
77
 
                for (i = 0; i < nvals; i++) {
78
 
                        const char *name, *data;
79
 
 
80
 
                        blkid_probe_get_value(pr, i, &name, &data, NULL);
81
 
                        printf("\t%s = %s\n", name, data);
82
 
                }
83
 
        }
84
 
 
85
 
        blkid_free_probe(pr);
86
 
        return EXIT_SUCCESS;
87
 
}