blob: fe0ad4827d444b544d7a2acec1e3d72f5c84caa4 [file] [log] [blame]
bigbiff7b4c7a62015-01-01 19:44:14 -05001/*
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#include "c.h"
17
18int main(int argc, char *argv[])
19{
20 int i, nparts;
21 char *devname;
22 blkid_probe pr;
23 blkid_partlist ls;
24 blkid_parttable root_tab;
25
26 if (argc < 2) {
27 fprintf(stderr, "usage: %s <device|file> "
28 "-- prints partitions\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 /* Binary interface */
39 ls = blkid_probe_get_partitions(pr);
40 if (!ls)
41 errx(EXIT_FAILURE, "%s: failed to read partitions\n", devname);
42
43 /*
44 * Print info about the primary (root) partition table
45 */
46 root_tab = blkid_partlist_get_table(ls);
47 if (!root_tab)
48 errx(EXIT_FAILURE, "%s: does not contains any "
49 "known partition table\n", devname);
50
51 printf("size: %jd, sector size: %u, PT: %s, offset: %jd, id=%s\n---\n",
52 blkid_probe_get_size(pr),
53 blkid_probe_get_sectorsize(pr),
54 blkid_parttable_get_type(root_tab),
55 blkid_parttable_get_offset(root_tab),
56 blkid_parttable_get_id(root_tab));
57
58 /*
59 * List partitions
60 */
61 nparts = blkid_partlist_numof_partitions(ls);
62 if (!nparts)
63 goto done;
64
65 for (i = 0; i < nparts; i++) {
66 const char *p;
67 blkid_partition par = blkid_partlist_get_partition(ls, i);
68 blkid_parttable tab = blkid_partition_get_table(par);
69
70 printf("#%d: %10llu %10llu 0x%x",
71 blkid_partition_get_partno(par),
72 (unsigned long long) blkid_partition_get_start(par),
73 (unsigned long long) blkid_partition_get_size(par),
74 blkid_partition_get_type(par));
75
76 if (root_tab != tab)
77 /* subpartition (BSD, Minix, ...) */
78 printf(" (%s)", blkid_parttable_get_type(tab));
79
80 p = blkid_partition_get_name(par);
81 if (p)
82 printf(" name='%s'", p);
83 p = blkid_partition_get_uuid(par);
84 if (p)
85 printf(" uuid='%s'", p);
86 p = blkid_partition_get_type_string(par);
87 if (p)
88 printf(" type='%s'", p);
89
90 putc('\n', stdout);
91 }
92
93done:
94 blkid_free_probe(pr);
95 return EXIT_SUCCESS;
96}