Blame SOURCES/0058-libparted-dasd-unify-vtoc-handling-for-cdl-ldl.patch

003ee8
From ebb6eef20792a17388da30f1c312ede4b03140fd Mon Sep 17 00:00:00 2001
003ee8
From: Wang Dong <dongdwdw@linux.vnet.ibm.com>
003ee8
Date: Wed, 26 Oct 2016 04:22:46 +0200
003ee8
Subject: [PATCH 58/75] libparted/dasd: unify vtoc handling for cdl/ldl
003ee8
003ee8
Merge volume label cdl and ldl. It is convenient to manipulate
003ee8
the same structure. Also remove unused arguments in the functions.
003ee8
003ee8
Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
003ee8
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
003ee8
Signed-off-by: Brian C. Lane <bcl@redhat.com>
003ee8
---
003ee8
 include/parted/vtoc.in.h | 34 +++++++++++++++++++---------------
003ee8
 libparted/labels/dasd.c  |  8 +++-----
003ee8
 libparted/labels/vtoc.c  | 38 +++++++++++++++++---------------------
003ee8
 3 files changed, 39 insertions(+), 41 deletions(-)
003ee8
003ee8
diff --git a/include/parted/vtoc.in.h b/include/parted/vtoc.in.h
003ee8
index 499c2d3..b9da23a 100644
003ee8
--- a/include/parted/vtoc.in.h
003ee8
+++ b/include/parted/vtoc.in.h
003ee8
@@ -62,7 +62,6 @@ typedef struct cchh             cchh_t;
003ee8
 typedef struct labeldate        labeldate_t;
003ee8
 typedef struct volume_label     volume_label_t;
003ee8
 typedef struct cms_volume_label cms_volume_label_t;
003ee8
-typedef struct ldl_volume_label ldl_volume_label_t;
003ee8
 typedef struct extent           extent_t;
003ee8
 typedef struct dev_const        dev_const_t;
003ee8
 typedef struct format1_label    format1_label_t;
003ee8
@@ -94,6 +93,19 @@ struct __attribute__ ((packed)) labeldate {
003ee8
         u_int16_t day;
003ee8
 };
003ee8
 
003ee8
+/*
003ee8
+ * The following structure is a merger of the cdl and ldl volume label.
003ee8
+ * On an ldl disk there is no key information, so when reading an
003ee8
+ * ldl label from disk, the data should be copied at the address of vollbl.
003ee8
+ * On the other side, the field ldl_version is reserved in a cdl record
003ee8
+ * and the field formatted_blocks exists only for ldl labels. So when
003ee8
+ * reading a cdl label from disk, the formatted_blocks field will contain
003ee8
+ * arbitrary data.
003ee8
+ * This layout may be a bit awkward, but the advantage of having the
003ee8
+ * same label type for both disk layout types is bigger than the effort
003ee8
+ * for taking a bit of extra care at the fringes.
003ee8
+ */
003ee8
+
003ee8
 struct __attribute__ ((packed)) volume_label {
003ee8
 	char volkey[4];         /* volume key = volume label                 */
003ee8
 	char vollbl[4];	        /* volume label ("VOL1" in EBCDIC)           */
003ee8
@@ -107,15 +119,8 @@ struct __attribute__ ((packed)) volume_label {
003ee8
 	char labperci[4];       /* no of labels per CI (FBA), blanks for CKD */
003ee8
 	char res2[4];	        /* reserved                                  */
003ee8
 	char lvtoc[14];	        /* owner code for LVTOC                      */
003ee8
-	char res3[29];	        /* reserved                                  */
003ee8
-        char fudge[4];          /* filler to match length of ldl label       */
003ee8
-};
003ee8
-
003ee8
-struct __attribute__ ((packed)) ldl_volume_label {
003ee8
-	char vollbl[4];         /* Label identifier ("LNX1" in EBCDIC)       */
003ee8
-        char volid[6];          /* Volume identifier                         */
003ee8
-        char res3[69];          /* Reserved field                            */
003ee8
-        char ldl_version[1];    /* Version number, valid for ldl format      */
003ee8
+        char res3[28];	        /* reserved                                  */
003ee8
+        char ldl_version;       /* version number, valid for ldl format      */
003ee8
         u_int64_t formatted_blocks;  /* valid when ldl_version >= "2" (in
003ee8
                                         EBCDIC)                              */
003ee8
 };
003ee8
@@ -335,11 +340,10 @@ void vtoc_write_label (int fd, unsigned long position,
003ee8
                        format7_label_t const *f7,
003ee8
                        format9_label_t const *f9);
003ee8
 
003ee8
-void vtoc_init_format1_label (char *volid, unsigned int blksize,
003ee8
+void vtoc_init_format1_label (unsigned int blksize,
003ee8
                               extent_t *part_extent, format1_label_t *f1);
003ee8
 
003ee8
 void vtoc_init_format4_label (format4_label_t *f4lbl,
003ee8
-                              unsigned int usable_partitions,
003ee8
                               unsigned int compat_cylinders,
003ee8
                               unsigned int real_cylinders,
003ee8
                               unsigned int tracks,
003ee8
@@ -352,11 +356,11 @@ void vtoc_update_format4_label (format4_label_t *f4, cchhb_t *highest_f1,
003ee8
 
003ee8
 void vtoc_init_format5_label (format5_label_t *f5);
003ee8
 
003ee8
-void vtoc_update_format5_label_add (format5_label_t *f5, int verbose, int cyl,
003ee8
+void vtoc_update_format5_label_add (format5_label_t *f5, int verbose,
003ee8
                                     int trk, u_int16_t a, u_int16_t b,
003ee8
                                     u_int8_t c);
003ee8
 
003ee8
-void vtoc_update_format5_label_del (format5_label_t *f5, int verbose, int cyl,
003ee8
+void vtoc_update_format5_label_del (format5_label_t *f5, int verbose,
003ee8
                                     int trk, u_int16_t a, u_int16_t b,
003ee8
                                     u_int8_t c);
003ee8
 
003ee8
@@ -368,7 +372,7 @@ void vtoc_update_format7_label_add (format7_label_t *f7, int verbose,
003ee8
 void vtoc_update_format7_label_del (format7_label_t *f7, int verbose,
003ee8
                                     u_int32_t a, u_int32_t b);
003ee8
 
003ee8
-void vtoc_init_format8_label (char *volid, unsigned int blksize,
003ee8
+void vtoc_init_format8_label (unsigned int blksize,
003ee8
                               extent_t *part_extent, format1_label_t *f1);
003ee8
 
003ee8
 void vtoc_update_format8_label (cchhb_t *associated_f9, format1_label_t *f8);
003ee8
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
003ee8
index 4e68512..7594e96 100644
003ee8
--- a/libparted/labels/dasd.c
003ee8
+++ b/libparted/labels/dasd.c
003ee8
@@ -330,13 +330,12 @@ dasd_read (PedDisk* disk)
003ee8
 		DasdPartitionData* dasd_data;
003ee8
 
003ee8
 		union vollabel {
003ee8
-			volume_label_t unused;
003ee8
-			ldl_volume_label_t ldl;
003ee8
+			volume_label_t ldl;
003ee8
 			cms_volume_label_t cms;
003ee8
 		};
003ee8
 		union vollabel *cms_ptr1 = (union vollabel *) anchor.vlabel;
003ee8
 		cms_volume_label_t *cms_ptr = &cms_ptr1->cms;
003ee8
-		ldl_volume_label_t *ldl_ptr = &cms_ptr1->ldl;
003ee8
+		volume_label_t *ldl_ptr = &cms_ptr1->ldl;
003ee8
 		int partition_start_block;
003ee8
 
003ee8
 		disk_specific->format_type = 1;
003ee8
@@ -360,8 +359,7 @@ dasd_read (PedDisk* disk)
003ee8
 				* (long long) cms_ptr->disk_offset;
003ee8
 
003ee8
 		if (is_ldl)
003ee8
-		   if (strncmp(ldl_ptr->ldl_version,
003ee8
-			       vtoc_ebcdic_enc("2", str, 1), 1) >= 0)
003ee8
+		   if (ldl_ptr->ldl_version >= 0xf2)
003ee8
 		      end = (long long) arch_specific->real_sector_size
003ee8
 			    / (long long) disk->dev->sector_size
003ee8
 			    * (long long) ldl_ptr->formatted_blocks - 1;
003ee8
diff --git a/libparted/labels/vtoc.c b/libparted/labels/vtoc.c
003ee8
index fdfa94f..d47b791 100644
003ee8
--- a/libparted/labels/vtoc.c
003ee8
+++ b/libparted/labels/vtoc.c
003ee8
@@ -150,7 +150,7 @@ enum failure {
003ee8
 	unable_to_read
003ee8
 };
003ee8
 
003ee8
-static char buffer[89];
003ee8
+static char buffer[93];
003ee8
 
003ee8
 static void
003ee8
 vtoc_error (enum failure why, char const *s1, char const *s2)
003ee8
@@ -329,7 +329,7 @@ void
003ee8
 vtoc_volume_label_init (volume_label_t *vlabel)
003ee8
 {
003ee8
 	PDEBUG
003ee8
-	sprintf(buffer, "%88s", " ");
003ee8
+	sprintf(buffer, "%92s", " ");
003ee8
 	vtoc_ebcdic_enc(buffer, buffer, sizeof *vlabel);
003ee8
 	memcpy(vlabel, buffer, sizeof *vlabel);
003ee8
 }
003ee8
@@ -348,8 +348,8 @@ vtoc_read_volume_label (int f, unsigned long vlabel_start,
003ee8
 	typedef union vollabel vollabel_t;
003ee8
 
003ee8
 	union __attribute__((packed)) vollabel {
003ee8
+		/* cdl and ldl have the same data struct */
003ee8
 		volume_label_t cdl;
003ee8
-		ldl_volume_label_t ldl;
003ee8
 		cms_volume_label_t cms;
003ee8
 	};
003ee8
 
003ee8
@@ -373,9 +373,7 @@ vtoc_read_volume_label (int f, unsigned long vlabel_start,
003ee8
 	}
003ee8
 
003ee8
 	rc = read(f, vlabel, sizeof(volume_label_t));
003ee8
-	if (rc != sizeof(volume_label_t) &&
003ee8
-	/* For CDL we ask to read 88 bytes, but only get 84 */
003ee8
-            rc != sizeof(volume_label_t) - 4) {
003ee8
+	if (rc != sizeof(volume_label_t)) {
003ee8
 		vtoc_error(unable_to_read, "vtoc_read_volume_label",
003ee8
 			   _("Could not read volume label."));
003ee8
 		return 1;
003ee8
@@ -427,10 +425,8 @@ vtoc_write_volume_label (int f, unsigned long vlabel_start,
003ee8
 		vtoc_error(unable_to_seek, "vtoc_write_volume_label",
003ee8
 			   _("Could not write volume label."));
003ee8
 
003ee8
-	rc = write(f, vlabel, sizeof(volume_label_t) - 4);
003ee8
-	/* Subtract 4 to leave off the "fudge" variable when writing.
003ee8
-           We only write CDL volume labels, never LDL or CMS.  */
003ee8
-	if (rc != sizeof(volume_label_t) - 4)
003ee8
+	rc = write(f, vlabel, sizeof(volume_label_t));
003ee8
+	if (rc != sizeof(volume_label_t))
003ee8
 		vtoc_error(unable_to_write, "vtoc_write_volume_label",
003ee8
 			   _("Could not write volume label."));
003ee8
 
003ee8
@@ -632,7 +628,7 @@ vtoc_write_label (int f, unsigned long position,
003ee8
  * initializes a format4 label
003ee8
  */
003ee8
 void
003ee8
-vtoc_init_format4_label (format4_label_t *f4, unsigned int usable_partitions,
003ee8
+vtoc_init_format4_label (format4_label_t *f4,
003ee8
                          unsigned int compat_cylinders,
003ee8
                          unsigned int real_cylinders, unsigned int tracks,
003ee8
                          unsigned int blocks, unsigned int blksize,
003ee8
@@ -740,7 +736,7 @@ vtoc_init_format7_label (format7_label_t *f7)
003ee8
  * format1 or format 8 label, all but the field DS1FMTID
003ee8
  */
003ee8
 void
003ee8
-vtoc_init_format_1_8_label (char *volid, unsigned int blksize,
003ee8
+vtoc_init_format_1_8_label (unsigned int blksize,
003ee8
                             extent_t *part_extent, format1_label_t *f1)
003ee8
 {
003ee8
 	PDEBUG
003ee8
@@ -794,18 +790,18 @@ vtoc_init_format_1_8_label (char *volid, unsigned int blksize,
003ee8
 }
003ee8
 
003ee8
 void
003ee8
-vtoc_init_format1_label (char *volid, unsigned int blksize,
003ee8
+vtoc_init_format1_label (unsigned int blksize,
003ee8
                          extent_t *part_extent, format1_label_t *f1)
003ee8
 {
003ee8
-	vtoc_init_format_1_8_label(volid, blksize, part_extent, f1);
003ee8
+	vtoc_init_format_1_8_label(blksize, part_extent, f1);
003ee8
 	f1->DS1FMTID = 0xf1;
003ee8
 }
003ee8
 
003ee8
 void
003ee8
-vtoc_init_format8_label (char *volid, unsigned int blksize,
003ee8
+vtoc_init_format8_label (unsigned int blksize,
003ee8
                          extent_t *part_extent, format1_label_t *f8)
003ee8
 {
003ee8
-	vtoc_init_format_1_8_label(volid, blksize, part_extent, f8);
003ee8
+	vtoc_init_format_1_8_label(blksize, part_extent, f8);
003ee8
 	f8->DS1FMTID = 0xf8;
003ee8
 }
003ee8
 
003ee8
@@ -886,7 +882,7 @@ vtoc_reorganize_FMT5_extents (format5_label_t *f5)
003ee8
  * add a free space extent description to the VTOC FMT5 DSCB
003ee8
  */
003ee8
 void
003ee8
-vtoc_update_format5_label_add (format5_label_t *f5, int verbose, int cyl,
003ee8
+vtoc_update_format5_label_add (format5_label_t *f5, int verbose,
003ee8
                                int trk, u_int16_t a, u_int16_t b, u_int8_t c)
003ee8
 {
003ee8
 	PDEBUG
003ee8
@@ -974,7 +970,7 @@ vtoc_update_format5_label_add (format5_label_t *f5, int verbose, int cyl,
003ee8
  * remove a free space extent description from the VTOC FMT5 DSCB
003ee8
  */
003ee8
 void
003ee8
-vtoc_update_format5_label_del (format5_label_t *f5, int verbose, int cyl,
003ee8
+vtoc_update_format5_label_del (format5_label_t *f5, int verbose,
003ee8
                                int trk, u_int16_t a, u_int16_t b, u_int8_t c)
003ee8
 {
003ee8
 	PDEBUG
003ee8
@@ -1054,7 +1050,7 @@ vtoc_update_format5_label_del (format5_label_t *f5, int verbose, int cyl,
003ee8
 			ext->ft = (a - ext->t) % trk;
003ee8
 
003ee8
 			vtoc_update_format5_label_add(f5, verbose,
003ee8
-						      cyl, trk, x, y, z);
003ee8
+						      trk, x, y, z);
003ee8
 
003ee8
 			if (verbose)
003ee8
 				puts ("FMT5 del extent: 2 pieces");
003ee8
@@ -1322,9 +1318,9 @@ vtoc_set_freespace(format4_label_t *f4, format5_label_t *f5,
003ee8
 		z =  (u_int8_t) ((stop - start + 1) % trk);
003ee8
 
003ee8
 		if (ch == '+')
003ee8
-			vtoc_update_format5_label_add(f5, verbose, cyl, trk, x, y, z);
003ee8
+			vtoc_update_format5_label_add(f5, verbose, trk, x, y, z);
003ee8
 		else if (ch == '-')
003ee8
-			vtoc_update_format5_label_del(f5, verbose, cyl, trk, x, y, z);
003ee8
+			vtoc_update_format5_label_del(f5, verbose, trk, x, y, z);
003ee8
 		else
003ee8
 			puts ("BUG: syntax error in vtoc_set_freespace call");
003ee8
 
003ee8
-- 
003ee8
2.9.3
003ee8