[PATCH] block: partitions: ibm.c: Cleaning same magic numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Replaced a lot of the magic number, so it are now using a define instead.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@xxxxxxxxxxxxxxxxxx>
---
 block/partitions/ibm.c |   37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/block/partitions/ibm.c b/block/partitions/ibm.c
index 47a6147..8556ea1 100644
--- a/block/partitions/ibm.c
+++ b/block/partitions/ibm.c
@@ -16,6 +16,8 @@
 #include "check.h"
 #include "ibm.h"
 
+#define IBM_PARTITION_TYPE_SIZE 4
+#define IBM_PARTITION_NAME_SIZE 6
 
 union label_t {
 	struct vtoc_volume_label_cdl vol;
@@ -72,7 +74,7 @@ static int find_label(struct parsed_partitions *state,
 	Sector sect;
 	unsigned char *data;
 	sector_t testsect[3];
-	unsigned char temp[5];
+	unsigned char temp[IBM_PARTITION_TYPE_SIZE + 1];
 	int found = 0;
 	int i, testcount;
 
@@ -102,22 +104,26 @@ static int find_label(struct parsed_partitions *state,
 		if (data == NULL)
 			continue;
 		memcpy(label, data, sizeof(*label));
-		memcpy(temp, data, 4);
-		temp[4] = 0;
-		EBCASC(temp, 4);
+		memcpy(temp, data, IBM_PARTITION_TYPE_SIZE);
+		temp[IBM_PARTITION_TYPE_SIZE] = 0;
+		EBCASC(temp, IBM_PARTITION_TYPE_SIZE);
 		put_dev_sector(sect);
 		if (!strcmp(temp, "VOL1") ||
 		    !strcmp(temp, "LNX1") ||
 		    !strcmp(temp, "CMS1")) {
 			if (!strcmp(temp, "VOL1")) {
-				strncpy(type, label->vol.vollbl, 4);
-				strncpy(name, label->vol.volid, 6);
+				strncpy(type, label->vol.vollbl,
+						IBM_PARTITION_TYPE_SIZE);
+				strncpy(name, label->vol.volid,
+						IBM_PARTITION_NAME_SIZE);
 			} else {
-				strncpy(type, label->lnx.vollbl, 4);
-				strncpy(name, label->lnx.volid, 6);
+				strncpy(type, label->lnx.vollbl,
+						IBM_PARTITION_TYPE_SIZE);
+				strncpy(name, label->lnx.volid,
+						IBM_PARTITION_NAME_SIZE);
 			}
-			EBCASC(type, 4);
-			EBCASC(name, 6);
+			EBCASC(type, IBM_PARTITION_TYPE_SIZE);
+			EBCASC(name, IBM_PARTITION_NAME_SIZE);
 			*labelsect = testsect[i];
 			found = 1;
 			break;
@@ -282,7 +288,6 @@ static int find_cms1_partitions(struct parsed_partitions *state,
 	return 1;
 }
 
-
 /*
  * This is the main function, called by check.c
  */
@@ -293,8 +298,8 @@ int ibm_partition(struct parsed_partitions *state)
 	loff_t i_size, offset, size;
 	dasd_information2_t *info;
 	struct hd_geometry *geo;
-	char type[5] = {0,};
-	char name[7] = {0,};
+	char type[IBM_PARTITION_TYPE_SIZE + 1] = {0,};
+	char name[IBM_PARTITION_NAME_SIZE + 1] = {0,};
 	sector_t labelsect;
 	union label_t *label;
 
@@ -323,14 +328,14 @@ int ibm_partition(struct parsed_partitions *state)
 
 	if (find_label(state, info, geo, blocksize, &labelsect, name, type,
 		       label)) {
-		if (!strncmp(type, "VOL1", 4)) {
+		if (!strncmp(type, "VOL1", IBM_PARTITION_TYPE_SIZE)) {
 			res = find_vol1_partitions(state, geo, blocksize, name,
 						   label);
-		} else if (!strncmp(type, "LNX1", 4)) {
+		} else if (!strncmp(type, "LNX1", IBM_PARTITION_TYPE_SIZE)) {
 			res = find_lnx1_partitions(state, geo, blocksize, name,
 						   label, labelsect, i_size,
 						   info);
-		} else if (!strncmp(type, "CMS1", 4)) {
+		} else if (!strncmp(type, "CMS1", IBM_PARTITION_TYPE_SIZE)) {
 			res = find_cms1_partitions(state, geo, blocksize, name,
 						   label, labelsect);
 		}
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-s390" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux