mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
libblkid: turn into dlopen() based dep
This commit is contained in:
@@ -1195,6 +1195,7 @@ libblkid = dependency('blkid',
|
||||
conf.set10('HAVE_BLKID', libblkid.found())
|
||||
conf.set10('HAVE_BLKID_PROBE_SET_HINT',
|
||||
libblkid.found() and cc.has_function('blkid_probe_set_hint', dependencies : libblkid))
|
||||
libblkid_cflags = libblkid.partial_dependency(includes: true, compile_args: true)
|
||||
|
||||
libkmod = dependency('libkmod',
|
||||
version : '>= 15',
|
||||
|
||||
@@ -143,20 +143,24 @@ static int probe_file_system_by_fd(
|
||||
assert(ret_fstype);
|
||||
assert(ret_uuid);
|
||||
|
||||
b = blkid_new_probe();
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
b = sym_blkid_new_probe();
|
||||
if (!b)
|
||||
return -ENOMEM;
|
||||
|
||||
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);
|
||||
|
||||
(void) blkid_probe_enable_superblocks(b, 1);
|
||||
(void) blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|BLKID_SUBLKS_UUID);
|
||||
(void) sym_blkid_probe_enable_superblocks(b, 1);
|
||||
(void) sym_blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|BLKID_SUBLKS_UUID);
|
||||
|
||||
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))
|
||||
@@ -164,11 +168,11 @@ static int probe_file_system_by_fd(
|
||||
|
||||
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)
|
||||
return -ENOPKG;
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "UUID", &uuid, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "UUID", &uuid, NULL);
|
||||
if (!uuid)
|
||||
return -ENOPKG;
|
||||
|
||||
@@ -674,22 +678,26 @@ static int luks_validate(
|
||||
assert(ret_offset);
|
||||
assert(ret_size);
|
||||
|
||||
b = blkid_new_probe();
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
b = sym_blkid_new_probe();
|
||||
if (!b)
|
||||
return -ENOMEM;
|
||||
|
||||
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);
|
||||
|
||||
(void) blkid_probe_enable_superblocks(b, 1);
|
||||
(void) blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
|
||||
(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);
|
||||
(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))
|
||||
@@ -697,7 +705,7 @@ static int luks_validate(
|
||||
|
||||
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 (streq_ptr(fstype, "crypto_LUKS")) {
|
||||
/* Directly a LUKS image */
|
||||
*ret_offset = 0;
|
||||
@@ -707,17 +715,17 @@ static int luks_validate(
|
||||
} else if (fstype)
|
||||
return -ENOPKG;
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
if (!streq_ptr(pttype, "gpt"))
|
||||
return -ENOPKG;
|
||||
|
||||
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 = blkid_partlist_numof_partitions(pl);
|
||||
n = sym_blkid_partlist_numof_partitions(pl);
|
||||
if (n < 0)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
@@ -726,14 +734,14 @@ static int luks_validate(
|
||||
blkid_partition pp;
|
||||
|
||||
errno = 0;
|
||||
pp = blkid_partlist_get_partition(pl, i);
|
||||
pp = sym_blkid_partlist_get_partition(pl, i);
|
||||
if (!pp)
|
||||
return errno_or_else(EIO);
|
||||
|
||||
if (sd_id128_string_equal(blkid_partition_get_type_string(pp), SD_GPT_USER_HOME) <= 0)
|
||||
if (sd_id128_string_equal(sym_blkid_partition_get_type_string(pp), SD_GPT_USER_HOME) <= 0)
|
||||
continue;
|
||||
|
||||
if (!streq_ptr(blkid_partition_get_name(pp), label))
|
||||
if (!streq_ptr(sym_blkid_partition_get_name(pp), label))
|
||||
continue;
|
||||
|
||||
r = blkid_partition_get_uuid_id128(pp, &id);
|
||||
@@ -745,8 +753,8 @@ static int luks_validate(
|
||||
if (found)
|
||||
return -ENOPKG;
|
||||
|
||||
offset = blkid_partition_get_start(pp);
|
||||
size = blkid_partition_get_size(pp);
|
||||
offset = sym_blkid_partition_get_start(pp);
|
||||
size = sym_blkid_partition_get_size(pp);
|
||||
found_partition_uuid = id;
|
||||
|
||||
found = true;
|
||||
|
||||
@@ -81,7 +81,7 @@ executables += [
|
||||
libshared_fdisk
|
||||
],
|
||||
'dependencies' : [
|
||||
libblkid,
|
||||
libblkid_cflags,
|
||||
libcrypt,
|
||||
libfdisk,
|
||||
libopenssl,
|
||||
|
||||
@@ -14,7 +14,7 @@ executables += [
|
||||
libshared_fdisk,
|
||||
],
|
||||
'dependencies' : [
|
||||
libblkid,
|
||||
libblkid_cflags,
|
||||
libfdisk,
|
||||
libopenssl,
|
||||
threads,
|
||||
@@ -33,7 +33,7 @@ executables += [
|
||||
libsystemd_static,
|
||||
],
|
||||
'dependencies' : [
|
||||
libblkid,
|
||||
libblkid_cflags,
|
||||
libfdisk,
|
||||
libopenssl,
|
||||
threads,
|
||||
|
||||
@@ -4278,32 +4278,36 @@ static int context_wipe_range(Context *context, uint64_t offset, uint64_t size)
|
||||
assert(offset != UINT64_MAX);
|
||||
assert(size != UINT64_MAX);
|
||||
|
||||
probe = blkid_new_probe();
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to load libblkid: %m");
|
||||
|
||||
probe = sym_blkid_new_probe();
|
||||
if (!probe)
|
||||
return log_oom();
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_set_device(probe, fdisk_get_devfd(context->fdisk_context), offset, size);
|
||||
r = sym_blkid_probe_set_device(probe, fdisk_get_devfd(context->fdisk_context), offset, size);
|
||||
if (r < 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to allocate device probe for wiping.");
|
||||
|
||||
errno = 0;
|
||||
if (blkid_probe_enable_superblocks(probe, true) < 0 ||
|
||||
blkid_probe_set_superblocks_flags(probe, BLKID_SUBLKS_MAGIC|BLKID_SUBLKS_BADCSUM) < 0 ||
|
||||
blkid_probe_enable_partitions(probe, true) < 0 ||
|
||||
blkid_probe_set_partitions_flags(probe, BLKID_PARTS_MAGIC) < 0)
|
||||
if (sym_blkid_probe_enable_superblocks(probe, true) < 0 ||
|
||||
sym_blkid_probe_set_superblocks_flags(probe, BLKID_SUBLKS_MAGIC|BLKID_SUBLKS_BADCSUM) < 0 ||
|
||||
sym_blkid_probe_enable_partitions(probe, true) < 0 ||
|
||||
sym_blkid_probe_set_partitions_flags(probe, BLKID_PARTS_MAGIC) < 0)
|
||||
return log_error_errno(errno ?: SYNTHETIC_ERRNO(EIO), "Failed to enable superblock and partition probing.");
|
||||
|
||||
for (;;) {
|
||||
errno = 0;
|
||||
r = blkid_do_probe(probe);
|
||||
r = sym_blkid_do_probe(probe);
|
||||
if (r < 0)
|
||||
return log_error_errno(errno_or_else(EIO), "Failed to probe for file systems.");
|
||||
if (r > 0)
|
||||
break;
|
||||
|
||||
errno = 0;
|
||||
if (blkid_do_wipe(probe, false) < 0)
|
||||
if (sym_blkid_do_wipe(probe, false) < 0)
|
||||
return log_error_errno(errno_or_else(EIO), "Failed to wipe file system signature.");
|
||||
}
|
||||
|
||||
@@ -7392,20 +7396,24 @@ static int resolve_copy_blocks_auto_candidate(
|
||||
return log_error_errno(r, "Failed to open block device " DEVNUM_FORMAT_STR ": %m",
|
||||
DEVNUM_FORMAT_VAL(whole_devno));
|
||||
|
||||
b = blkid_new_probe();
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to find libblkid: %m");
|
||||
|
||||
b = sym_blkid_new_probe();
|
||||
if (!b)
|
||||
return log_oom();
|
||||
|
||||
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 log_error_errno(errno_or_else(ENOMEM), "Failed to open block device '%s': %m", p);
|
||||
|
||||
(void) blkid_probe_enable_partitions(b, 1);
|
||||
(void) blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
|
||||
(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 log_error_errno(errno_or_else(EIO), "Unable to probe for partition table of '%s': %m", p);
|
||||
if (IN_SET(r, _BLKID_SAFEPROBE_AMBIGUOUS, _BLKID_SAFEPROBE_NOT_FOUND)) {
|
||||
@@ -7415,18 +7423,18 @@ static int resolve_copy_blocks_auto_candidate(
|
||||
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
if (!streq_ptr(pttype, "gpt")) {
|
||||
log_debug("Didn't find a GPT partition table on '%s'.", p);
|
||||
return false;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
pl = blkid_probe_get_partitions(b);
|
||||
pl = sym_blkid_probe_get_partitions(b);
|
||||
if (!pl)
|
||||
return log_error_errno(errno_or_else(EIO), "Unable read partition table of '%s': %m", p);
|
||||
|
||||
pp = blkid_partlist_devno_to_partition(pl, partition_devno);
|
||||
pp = sym_blkid_partlist_devno_to_partition(pl, partition_devno);
|
||||
if (!pp) {
|
||||
log_debug("Partition %u:%u has no matching partition table entry on '%s'.",
|
||||
major(partition_devno), minor(partition_devno), p);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -287,8 +287,9 @@ executables += [
|
||||
test_template + {
|
||||
'sources' : files('test-dlopen-so.c'),
|
||||
'dependencies' : [
|
||||
libp11kit_cflags,
|
||||
libblkid_cflags,
|
||||
libkmod_cflags,
|
||||
libp11kit_cflags,
|
||||
],
|
||||
},
|
||||
test_template + {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "acl-util.h"
|
||||
#include "apparmor-util.h"
|
||||
#include "blkid-util.h"
|
||||
#include "bpf-dlopen.h"
|
||||
#include "compress.h"
|
||||
#include "cryptsetup-util.h"
|
||||
@@ -54,6 +55,7 @@ static int run(int argc, char **argv) {
|
||||
ASSERT_DLOPEN(dlopen_libaudit, HAVE_AUDIT);
|
||||
ASSERT_DLOPEN(dlopen_libpam, HAVE_PAM);
|
||||
ASSERT_DLOPEN(dlopen_libacl, HAVE_ACL);
|
||||
ASSERT_DLOPEN(dlopen_libblkid, HAVE_BLKID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ endif
|
||||
|
||||
udev_dependencies = [
|
||||
libacl_cflags,
|
||||
libblkid,
|
||||
libblkid_cflags,
|
||||
libkmod,
|
||||
threads,
|
||||
]
|
||||
@@ -132,7 +132,7 @@ udev_common_template = {
|
||||
'objects' : ['udevadm'],
|
||||
'dependencies' : [
|
||||
libacl_cflags,
|
||||
libblkid,
|
||||
libblkid_cflags,
|
||||
threads,
|
||||
],
|
||||
}
|
||||
|
||||
@@ -49,21 +49,21 @@ static void print_property(UdevEvent *event, const char *name, const char *value
|
||||
udev_builtin_add_property(event, "ID_FS_VERSION", value);
|
||||
|
||||
} else if (streq(name, "UUID")) {
|
||||
blkid_safe_string(value, s, sizeof(s));
|
||||
sym_blkid_safe_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_UUID", s);
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_UUID_ENC", s);
|
||||
|
||||
} else if (streq(name, "UUID_SUB")) {
|
||||
blkid_safe_string(value, s, sizeof(s));
|
||||
sym_blkid_safe_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_UUID_SUB", s);
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_UUID_SUB_ENC", s);
|
||||
|
||||
} else if (streq(name, "LABEL")) {
|
||||
blkid_safe_string(value, s, sizeof(s));
|
||||
sym_blkid_safe_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_LABEL", s);
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_LABEL_ENC", s);
|
||||
|
||||
} else if (STR_IN_SET(name, "FSSIZE", "FSLASTBLOCK", "FSBLOCKSIZE")) {
|
||||
@@ -77,11 +77,11 @@ static void print_property(UdevEvent *event, const char *name, const char *value
|
||||
udev_builtin_add_property(event, "ID_PART_TABLE_UUID", value);
|
||||
|
||||
} else if (streq(name, "PART_ENTRY_NAME")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_PART_ENTRY_NAME", s);
|
||||
|
||||
} else if (streq(name, "PART_ENTRY_TYPE")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_PART_ENTRY_TYPE", s);
|
||||
|
||||
} else if (startswith(name, "PART_ENTRY_")) {
|
||||
@@ -89,35 +89,35 @@ static void print_property(UdevEvent *event, const char *name, const char *value
|
||||
udev_builtin_add_property(event, s, value);
|
||||
|
||||
} else if (streq(name, "SYSTEM_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_SYSTEM_ID", s);
|
||||
|
||||
} else if (streq(name, "PUBLISHER_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_PUBLISHER_ID", s);
|
||||
|
||||
} else if (streq(name, "APPLICATION_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_APPLICATION_ID", s);
|
||||
|
||||
} else if (streq(name, "BOOT_SYSTEM_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_BOOT_SYSTEM_ID", s);
|
||||
|
||||
} else if (streq(name, "VOLUME_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_VOLUME_ID", s);
|
||||
|
||||
} else if (streq(name, "LOGICAL_VOLUME_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_LOGICAL_VOLUME_ID", s);
|
||||
|
||||
} else if (streq(name, "VOLUME_SET_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_VOLUME_SET_ID", s);
|
||||
|
||||
} else if (streq(name, "DATA_PREPARER_ID")) {
|
||||
blkid_encode_string(value, s, sizeof(s));
|
||||
sym_blkid_encode_string(value, s, sizeof(s));
|
||||
udev_builtin_add_property(event, "ID_FS_DATA_PREPARER_ID", s);
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ static int find_gpt_root(UdevEvent *event, blkid_probe pr, const char *loop_back
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
blkid_partlist pl = blkid_probe_get_partitions(pr);
|
||||
blkid_partlist pl = sym_blkid_probe_get_partitions(pr);
|
||||
if (!pl)
|
||||
return log_device_debug_errno(dev, errno_or_else(ENOMEM), "Failed to probe partitions: %m");
|
||||
|
||||
@@ -233,7 +233,7 @@ static int find_gpt_root(UdevEvent *event, blkid_probe pr, const char *loop_back
|
||||
/* If we already know the root partition, let's verify its type ID and then directly query
|
||||
* its ID */
|
||||
|
||||
blkid_partition root_partition = blkid_partlist_devno_to_partition(pl, root_devno);
|
||||
blkid_partition root_partition = sym_blkid_partlist_devno_to_partition(pl, root_devno);
|
||||
if (root_partition) {
|
||||
sd_id128_t type;
|
||||
r = blkid_partition_get_type_id128(root_partition, &type);
|
||||
@@ -249,13 +249,13 @@ static int find_gpt_root(UdevEvent *event, blkid_probe pr, const char *loop_back
|
||||
/* We do not know the root partition, let's search for it. */
|
||||
|
||||
_cleanup_free_ char *root_label = NULL;
|
||||
int nvals = blkid_partlist_numof_partitions(pl);
|
||||
int nvals = sym_blkid_partlist_numof_partitions(pl);
|
||||
for (int i = 0; i < nvals; i++) {
|
||||
blkid_partition pp;
|
||||
const char *label;
|
||||
sd_id128_t type, id;
|
||||
|
||||
pp = blkid_partlist_get_partition(pl, i);
|
||||
pp = sym_blkid_partlist_get_partition(pl, i);
|
||||
if (!pp)
|
||||
continue;
|
||||
|
||||
@@ -271,7 +271,7 @@ static int find_gpt_root(UdevEvent *event, blkid_probe pr, const char *loop_back
|
||||
continue;
|
||||
}
|
||||
|
||||
label = blkid_partition_get_name(pp); /* returns NULL if empty */
|
||||
label = sym_blkid_partition_get_name(pp); /* returns NULL if empty */
|
||||
|
||||
if (need_esp_or_xbootldr && sd_id128_in_set(type, SD_GPT_ESP, SD_GPT_XBOOTLDR)) {
|
||||
|
||||
@@ -282,7 +282,7 @@ static int find_gpt_root(UdevEvent *event, blkid_probe pr, const char *loop_back
|
||||
} else if (sd_id128_equal(type, SD_GPT_ROOT_NATIVE)) {
|
||||
unsigned long long flags;
|
||||
|
||||
flags = blkid_partition_get_flags(pp);
|
||||
flags = sym_blkid_partition_get_flags(pp);
|
||||
if (flags & SD_GPT_FLAG_NO_AUTO)
|
||||
continue;
|
||||
|
||||
@@ -322,32 +322,32 @@ static int probe_superblocks(blkid_probe pr) {
|
||||
|
||||
/* TODO: Return negative errno. */
|
||||
|
||||
if (fstat(blkid_probe_get_fd(pr), &st))
|
||||
if (fstat(sym_blkid_probe_get_fd(pr), &st))
|
||||
return -errno;
|
||||
|
||||
blkid_probe_enable_partitions(pr, 1);
|
||||
sym_blkid_probe_enable_partitions(pr, 1);
|
||||
|
||||
if (!S_ISCHR(st.st_mode) &&
|
||||
blkid_probe_get_size(pr) <= 1024 * 1440 &&
|
||||
blkid_probe_is_wholedisk(pr)) {
|
||||
sym_blkid_probe_get_size(pr) <= 1024 * 1440 &&
|
||||
sym_blkid_probe_is_wholedisk(pr)) {
|
||||
/*
|
||||
* check if the small disk is partitioned, if yes then
|
||||
* don't probe for filesystems.
|
||||
*/
|
||||
blkid_probe_enable_superblocks(pr, 0);
|
||||
sym_blkid_probe_enable_superblocks(pr, 0);
|
||||
|
||||
rc = blkid_do_fullprobe(pr);
|
||||
rc = sym_blkid_do_fullprobe(pr);
|
||||
if (rc < 0)
|
||||
return rc; /* -1 = error, 1 = nothing, 0 = success */
|
||||
|
||||
if (blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0)
|
||||
if (sym_blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0)
|
||||
return 0; /* partition table detected */
|
||||
}
|
||||
|
||||
blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
|
||||
blkid_probe_enable_superblocks(pr, 1);
|
||||
sym_blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
|
||||
sym_blkid_probe_enable_superblocks(pr, 1);
|
||||
|
||||
return blkid_do_safeprobe(pr);
|
||||
return sym_blkid_do_safeprobe(pr);
|
||||
}
|
||||
|
||||
static int read_loopback_backing_inode(
|
||||
@@ -440,8 +440,12 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
|
||||
{}
|
||||
};
|
||||
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(dev, r, "blkid not available: %m");
|
||||
|
||||
errno = 0;
|
||||
pr = blkid_new_probe();
|
||||
pr = sym_blkid_new_probe();
|
||||
if (!pr)
|
||||
return log_device_debug_errno(dev, errno_or_else(ENOMEM), "Failed to create blkid prober: %m");
|
||||
|
||||
@@ -456,7 +460,7 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
|
||||
case 'H':
|
||||
#if HAVE_BLKID_PROBE_SET_HINT
|
||||
errno = 0;
|
||||
r = blkid_probe_set_hint(pr, optarg, 0);
|
||||
r = sym_blkid_probe_set_hint(pr, optarg, 0);
|
||||
if (r < 0)
|
||||
return log_device_error_errno(dev, errno_or_else(ENOMEM), "Failed to use '%s' probing hint: %m", optarg);
|
||||
break;
|
||||
@@ -482,7 +486,7 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
blkid_probe_set_superblocks_flags(pr,
|
||||
sym_blkid_probe_set_superblocks_flags(pr,
|
||||
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
|
||||
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
|
||||
#ifdef BLKID_SUBLKS_FSINFO
|
||||
@@ -491,7 +495,7 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
|
||||
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);
|
||||
|
||||
if (noraid)
|
||||
blkid_probe_filter_superblocks_usage(pr, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);
|
||||
sym_blkid_probe_filter_superblocks_usage(pr, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);
|
||||
|
||||
r = sd_device_get_devname(dev, &devnode);
|
||||
if (r < 0)
|
||||
@@ -506,7 +510,7 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
r = blkid_probe_set_device(pr, fd, offset, 0);
|
||||
r = sym_blkid_probe_set_device(pr, fd, offset, 0);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(dev, errno_or_else(ENOMEM), "Failed to set device to blkid prober: %m");
|
||||
|
||||
@@ -520,12 +524,12 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
|
||||
(void) sd_device_get_property_value(dev, "ID_PART_GPT_AUTO_ROOT_UUID", &root_partition);
|
||||
|
||||
errno = 0;
|
||||
int nvals = blkid_probe_numof_values(pr);
|
||||
int nvals = sym_blkid_probe_numof_values(pr);
|
||||
if (nvals < 0)
|
||||
return log_device_debug_errno(dev, errno_or_else(ENOMEM), "Failed to get number of probed values: %m");
|
||||
|
||||
for (int i = 0; i < nvals; i++) {
|
||||
if (blkid_probe_get_value(pr, i, &name, &data, NULL) < 0)
|
||||
if (sym_blkid_probe_get_value(pr, i, &name, &data, NULL) < 0)
|
||||
continue;
|
||||
|
||||
print_property(event, name, data);
|
||||
@@ -559,7 +563,7 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
|
||||
char encoded[sizeof_field(struct loop_info64, lo_file_name) * 4 + 1];
|
||||
|
||||
assert(strlen(backing_fname) < ELEMENTSOF(encoded) / 4);
|
||||
blkid_encode_string(backing_fname, encoded, ELEMENTSOF(encoded));
|
||||
sym_blkid_encode_string(backing_fname, encoded, ELEMENTSOF(encoded));
|
||||
|
||||
udev_builtin_add_property(event, "ID_LOOP_BACKING_FILENAME", backing_fname);
|
||||
udev_builtin_add_property(event, "ID_LOOP_BACKING_FILENAME_ENC", encoded);
|
||||
|
||||
@@ -8,7 +8,7 @@ executables += [
|
||||
],
|
||||
'sources' : files('validatefs.c'),
|
||||
'dependencies' : [
|
||||
libblkid,
|
||||
libblkid_cflags,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -257,7 +257,7 @@ static int validate_gpt_label(blkid_probe b, const ValidateFields *f) {
|
||||
return 0;
|
||||
|
||||
const char *v = NULL;
|
||||
(void) blkid_probe_lookup_value(b, "PART_ENTRY_NAME", &v, /* len= */ NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "PART_ENTRY_NAME", &v, /* len= */ NULL);
|
||||
|
||||
if (strv_contains(f->gpt_label, strempty(v)))
|
||||
return 0;
|
||||
@@ -277,7 +277,7 @@ static int validate_gpt_type(blkid_probe b, const ValidateFields *f) {
|
||||
return 0;
|
||||
|
||||
const char *v = NULL;
|
||||
(void) blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, /* len= */ NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, /* len= */ NULL);
|
||||
|
||||
sd_id128_t id;
|
||||
if (!v || sd_id128_from_string(v, &id) < 0) {
|
||||
@@ -305,26 +305,30 @@ static int validate_gpt_metadata_one(sd_device *d, const char *path, const Valid
|
||||
assert(d);
|
||||
assert(f);
|
||||
|
||||
r = dlopen_libblkid();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Cannot validate GPT constraints, refusing.");
|
||||
|
||||
_cleanup_close_ int block_fd = sd_device_open(d, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
|
||||
if (block_fd < 0)
|
||||
return log_error_errno(block_fd, "Failed to open block device backing '%s': %m", path);
|
||||
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = blkid_new_probe();
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = sym_blkid_new_probe();
|
||||
if (!b)
|
||||
return log_oom();
|
||||
|
||||
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 log_error_errno(errno_or_else(ENOMEM), "Failed to set up block device prober for '%s': %m", path);
|
||||
|
||||
(void) blkid_probe_enable_superblocks(b, 1);
|
||||
(void) blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE|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_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 log_error_errno(errno_or_else(EIO), "Failed to probe block device of '%s': %m", path);
|
||||
if (r == _BLKID_SAFEPROBE_AMBIGUOUS)
|
||||
@@ -335,7 +339,7 @@ static int validate_gpt_metadata_one(sd_device *d, const char *path, const Valid
|
||||
assert(r == _BLKID_SAFEPROBE_FOUND);
|
||||
|
||||
const char *v = NULL;
|
||||
(void) blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &v, /* len= */ NULL);
|
||||
(void) sym_blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &v, /* len= */ NULL);
|
||||
if (!streq_ptr(v, "gpt"))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EPERM), "File system is supposed to be on a GPT partition table, but is not, refusing.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user