Skip to contentSkip to conversation

master - device: cleanup signature wiping functions

PATCH Peter Rajnoha 1 participant 1 message Nov 27, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=03c941a4caf411f21045670e205ccdd975be27c7
Commit:        03c941a4caf411f21045670e205ccdd975be27c7
Parent:        120df5561088f4a5277716117339d9212b666214
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Nov 6 15:09:29 2013 +0100
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Nov 27 12:56:58 2013 +0100

device: cleanup signature wiping functions

The wipe_known_signatures fn now wraps the _wipe_signature fn that is called for each known signature (currently md, swap and luks). This patch makes the code more readable, not repeating the same sequence when used anywhere in the code. We're going to reuse this code later...

---
 lib/device/dev-luks.c   |    5 +++--
 lib/device/dev-md.c     |    6 +++---
 lib/device/dev-swap.c   |    7 +++----
 lib/device/dev-type.c   |   42 ++++++++++++++++++++++++++++++++++++++++++
 lib/device/dev-type.h   |    4 ++++
 lib/metadata/metadata.c |   46 ++++------------------------------------------
 6 files changed, 59 insertions(+), 51 deletions(-)
lib/device/dev-luks.c +3 -2
index 2671d62..572fd1d 100644
@@ -18,7 +18,7 @@
 #define LUKS_SIGNATURE "LUKS\xba\xbe"
 #define LUKS_SIGNATURE_SIZE 6
 
-int dev_is_luks(struct device *dev, uint64_t *signature)
+int dev_is_luks(struct device *dev, uint64_t *offset_found)
 {
 	char buf[LUKS_SIGNATURE_SIZE];
 	int ret = -1;
@@ -28,7 +28,8 @@ int dev_is_luks(struct device *dev, uint64_t *signature)
 		return -1;
 	}
 
-	*signature = 0;
+	if (offset_found)
+		*offset_found = 0;
 
 	if (!dev_read(dev, 0, LUKS_SIGNATURE_SIZE, buf))
 		goto_out;
lib/device/dev-md.c +3 -3
index 9af8074..d6a7609 100644
@@ -81,7 +81,7 @@ static uint64_t _v1_sb_offset(uint64_t size, md_minor_version_t minor_version)
 /*
  * Returns -1 on error
  */
-int dev_is_md(struct device *dev, uint64_t *sb)
+int dev_is_md(struct device *dev, uint64_t *offset_found)
 {
 	int ret = 1;
 	md_minor_version_t minor;
@@ -120,8 +120,8 @@ out:
 	if (!dev_close(dev))
 		stack;
 
-	if (ret && sb)
-		*sb = sb_offset;
+	if (ret && offset_found)
+		*offset_found = sb_offset;
 
 	return ret;
 }
lib/device/dev-swap.c +3 -4
index cc44008..f506eda 100644
@@ -36,7 +36,7 @@ _swap_detect_signature(const char *buf)
 	return 0;
 }
 
-int dev_is_swap(struct device *dev, uint64_t *signature)
+int dev_is_swap(struct device *dev, uint64_t *offset_found)
 {
 	char buf[10];
 	uint64_t size;
@@ -53,8 +53,6 @@ int dev_is_swap(struct device *dev, uint64_t *signature)
 		return -1;
 	}
 
-	*signature = 0;
-
 	for (page = 0x1000; page <= MAX_PAGESIZE; page <<= 1) {
 		/*
 		 * skip 32k pagesize since this does not seem to be supported
@@ -69,7 +67,8 @@ int dev_is_swap(struct device *dev, uint64_t *signature)
 			break;
 		}
 		if (_swap_detect_signature(buf)) {
-			*signature = page - SIGNATURE_SIZE;
+			if (offset_found)
+				*offset_found = page - SIGNATURE_SIZE;
 			ret = 1;
 			break;
 		}
lib/device/dev-type.c +42 -0

48 lines not on this page · raw message

lib/device/dev-type.h +4 -0
index 2fa32db..895a172 100644
@@ -16,6 +16,7 @@
 #define _LVM_DEV_TYPE_H
 
 #include "device.h"
+#include "display.h"
 
 #define NUMBER_OF_MAJORS 4096
 
@@ -58,6 +59,9 @@ int dev_is_md(struct device *dev, uint64_t *sb);
 int dev_is_swap(struct device *dev, uint64_t *signature);
 int dev_is_luks(struct device *dev, uint64_t *signature);
 
+/* Signature wiping. */
+int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t force);
+
 /* Type-specific device properties */
 unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev);
 
lib/metadata/metadata.c +4 -42

58 lines not on this page · raw message