From: Karel Zak Date: Tue, 9 May 2023 11:21:58 +0000 (+0200) Subject: libmount: allow overwrite how to use libblkid X-Git-Tag: v2.39~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=128c416d5c6c28e31ab5c3e831662ec8ab5f8e69;p=thirdparty%2Futil-linux.git libmount: allow overwrite how to use libblkid This is unnecessary for classic mount-like tasks, but application may use libmount in situation when the default for probing is not optimal. Addresses: https://github.com/util-linux/util-linux/issues/2214 Signed-off-by: Karel Zak --- diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt index 3e2e6761da..86a762277d 100644 --- a/libmount/docs/libmount-sections.txt +++ b/libmount/docs/libmount-sections.txt @@ -9,6 +9,7 @@ mnt_cache_device_has_tag mnt_cache_find_tag_value mnt_cache_read_tags mnt_cache_set_targets +mnt_cache_set_sbprobe mnt_get_fstype mnt_pretty_path mnt_resolve_path diff --git a/libmount/src/cache.c b/libmount/src/cache.c index c9b99538a3..2505919c99 100644 --- a/libmount/src/cache.c +++ b/libmount/src/cache.c @@ -56,6 +56,7 @@ struct libmnt_cache { size_t nents; size_t nallocs; int refcount; + int probe_sb_extra; /* extra BLKID_SUBLKS_* flags */ /* blkid_evaluate_tag() works in two ways: * @@ -170,6 +171,23 @@ int mnt_cache_set_targets(struct libmnt_cache *cache, return 0; } +/** + * mnt_cache_set_sbprobe: + * @cache: cache pointer + * @flags: BLKID_SUBLKS_* flags + * + * Add extra flags to the libblkid prober. Don't use if not sure. + * + * Returns: negative number in case of error, or 0 o success. + */ +int mnt_cache_set_sbprobe(struct libmnt_cache *cache, int flags) +{ + if (!cache) + return -EINVAL; + + cache->probe_sb_extra = flags; + return 0; +} /* note that the @key could be the same pointer as @value */ static int cache_add_entry(struct libmnt_cache *cache, char *key, @@ -346,7 +364,7 @@ int mnt_cache_read_tags(struct libmnt_cache *cache, const char *devname) blkid_probe_enable_superblocks(pr, 1); blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | - BLKID_SUBLKS_TYPE); + BLKID_SUBLKS_TYPE | cache->probe_sb_extra); blkid_probe_enable_partitions(pr, 1); blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS); diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index 6e57efb751..73a2802f49 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -363,6 +363,7 @@ extern void mnt_unref_cache(struct libmnt_cache *cache); extern int mnt_cache_set_targets(struct libmnt_cache *cache, struct libmnt_table *mountinfo); +extern int mnt_cache_set_sbprobe(struct libmnt_cache *cache, int flags); extern int mnt_cache_read_tags(struct libmnt_cache *cache, const char *devname); extern int mnt_cache_device_has_tag(struct libmnt_cache *cache, diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym index 7d8396a1a9..715bb5c5f0 100644 --- a/libmount/src/libmount.sym +++ b/libmount/src/libmount.sym @@ -368,6 +368,7 @@ MOUNT_2_38 { } MOUNT_2_37; MOUNT_2_39 { + mnt_cache_set_sbprobe; mnt_context_enable_onlyonce; mnt_context_is_lazy; mnt_context_enable_noautofs;