blob: 5c3ebe79e47042694988eec96ee23ce1932ba3bf [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
17#include "c.h"
18
19int 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 "-- checks based on libblkid for mkfs-like programs.\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 /*
40 * check Filesystems / Partitions overwrite
41 */
42
43 /* enable partitions probing (superblocks are enabled by default) */
44 blkid_probe_enable_partitions(pr, TRUE);
45
46 rc = blkid_do_fullprobe(pr);
47 if (rc == -1)
48 errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname);
49 else if (rc == 0) {
50 const char *type;
51
52 if (!blkid_probe_lookup_value(pr, "TYPE", &type, NULL))
53 errx(EXIT_FAILURE, "%s: appears to contain an existing "
54 "%s superblock", devname, type);
55
56 if (!blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL))
57 errx(EXIT_FAILURE, "%s: appears to contain an partition "
58 "table (%s)", devname, type);
59 }
60
61 /*
62 * get topology details
63 */
64 tp = blkid_probe_get_topology(pr);
65 if (!tp)
66 errx(EXIT_FAILURE, "%s: failed to read topology", devname);
67
68
69 /* ... your mkfs.<type> code or so ...
70
71 off = blkid_topology_get_alignment_offset(tp);
72
73 */
74
75 blkid_free_probe(pr);
76
77 return EXIT_SUCCESS;
78}