]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: introduce blkid_wipe_all
authorThomas Weißschuh <thomas@t-8ch.de>
Wed, 29 Nov 2023 18:51:37 +0000 (19:51 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Wed, 29 Nov 2023 18:59:46 +0000 (19:59 +0100)
This helper makes the common task of wiping all signatures easier.

Fixes #2592
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/docs/libblkid-sections.txt
libblkid/src/blkid.h.in
libblkid/src/libblkid.sym
libblkid/src/probe.c

index 92970025321292f0a56647f5fd329185c8952090..308f8effdc414dc25f6b121091060feade85b319 100644 (file)
@@ -73,6 +73,7 @@ BLKID_PROBE_AMBIGUOUS
 <FILE>lowprobe-tags</FILE>
 blkid_do_fullprobe
 blkid_do_wipe
+blkid_wipe_all
 blkid_do_probe
 blkid_do_safeprobe
 <SUBSECTION>
index c232d72fd17170a400a504794f624f5744ce2acd..8f6ec97d1a5e7a231b26393c49365af3faa96b51 100644 (file)
@@ -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));
 
index 775b0246cacb4681fe95e12669ad22630c03d4bb..7b2263a1c465495fb4c44cccfc21ee9e2543400b 100644 (file)
@@ -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;
index 19b80ec6ebeb275b159b3b8c8fd60ccefa116958..da1cc75490dd7954bc2a1d017e3612b444d5aab3 100644 (file)
@@ -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.
+ *
+ *  <example>
+ *  <title>wipe all filesystems or raids from the device</title>
+ *   <programlisting>
+ *      fd = open(devname, O_RDWR|O_CLOEXEC);
+ *      blkid_probe_set_device(pr, fd, 0, 0);
+ *
+ *      blkid_wipe_all(pr);
+ *  </programlisting>
+ * </example>
+ *
+ * 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