libblkid: turn into dlopen() based dep
This commit is contained in:
+91
-3
@@ -1,17 +1,105 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#if HAVE_BLKID
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "blkid-util.h"
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
|
||||
#if HAVE_BLKID
|
||||
static void *libblkid_dl = NULL;
|
||||
|
||||
DLSYM_PROTOTYPE(blkid_do_fullprobe) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_do_probe) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_do_safeprobe) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_do_wipe) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_encode_string) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_free_probe) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_new_probe) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_new_probe_from_filename) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_flags) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_name) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_partno) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_size) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_start) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_type) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_type_string) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partition_get_uuid) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partlist_devno_to_partition) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partlist_get_partition) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_partlist_numof_partitions) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_enable_partitions) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_enable_superblocks) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_filter_superblocks_type) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_filter_superblocks_usage) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_get_fd) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_get_partitions) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_get_size) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_get_value) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_is_wholedisk) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_lookup_value) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_numof_values) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_set_device) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_set_hint) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_set_partitions_flags) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_set_sectorsize) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_probe_set_superblocks_flags) = NULL;
|
||||
DLSYM_PROTOTYPE(blkid_safe_string) = NULL;
|
||||
|
||||
int dlopen_libblkid(void) {
|
||||
ELF_NOTE_DLOPEN("blkid",
|
||||
"Support for block device identification",
|
||||
ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
|
||||
"libblkid.so.1");
|
||||
|
||||
return dlopen_many_sym_or_warn(
|
||||
&libblkid_dl,
|
||||
"libblkid.so.1",
|
||||
LOG_DEBUG,
|
||||
DLSYM_ARG(blkid_do_fullprobe),
|
||||
DLSYM_ARG(blkid_do_probe),
|
||||
DLSYM_ARG(blkid_do_safeprobe),
|
||||
DLSYM_ARG(blkid_do_wipe),
|
||||
DLSYM_ARG(blkid_encode_string),
|
||||
DLSYM_ARG(blkid_free_probe),
|
||||
DLSYM_ARG(blkid_new_probe),
|
||||
DLSYM_ARG(blkid_new_probe_from_filename),
|
||||
DLSYM_ARG(blkid_partition_get_flags),
|
||||
DLSYM_ARG(blkid_partition_get_name),
|
||||
DLSYM_ARG(blkid_partition_get_partno),
|
||||
DLSYM_ARG(blkid_partition_get_size),
|
||||
DLSYM_ARG(blkid_partition_get_start),
|
||||
DLSYM_ARG(blkid_partition_get_type),
|
||||
DLSYM_ARG(blkid_partition_get_type_string),
|
||||
DLSYM_ARG(blkid_partition_get_uuid),
|
||||
DLSYM_ARG(blkid_partlist_devno_to_partition),
|
||||
DLSYM_ARG(blkid_partlist_get_partition),
|
||||
DLSYM_ARG(blkid_partlist_numof_partitions),
|
||||
DLSYM_ARG(blkid_probe_enable_partitions),
|
||||
DLSYM_ARG(blkid_probe_enable_superblocks),
|
||||
DLSYM_ARG(blkid_probe_filter_superblocks_type),
|
||||
DLSYM_ARG(blkid_probe_filter_superblocks_usage),
|
||||
DLSYM_ARG(blkid_probe_get_fd),
|
||||
DLSYM_ARG(blkid_probe_get_partitions),
|
||||
DLSYM_ARG(blkid_probe_get_size),
|
||||
DLSYM_ARG(blkid_probe_get_value),
|
||||
DLSYM_ARG(blkid_probe_is_wholedisk),
|
||||
DLSYM_ARG(blkid_probe_lookup_value),
|
||||
DLSYM_ARG(blkid_probe_numof_values),
|
||||
DLSYM_ARG(blkid_probe_set_device),
|
||||
DLSYM_ARG(blkid_probe_set_hint),
|
||||
DLSYM_ARG(blkid_probe_set_partitions_flags),
|
||||
DLSYM_ARG(blkid_probe_set_sectorsize),
|
||||
DLSYM_ARG(blkid_probe_set_superblocks_flags),
|
||||
DLSYM_ARG(blkid_safe_string));
|
||||
}
|
||||
|
||||
int blkid_partition_get_uuid_id128(blkid_partition p, sd_id128_t *ret) {
|
||||
const char *s;
|
||||
|
||||
assert(p);
|
||||
|
||||
s = blkid_partition_get_uuid(p);
|
||||
s = sym_blkid_partition_get_uuid(p);
|
||||
if (isempty(s))
|
||||
return -ENXIO;
|
||||
|
||||
@@ -23,7 +111,7 @@ int blkid_partition_get_type_id128(blkid_partition p, sd_id128_t *ret) {
|
||||
|
||||
assert(p);
|
||||
|
||||
s = blkid_partition_get_type_string(p);
|
||||
s = sym_blkid_partition_get_type_string(p);
|
||||
if (isempty(s))
|
||||
return -ENXIO;
|
||||
|
||||
|
||||
+47
-2
@@ -1,13 +1,54 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "forward.h"
|
||||
|
||||
#if HAVE_BLKID
|
||||
|
||||
#include <blkid.h>
|
||||
|
||||
#include "forward.h"
|
||||
#include "dlfcn-util.h"
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(blkid_probe, blkid_free_probe, NULL);
|
||||
extern DLSYM_PROTOTYPE(blkid_do_fullprobe);
|
||||
extern DLSYM_PROTOTYPE(blkid_do_probe);
|
||||
extern DLSYM_PROTOTYPE(blkid_do_safeprobe);
|
||||
extern DLSYM_PROTOTYPE(blkid_do_wipe);
|
||||
extern DLSYM_PROTOTYPE(blkid_encode_string);
|
||||
extern DLSYM_PROTOTYPE(blkid_free_probe);
|
||||
extern DLSYM_PROTOTYPE(blkid_new_probe);
|
||||
extern DLSYM_PROTOTYPE(blkid_new_probe_from_filename);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_flags);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_name);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_partno);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_size);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_start);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_type);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_type_string);
|
||||
extern DLSYM_PROTOTYPE(blkid_partition_get_uuid);
|
||||
extern DLSYM_PROTOTYPE(blkid_partlist_devno_to_partition);
|
||||
extern DLSYM_PROTOTYPE(blkid_partlist_get_partition);
|
||||
extern DLSYM_PROTOTYPE(blkid_partlist_numof_partitions);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_enable_partitions);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_enable_superblocks);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_filter_superblocks_type);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_filter_superblocks_usage);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_get_fd);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_get_partitions);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_get_size);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_get_value);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_is_wholedisk);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_lookup_value);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_numof_values);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_set_device);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_set_hint);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_set_partitions_flags);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_set_sectorsize);
|
||||
extern DLSYM_PROTOTYPE(blkid_probe_set_superblocks_flags);
|
||||
extern DLSYM_PROTOTYPE(blkid_safe_string);
|
||||
|
||||
int dlopen_libblkid(void);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(blkid_probe, sym_blkid_free_probe, blkid_free_probep, NULL);
|
||||
|
||||
int blkid_partition_get_uuid_id128(blkid_partition p, sd_id128_t *ret);
|
||||
|
||||
@@ -22,4 +63,8 @@ enum {
|
||||
_BLKID_SAFEPROBE_ERROR = -1,
|
||||
};
|
||||
|
||||
#else
|
||||
static inline int dlopen_libblkid(void) {
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
#endif
|
||||
|
||||
+38
-31
@@ -199,12 +199,12 @@ static int probe_blkid_filter(blkid_probe p) {
|
||||
return r;
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_filter_superblocks_type(p, BLKID_FLTR_ONLYIN, fstypes);
|
||||
r = sym_blkid_probe_filter_superblocks_type(p, BLKID_FLTR_ONLYIN, fstypes);
|
||||
if (r != 0)
|
||||
return errno_or_else(EINVAL);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_filter_superblocks_usage(p, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);
|
||||
r = sym_blkid_probe_filter_superblocks_usage(p, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);
|
||||
if (r != 0)
|
||||
return errno_or_else(EINVAL);
|
||||
|
||||
@@ -234,6 +234,10 @@ int probe_filesystem_full(
|
||||
assert(fd >= 0 || path);
|
||||
assert(ret_fstype);
|
||||
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (fd < 0) {
|
||||
fd_close = open(path, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
|
||||
if (fd_close < 0)
|
||||
@@ -253,7 +257,7 @@ int probe_filesystem_full(
|
||||
if (size == 0) /* empty size? nothing found! */
|
||||
goto not_found;
|
||||
|
||||
b = blkid_new_probe();
|
||||
b = sym_blkid_new_probe();
|
||||
if (!b)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -279,7 +283,7 @@ int probe_filesystem_full(
|
||||
log_debug_errno(errno, "Failed to flush block device cache, ignoring: %m");
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_set_device(
|
||||
r = sym_blkid_probe_set_device(
|
||||
b,
|
||||
fd,
|
||||
offset,
|
||||
@@ -287,11 +291,11 @@ int probe_filesystem_full(
|
||||
if (r != 0)
|
||||
return errno_or_else(ENOMEM);
|
||||
|
||||
blkid_probe_enable_superblocks(b, 1);
|
||||
blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
|
||||
sym_blkid_probe_enable_superblocks(b, 1);
|
||||
sym_blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
r = sym_blkid_do_safeprobe(b);
|
||||
if (r == _BLKID_SAFEPROBE_NOT_FOUND)
|
||||
goto not_found;
|
||||
if (r == _BLKID_SAFEPROBE_AMBIGUOUS)
|
||||
@@ -302,8 +306,7 @@ int probe_filesystem_full(
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
|
||||
|
||||
(void) sym_blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
|
||||
if (fstype) {
|
||||
log_debug("Probed fstype '%s' on partition %s.", fstype, path);
|
||||
return strdup_to_full(ret_fstype, fstype);
|
||||
@@ -789,7 +792,11 @@ static int dissect_image(
|
||||
}
|
||||
}
|
||||
|
||||
b = blkid_new_probe();
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
b = sym_blkid_new_probe();
|
||||
if (!b)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -798,26 +805,26 @@ static int dissect_image(
|
||||
return r;
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_set_device(b, fd, 0, 0);
|
||||
r = sym_blkid_probe_set_device(b, fd, 0, 0);
|
||||
if (r != 0)
|
||||
return errno_or_else(ENOMEM);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_set_sectorsize(b, m->sector_size);
|
||||
r = sym_blkid_probe_set_sectorsize(b, m->sector_size);
|
||||
if (r != 0)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
if ((flags & DISSECT_IMAGE_GPT_ONLY) == 0) {
|
||||
/* Look for file system superblocks, unless we only shall look for GPT partition tables */
|
||||
blkid_probe_enable_superblocks(b, 1);
|
||||
blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|BLKID_SUBLKS_USAGE|BLKID_SUBLKS_UUID);
|
||||
sym_blkid_probe_enable_superblocks(b, 1);
|
||||
sym_blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|BLKID_SUBLKS_USAGE|BLKID_SUBLKS_UUID);
|
||||
}
|
||||
|
||||
blkid_probe_enable_partitions(b, 1);
|
||||
blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
sym_blkid_probe_enable_partitions(b, 1);
|
||||
sym_blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
r = sym_blkid_do_safeprobe(b);
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return errno_or_else(EIO);
|
||||
if (IN_SET(r, _BLKID_SAFEPROBE_AMBIGUOUS, _BLKID_SAFEPROBE_NOT_FOUND))
|
||||
@@ -832,7 +839,7 @@ static int dissect_image(
|
||||
|
||||
/* If flags permit this, also allow using non-partitioned single-filesystem images */
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "USAGE", &usage, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "USAGE", &usage, NULL);
|
||||
if (STRPTR_IN_SET(usage, "filesystem", "crypto")) {
|
||||
_cleanup_free_ char *t = NULL, *n = NULL, *o = NULL;
|
||||
const char *fstype = NULL, *options = NULL, *suuid = NULL;
|
||||
@@ -852,8 +859,8 @@ static int dissect_image(
|
||||
if (r == 0) /* policy says ignore this, so we ignore it */
|
||||
return -ENOPKG;
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
|
||||
(void) blkid_probe_lookup_value(b, "UUID", &suuid, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "UUID", &suuid, NULL);
|
||||
|
||||
encrypted = streq_ptr(fstype, "crypto_LUKS");
|
||||
|
||||
@@ -931,7 +938,7 @@ static int dissect_image(
|
||||
}
|
||||
}
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
if (!pttype)
|
||||
return -ENOPKG;
|
||||
|
||||
@@ -955,7 +962,7 @@ static int dissect_image(
|
||||
return -EPROTONOSUPPORT;
|
||||
}
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "PTUUID", &sptuuid, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "PTUUID", &sptuuid, NULL);
|
||||
if (sptuuid) {
|
||||
r = sd_id128_from_string(sptuuid, &m->image_uuid);
|
||||
if (r < 0)
|
||||
@@ -963,12 +970,12 @@ static int dissect_image(
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
pl = blkid_probe_get_partitions(b);
|
||||
pl = sym_blkid_probe_get_partitions(b);
|
||||
if (!pl)
|
||||
return errno_or_else(ENOMEM);
|
||||
|
||||
errno = 0;
|
||||
n_partitions = blkid_partlist_numof_partitions(pl);
|
||||
n_partitions = sym_blkid_partlist_numof_partitions(pl);
|
||||
if (n_partitions < 0)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
@@ -980,26 +987,26 @@ static int dissect_image(
|
||||
int nr;
|
||||
|
||||
errno = 0;
|
||||
pp = blkid_partlist_get_partition(pl, i);
|
||||
pp = sym_blkid_partlist_get_partition(pl, i);
|
||||
if (!pp)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
pflags = blkid_partition_get_flags(pp);
|
||||
pflags = sym_blkid_partition_get_flags(pp);
|
||||
|
||||
errno = 0;
|
||||
nr = blkid_partition_get_partno(pp);
|
||||
nr = sym_blkid_partition_get_partno(pp);
|
||||
if (nr < 0)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
errno = 0;
|
||||
start = blkid_partition_get_start(pp);
|
||||
start = sym_blkid_partition_get_start(pp);
|
||||
if (start < 0)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
assert((uint64_t) start < UINT64_MAX/512);
|
||||
|
||||
errno = 0;
|
||||
size = blkid_partition_get_size(pp);
|
||||
size = sym_blkid_partition_get_size(pp);
|
||||
if (size < 0)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
@@ -1054,7 +1061,7 @@ static int dissect_image(
|
||||
|
||||
type = gpt_partition_type_from_uuid(type_id);
|
||||
|
||||
label = blkid_partition_get_name(pp); /* libblkid returns NULL here if empty */
|
||||
label = sym_blkid_partition_get_name(pp); /* libblkid returns NULL here if empty */
|
||||
|
||||
/* systemd-sysupdate expects empty partitions to be marked with an "_empty" label, hence ignore them here. */
|
||||
if (streq_ptr(label, "_empty"))
|
||||
@@ -1360,7 +1367,7 @@ static int dissect_image(
|
||||
|
||||
} else if (is_mbr) {
|
||||
|
||||
switch (blkid_partition_get_type(pp)) {
|
||||
switch (sym_blkid_partition_get_type(pp)) {
|
||||
|
||||
case 0x83: /* Linux partition */
|
||||
|
||||
|
||||
+29
-21
@@ -76,22 +76,26 @@ static int verify_esp_blkid(
|
||||
const char *v;
|
||||
int r;
|
||||
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "No libblkid support: %m");
|
||||
|
||||
r = devname_from_devnum(S_IFBLK, devid, &node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get device path for " DEVNUM_FORMAT_STR ": %m", DEVNUM_FORMAT_VAL(devid));
|
||||
|
||||
errno = 0;
|
||||
b = blkid_new_probe_from_filename(node);
|
||||
b = sym_blkid_new_probe_from_filename(node);
|
||||
if (!b)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(ENOMEM), "Failed to open file system \"%s\": %m", node);
|
||||
|
||||
blkid_probe_enable_superblocks(b, 1);
|
||||
blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
|
||||
blkid_probe_enable_partitions(b, 1);
|
||||
blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
sym_blkid_probe_enable_superblocks(b, 1);
|
||||
sym_blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
|
||||
sym_blkid_probe_enable_partitions(b, 1);
|
||||
sym_blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
r = sym_blkid_do_safeprobe(b);
|
||||
if (r == -2)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "File system \"%s\" is ambiguous.", node);
|
||||
if (r == 1)
|
||||
@@ -99,7 +103,7 @@ static int verify_esp_blkid(
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe file system \"%s\": %m", node);
|
||||
|
||||
r = blkid_probe_lookup_value(b, "TYPE", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "TYPE", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
|
||||
SYNTHETIC_ERRNO(searching ? EADDRNOTAVAIL : ENODEV),
|
||||
@@ -109,7 +113,7 @@ static int verify_esp_blkid(
|
||||
SYNTHETIC_ERRNO(searching ? EADDRNOTAVAIL : ENODEV),
|
||||
"File system \"%s\" is not FAT.", node);
|
||||
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
|
||||
SYNTHETIC_ERRNO(searching ? EADDRNOTAVAIL : ENODEV),
|
||||
@@ -120,7 +124,7 @@ static int verify_esp_blkid(
|
||||
"File system \"%s\" is not on a GPT partition table.", node);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: EIO, "Failed to probe partition type UUID of \"%s\": %m", node);
|
||||
if (sd_id128_string_equal(v, SD_GPT_ESP) <= 0)
|
||||
@@ -129,7 +133,7 @@ static int verify_esp_blkid(
|
||||
"File system \"%s\" has wrong type for an EFI System Partition (ESP).", node);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe partition entry UUID of \"%s\": %m", node);
|
||||
r = sd_id128_from_string(v, &uuid);
|
||||
@@ -137,7 +141,7 @@ static int verify_esp_blkid(
|
||||
return log_error_errno(r, "Partition \"%s\" has invalid UUID \"%s\".", node, v);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_NUMBER", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_NUMBER", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe partition number of \"%s\": %m", node);
|
||||
r = safe_atou32(v, &part);
|
||||
@@ -145,7 +149,7 @@ static int verify_esp_blkid(
|
||||
return log_error_errno(r, "Failed to parse PART_ENTRY_NUMBER field.");
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_OFFSET", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_OFFSET", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe partition offset of \"%s\": %m", node);
|
||||
r = safe_atou64(v, &pstart);
|
||||
@@ -153,7 +157,7 @@ static int verify_esp_blkid(
|
||||
return log_error_errno(r, "Failed to parse PART_ENTRY_OFFSET field.");
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_SIZE", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_SIZE", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to probe partition size of \"%s\": %m", node);
|
||||
r = safe_atou64(v, &psize);
|
||||
@@ -603,21 +607,25 @@ static int verify_xbootldr_blkid(
|
||||
const char *type, *v;
|
||||
int r;
|
||||
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "No libblkid support: %m");
|
||||
|
||||
r = devname_from_devnum(S_IFBLK, devid, &node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get block device path for " DEVNUM_FORMAT_STR ": %m",
|
||||
DEVNUM_FORMAT_VAL(devid));
|
||||
|
||||
errno = 0;
|
||||
b = blkid_new_probe_from_filename(node);
|
||||
b = sym_blkid_new_probe_from_filename(node);
|
||||
if (!b)
|
||||
return log_error_errno(errno_or_else(ENOMEM), "%s: Failed to create blkid probe: %m", node);
|
||||
|
||||
blkid_probe_enable_partitions(b, 1);
|
||||
blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
sym_blkid_probe_enable_partitions(b, 1);
|
||||
sym_blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
r = sym_blkid_do_safeprobe(b);
|
||||
if (r == _BLKID_SAFEPROBE_AMBIGUOUS)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "%s: File system is ambiguous.", node);
|
||||
if (r == _BLKID_SAFEPROBE_NOT_FOUND)
|
||||
@@ -627,7 +635,7 @@ static int verify_xbootldr_blkid(
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &type, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &type, NULL);
|
||||
if (r != 0)
|
||||
return log_full_errno(searching ? LOG_DEBUG : LOG_ERR,
|
||||
searching ? SYNTHETIC_ERRNO(EADDRNOTAVAIL) : SYNTHETIC_ERRNO(EIO),
|
||||
@@ -635,7 +643,7 @@ static int verify_xbootldr_blkid(
|
||||
if (streq(type, "gpt")) {
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe PART_ENTRY_TYPE: %m", node);
|
||||
if (sd_id128_string_equal(v, SD_GPT_XBOOTLDR) <= 0)
|
||||
@@ -644,7 +652,7 @@ static int verify_xbootldr_blkid(
|
||||
"%s: Partition has wrong PART_ENTRY_TYPE=%s for XBOOTLDR partition.", node, v);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe PART_ENTRY_UUID: %m", node);
|
||||
r = sd_id128_from_string(v, &uuid);
|
||||
@@ -654,7 +662,7 @@ static int verify_xbootldr_blkid(
|
||||
} else if (streq(type, "dos")) {
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
r = sym_blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
|
||||
if (r != 0)
|
||||
return log_error_errno(errno_or_else(EIO), "%s: Failed to probe PART_ENTRY_TYPE: %m", node);
|
||||
if (!streq(v, "0xea"))
|
||||
|
||||
@@ -315,7 +315,7 @@ libshared_name = 'systemd-shared-@0@'.format(shared_lib_tag)
|
||||
libshared_deps = [threads,
|
||||
libacl_cflags,
|
||||
libaudit_cflags,
|
||||
libblkid,
|
||||
libblkid_cflags,
|
||||
libcap,
|
||||
libcrypt,
|
||||
libdl,
|
||||
|
||||
@@ -30,26 +30,30 @@ static int device_get_file_system_word(
|
||||
assert(ret);
|
||||
|
||||
#if HAVE_BLKID
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
_cleanup_close_ int block_fd = sd_device_open(d, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
|
||||
if (block_fd < 0)
|
||||
return block_fd;
|
||||
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = blkid_new_probe();
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = sym_blkid_new_probe();
|
||||
if (!b)
|
||||
return -ENOMEM;
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_set_device(b, block_fd, 0, 0);
|
||||
r = sym_blkid_probe_set_device(b, block_fd, 0, 0);
|
||||
if (r != 0)
|
||||
return errno_or_else(ENOMEM);
|
||||
|
||||
(void) blkid_probe_enable_superblocks(b, 1);
|
||||
(void) blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|BLKID_SUBLKS_UUID|BLKID_SUBLKS_LABEL);
|
||||
(void) blkid_probe_enable_partitions(b, 1);
|
||||
(void) blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
(void) sym_blkid_probe_enable_superblocks(b, 1);
|
||||
(void) sym_blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|BLKID_SUBLKS_UUID|BLKID_SUBLKS_LABEL);
|
||||
(void) sym_blkid_probe_enable_partitions(b, 1);
|
||||
(void) sym_blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
|
||||
errno = 0;
|
||||
r = blkid_do_safeprobe(b);
|
||||
r = sym_blkid_do_safeprobe(b);
|
||||
if (r == _BLKID_SAFEPROBE_ERROR)
|
||||
return errno_or_else(EIO);
|
||||
if (IN_SET(r, _BLKID_SAFEPROBE_AMBIGUOUS, _BLKID_SAFEPROBE_NOT_FOUND))
|
||||
@@ -64,7 +68,7 @@ static int device_get_file_system_word(
|
||||
FOREACH_STRING(field, "TYPE", "UUID", "LABEL", "PART_ENTRY_UUID", "PART_ENTRY_TYPE", "PART_ENTRY_NAME") {
|
||||
const char *v = NULL;
|
||||
|
||||
(void) blkid_probe_lookup_value(b, field, &v, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, field, &v, NULL);
|
||||
|
||||
_cleanup_free_ char *escaped = xescape(strempty(v), ":"); /* Avoid ambiguity around ":" */
|
||||
if (!escaped)
|
||||
|
||||
Reference in New Issue
Block a user