bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 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 <errno.h> |
| 14 | |
| 15 | #include <blkid.h> |
| 16 | |
| 17 | #include "c.h" |
| 18 | |
| 19 | int main(int argc, char *argv[]) |
| 20 | { |
| 21 | int rc; |
| 22 | char *devname; |
| 23 | blkid_probe pr; |
| 24 | blkid_topology tp; |
| 25 | |
| 26 | if (argc < 2) { |
| 27 | fprintf(stderr, "usage: %s <device> " |
| 28 | "-- prints topology details about the device\n", |
| 29 | program_invocation_short_name); |
| 30 | return EXIT_FAILURE; |
| 31 | } |
| 32 | |
| 33 | devname = argv[1]; |
| 34 | pr = blkid_new_probe_from_filename(devname); |
| 35 | if (!pr) |
| 36 | err(EXIT_FAILURE, "%s: faild to create a new libblkid probe", |
| 37 | devname); |
| 38 | /* |
| 39 | * Binary interface |
| 40 | */ |
| 41 | tp = blkid_probe_get_topology(pr); |
| 42 | if (tp) { |
| 43 | printf("----- binary interface:\n"); |
| 44 | printf("\talignment offset : %lu\n", |
| 45 | blkid_topology_get_alignment_offset(tp)); |
| 46 | printf("\tminimum io size : %lu\n", |
| 47 | blkid_topology_get_minimum_io_size(tp)); |
| 48 | printf("\toptimal io size : %lu\n", |
| 49 | blkid_topology_get_optimal_io_size(tp)); |
| 50 | printf("\tlogical sector size : %lu\n", |
| 51 | blkid_topology_get_logical_sector_size(tp)); |
| 52 | printf("\tphysical sector size : %lu\n", |
| 53 | blkid_topology_get_physical_sector_size(tp)); |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * NAME=value interface |
| 58 | */ |
| 59 | |
| 60 | /* enable topology probing */ |
| 61 | blkid_probe_enable_topology(pr, TRUE); |
| 62 | |
| 63 | /* disable superblocks probing (enabled by default) */ |
| 64 | blkid_probe_enable_superblocks(pr, FALSE); |
| 65 | |
| 66 | rc = blkid_do_fullprobe(pr); |
| 67 | if (rc == -1) |
| 68 | errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname); |
| 69 | else if (rc == 1) |
| 70 | warnx("%s: missing topology information", devname); |
| 71 | else { |
| 72 | int i, nvals = blkid_probe_numof_values(pr); |
| 73 | |
| 74 | printf("----- NAME=value interface (values: %d):\n", nvals); |
| 75 | |
| 76 | for (i = 0; i < nvals; i++) { |
| 77 | const char *name, *data; |
| 78 | |
| 79 | blkid_probe_get_value(pr, i, &name, &data, NULL); |
| 80 | printf("\t%s = %s\n", name, data); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | blkid_free_probe(pr); |
| 85 | return EXIT_SUCCESS; |
| 86 | } |