]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: add blkid_evaluate_tag2() with flags
authorKarel Zak <kzak@redhat.com>
Tue, 2 Jun 2026 10:25:27 +0000 (12:25 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 9 Jun 2026 08:40:39 +0000 (10:40 +0200)
Add blkid_evaluate_tag2() that accepts flags to control tag
evaluation behavior. The BLKID_EVALUATE_NOPROBE flag disables
low-level device scanning (evaluate_by_scan), while keeping
udev symlink-based evaluation (evaluate_by_udev) functional.

The original blkid_evaluate_tag() is now a thin wrapper around
the new function with flags=0.

Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/docs/libblkid-sections.txt
libblkid/src/blkid.h.in
libblkid/src/evaluate.c
libblkid/src/libblkid.sym

index 308f8effdc414dc25f6b121091060feade85b319..60a43b5024af88d0b18dc13e3e759af386bf692c 100644 (file)
@@ -1,6 +1,7 @@
 <SECTION>
 <FILE>evaluate</FILE>
 blkid_evaluate_tag
+blkid_evaluate_tag2
 blkid_evaluate_spec
 </SECTION>
 
index 637d970f2a9ddbe4255eb86c346cd3ec472fb59c..8dfea21523e2ca2d96953f6e7add5907bad17a47 100644 (file)
@@ -219,9 +219,14 @@ extern int blkid_send_uevent(const char *devname, const char *action);
 extern char *blkid_evaluate_tag(const char *token, const char *value,
                                blkid_cache *cache)
                        __ul_attribute__((warn_unused_result));
+extern char *blkid_evaluate_tag2(const char *token, const char *value,
+                               blkid_cache *cache, int flags)
+                       __ul_attribute__((warn_unused_result));
 extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
                        __ul_attribute__((warn_unused_result));
 
+#define BLKID_EVALUATE_NOPROBE (1 << 0)        /* disable low-level device probing */
+
 /* probe.c */
 extern blkid_probe blkid_new_probe(void)
                        __ul_attribute__((warn_unused_result));
index 11c26163a42806de8d56834b1cb6406b8c949cef..2618b9192d2766aea0d3f43c6add2764d1a8440a 100644 (file)
@@ -218,18 +218,8 @@ static char *evaluate_by_scan(const char *token, const char *value,
        return res;
 }
 
-/**
- * blkid_evaluate_tag:
- * @token: token name (e.g "LABEL" or "UUID") or unparsed tag (e.g. "LABEL=foo")
- * @value: token data (e.g. "foo")
- * @cache: pointer to cache (or NULL when you don't want to re-use the cache)
- *
-* If the @value is NULL and @token is not in the NAME=value format, then return
-* a copy of the @token.
- *
- * Returns: allocated string with a device name.
- */
-char *blkid_evaluate_tag(const char *token, const char *value, blkid_cache *cache)
+static char *evaluate_tag(const char *token, const char *value,
+               blkid_cache *cache, int flags)
 {
        struct blkid_config *conf = NULL;
        char *t = NULL, *v = NULL;
@@ -260,7 +250,8 @@ char *blkid_evaluate_tag(const char *token, const char *value, blkid_cache *cach
        for (i = 0; i < conf->nevals; i++) {
                if (conf->eval[i] == BLKID_EVAL_UDEV)
                        ret = evaluate_by_udev(token, value, conf->uevent);
-               else if (conf->eval[i] == BLKID_EVAL_SCAN)
+               else if (conf->eval[i] == BLKID_EVAL_SCAN
+                        && !(flags & BLKID_EVALUATE_NOPROBE))
                        ret = evaluate_by_scan(token, value, cache, conf);
                if (ret)
                        break;
@@ -274,6 +265,40 @@ out:
        return ret;
 }
 
+/**
+ * blkid_evaluate_tag:
+ * @token: token name (e.g "LABEL" or "UUID") or unparsed tag (e.g. "LABEL=foo")
+ * @value: token data (e.g. "foo")
+ * @cache: pointer to cache (or NULL when you don't want to re-use the cache)
+ *
+ * If the @value is NULL and @token is not in the NAME=value format, then return
+ * a copy of the @token.
+ *
+ * Returns: allocated string with a device name.
+ */
+char *blkid_evaluate_tag(const char *token, const char *value, blkid_cache *cache)
+{
+       return evaluate_tag(token, value, cache, 0);
+}
+
+/**
+ * blkid_evaluate_tag2:
+ * @token: token name (e.g "LABEL" or "UUID") or unparsed tag (e.g. "LABEL=foo")
+ * @value: token data (e.g. "foo")
+ * @cache: pointer to cache (or NULL when you don't want to re-use the cache)
+ * @flags: BLKID_EVALUATE_* flags
+ *
+ * Same as blkid_evaluate_tag(), but with flags to control evaluation.
+ * The BLKID_EVALUATE_NOPROBE flag disables low-level device probing.
+ *
+ * Returns: allocated string with a device name.
+ */
+char *blkid_evaluate_tag2(const char *token, const char *value,
+               blkid_cache *cache, int flags)
+{
+       return evaluate_tag(token, value, cache, flags);
+}
+
 /**
  * blkid_evaluate_spec:
  * @spec: unparsed tag (e.g. "LABEL=foo") or path (e.g. /dev/dm-0)
index 7b2263a1c465495fb4c44cccfc21ee9e2543400b..01b6170f9c65ae83dfe73c05261439565e07ebf9 100644 (file)
@@ -191,3 +191,7 @@ BLKID_2_39 {
 BLKID_2_40 {
     blkid_wipe_all;
 } BLKID_2_39;
+
+BLKID_2_43 {
+    blkid_evaluate_tag2;
+} BLKID_2_40;