2 * Copyright (C) 2016 Jo-Philipp Wich <jo@mein.io>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
17 #include <blkid/blkid.h>
18 #include <libubox/utils.h>
25 blkid_probe (*alloc
)(const char *);
26 int (*probe
)(blkid_probe
);
27 int (*lookup
)(blkid_probe
, const char *, const char **, size_t *);
28 void (*free
)(blkid_probe
);
37 if (!libblkid
.loaded
) {
38 lib
= dlopen("libblkid.so", RTLD_GLOBAL
);
41 lib
= dlopen("libblkid.so.1", RTLD_GLOBAL
);
44 libblkid
.alloc
= dlsym(lib
, "blkid_new_probe_from_filename");
45 libblkid
.probe
= dlsym(lib
, "blkid_do_probe");
46 libblkid
.lookup
= dlsym(lib
, "blkid_probe_lookup_value");
47 libblkid
.free
= dlsym(lib
, "blkid_free_probe");
50 libblkid
.loaded
= true;
53 return (libblkid
.alloc
&& libblkid
.probe
&& libblkid
.lookup
&& libblkid
.free
);
57 probe_path_libblkid(const char *path
)
60 struct probe_info
*info
= NULL
;
61 size_t type_len
, uuid_len
, label_len
, version_len
;
62 char *dev_ptr
, *type_ptr
, *uuid_ptr
, *label_ptr
, *version_ptr
;
63 const char *type_val
, *uuid_val
, *label_val
, *version_val
;
68 pr
= libblkid
.alloc(path
);
73 if (libblkid
.probe(pr
) == 0) {
74 if (libblkid
.lookup(pr
, "TYPE", &type_val
, &type_len
))
77 if (libblkid
.lookup(pr
, "UUID", &uuid_val
, &uuid_len
))
80 if (libblkid
.lookup(pr
, "LABEL", &label_val
, &label_len
))
83 if (libblkid
.lookup(pr
, "VERSION", &version_val
, &version_len
))
87 info
= calloc_a(sizeof(*info
),
88 &dev_ptr
, strlen(path
) + 1,
91 &label_ptr
, label_len
,
92 &version_ptr
, version_len
);
95 info
->dev
= strcpy(dev_ptr
, path
);
96 info
->type
= strcpy(type_ptr
, type_val
);
99 info
->uuid
= strcpy(uuid_ptr
, uuid_val
);
102 info
->label
= strcpy(label_ptr
, label_val
);
105 info
->version
= strcpy(version_ptr
, version_val
);