From 412de7dc2596b44ac1e7e1490b3408fb8ae80394 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Thu, 7 Apr 2022 16:22:56 +0200 Subject: [PATCH] Add suport for filtering only LUKS signatures. --- lib/utils_blkid.c | 27 +++++++++++++++++++++++---- lib/utils_blkid.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/utils_blkid.c b/lib/utils_blkid.c index 372d822f..6ffbc34c 100644 --- a/lib/utils_blkid.c +++ b/lib/utils_blkid.c @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -135,16 +136,34 @@ int blk_init_by_fd(struct blkid_handle **h, int fd) return r; } -int blk_superblocks_filter_luks(struct blkid_handle *h) -{ - int r = -ENOTSUP; #ifdef HAVE_BLKID +static int blk_superblocks_luks(struct blkid_handle *h, bool enable) +{ char luks[] = "crypto_LUKS"; char *luks_filter[] = { luks, NULL }; - r = blkid_probe_filter_superblocks_type(h->pr, BLKID_FLTR_NOTIN, luks_filter); + return blkid_probe_filter_superblocks_type(h->pr, + enable ? BLKID_FLTR_ONLYIN : BLKID_FLTR_NOTIN, + luks_filter); +} +#endif + +int blk_superblocks_filter_luks(struct blkid_handle *h) +{ + int r = -ENOTSUP; +#ifdef HAVE_BLKID + r = blk_superblocks_luks(h, false); +#endif + return r; +} + +int blk_superblocks_only_luks(struct blkid_handle *h) +{ + int r = -ENOTSUP; +#ifdef HAVE_BLKID + r = blk_superblocks_luks(h, true); #endif return r; } diff --git a/lib/utils_blkid.h b/lib/utils_blkid.h index ad7980fd..60f3b6a2 100644 --- a/lib/utils_blkid.h +++ b/lib/utils_blkid.h @@ -44,6 +44,7 @@ void blk_set_chains_for_full_print(struct blkid_handle *h); void blk_set_chains_for_fast_detection(struct blkid_handle *h); int blk_superblocks_filter_luks(struct blkid_handle *h); +int blk_superblocks_only_luks(struct blkid_handle *h); blk_probe_status blk_safeprobe(struct blkid_handle *h);