From: Thomas Weißschuh Date: Wed, 29 Nov 2023 18:51:37 +0000 (+0100) Subject: libblkid: introduce blkid_wipe_all X-Git-Tag: v2.40-rc1~141^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c92c65a9906088f6237d709c9a135751e9029a5;p=thirdparty%2Futil-linux.git libblkid: introduce blkid_wipe_all This helper makes the common task of wiping all signatures easier. Fixes #2592 Signed-off-by: Thomas Weißschuh --- diff --git a/libblkid/docs/libblkid-sections.txt b/libblkid/docs/libblkid-sections.txt index 9297002532..308f8effdc 100644 --- a/libblkid/docs/libblkid-sections.txt +++ b/libblkid/docs/libblkid-sections.txt @@ -73,6 +73,7 @@ BLKID_PROBE_AMBIGUOUS lowprobe-tags blkid_do_fullprobe blkid_do_wipe +blkid_wipe_all blkid_do_probe blkid_do_safeprobe diff --git a/libblkid/src/blkid.h.in b/libblkid/src/blkid.h.in index c232d72fd1..8f6ec97d1a 100644 --- a/libblkid/src/blkid.h.in +++ b/libblkid/src/blkid.h.in @@ -458,6 +458,8 @@ extern int blkid_probe_has_value(blkid_probe pr, const char *name) __ul_attribute__((nonnull)); extern int blkid_do_wipe(blkid_probe pr, int dryrun) __ul_attribute__((nonnull)); +extern int blkid_wipe_all(blkid_probe pr) + __ul_attribute__((nonnull)); extern int blkid_probe_step_back(blkid_probe pr) __ul_attribute__((nonnull)); diff --git a/libblkid/src/libblkid.sym b/libblkid/src/libblkid.sym index 775b0246ca..7b2263a1c4 100644 --- a/libblkid/src/libblkid.sym +++ b/libblkid/src/libblkid.sym @@ -187,3 +187,7 @@ BLKID_2_37 { BLKID_2_39 { blkid_topology_get_diskseq; } BLKID_2_37; + +BLKID_2_40 { + blkid_wipe_all; +} BLKID_2_39; diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 19b80ec6eb..da1cc75490 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -1482,6 +1482,8 @@ static inline int is_conventional(blkid_probe pr __attribute__((__unused__)), * See also blkid_probe_step_back() if you cannot use this built-in wipe * function, but you want to use libblkid probing as a source for wiping. * + * See also blkid_wipe_all() which works the same as the example above. + * * Returns: 0 on success, and -1 in case of error. */ int blkid_do_wipe(blkid_probe pr, int dryrun) @@ -1582,6 +1584,46 @@ int blkid_do_wipe(blkid_probe pr, int dryrun) return BLKID_PROBE_OK; } +/** + * blkid_wipe_all: + * @pr: prober + * + * This function erases all detectable signatures from &pr. + * The @pr has to be open in O_RDWR mode. All other necessary configurations + * will be enabled automatically. + * + * + * wipe all filesystems or raids from the device + * + * fd = open(devname, O_RDWR|O_CLOEXEC); + * blkid_probe_set_device(pr, fd, 0, 0); + * + * blkid_wipe_all(pr); + * + * + * + * Returns: 0 on success, and -1 in case of error. + */ +int blkid_wipe_all(blkid_probe pr) +{ + DBG(LOWPROBE, ul_debug("wiping all signatures")); + + blkid_probe_enable_superblocks(pr, 1); + blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC | + BLKID_SUBLKS_BADCSUM); + + blkid_probe_enable_partitions(pr, 1); + blkid_probe_set_partitions_flags(pr, BLKID_PARTS_MAGIC | + BLKID_PARTS_FORCE_GPT); + + while (blkid_do_probe(pr) == 0) { + DBG(LOWPROBE, ul_debug("wiping one signature")); + blkid_do_wipe(pr, 0); + } + + return BLKID_PROBE_OK; +} + /** * blkid_probe_step_back: * @pr: prober