|
|
003ee8 |
From 3267b55ff764840cf267fd1e02fa467e4d87d388 Mon Sep 17 00:00:00 2001
|
|
|
003ee8 |
From: Wang Dong <dongdwdw@linux.vnet.ibm.com>
|
|
|
003ee8 |
Date: Wed, 26 Oct 2016 04:22:48 +0200
|
|
|
003ee8 |
Subject: [PATCH 60/75] libparted/dasd: add new fdasd functions
|
|
|
003ee8 |
|
|
|
003ee8 |
Introduce a set of new functions from the fdasd utility of the s390-tools
|
|
|
003ee8 |
to keep the code base in parted and s390-tools in sync.
|
|
|
003ee8 |
|
|
|
003ee8 |
These new functions are:
|
|
|
003ee8 |
fdasd_check_volser(): validate the volser input
|
|
|
003ee8 |
fdasd_get_volser(): get volume serial (volser)
|
|
|
003ee8 |
fdasd_change_volser(): change volser with string
|
|
|
003ee8 |
fdasd_reuse_vtoc(): re-create vtoc labels based on the existing vtoc
|
|
|
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/fdasd.in.h | 4 ++
|
|
|
003ee8 |
libparted/labels/fdasd.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
003ee8 |
2 files changed, 127 insertions(+)
|
|
|
003ee8 |
|
|
|
003ee8 |
diff --git a/include/parted/fdasd.in.h b/include/parted/fdasd.in.h
|
|
|
003ee8 |
index 09a35a0..9e5d7d1 100644
|
|
|
003ee8 |
--- a/include/parted/fdasd.in.h
|
|
|
003ee8 |
+++ b/include/parted/fdasd.in.h
|
|
|
003ee8 |
@@ -293,5 +293,9 @@ void fdasd_recreate_vtoc(fdasd_anchor_t *anc);
|
|
|
003ee8 |
partition_info_t * fdasd_add_partition (fdasd_anchor_t *anc,
|
|
|
003ee8 |
unsigned int start, unsigned int stop);
|
|
|
003ee8 |
int fdasd_prepare_labels (fdasd_anchor_t *anc, int fd) ;
|
|
|
003ee8 |
+void fdasd_check_volser(char *volser, int devno);
|
|
|
003ee8 |
+int fdasd_get_volser(fdasd_anchor_t *anc, char *volser, int fd);
|
|
|
003ee8 |
+void fdasd_change_volser(fdasd_anchor_t *anc, char *str);
|
|
|
003ee8 |
+void fdasd_reuse_vtoc(fdasd_anchor_t *anc);
|
|
|
003ee8 |
|
|
|
003ee8 |
#endif /* FDASD_H */
|
|
|
003ee8 |
diff --git a/libparted/labels/fdasd.c b/libparted/labels/fdasd.c
|
|
|
003ee8 |
index e5df5cf..713ed6b 100644
|
|
|
003ee8 |
--- a/libparted/labels/fdasd.c
|
|
|
003ee8 |
+++ b/libparted/labels/fdasd.c
|
|
|
003ee8 |
@@ -1320,4 +1320,127 @@ fdasd_add_partition (fdasd_anchor_t *anc, unsigned int start,
|
|
|
003ee8 |
return p;
|
|
|
003ee8 |
}
|
|
|
003ee8 |
|
|
|
003ee8 |
+/*
|
|
|
003ee8 |
+ * Check for valid volume serial characters (max. 6) - remove invalid.
|
|
|
003ee8 |
+ * If volser is empty, fill with default volser.
|
|
|
003ee8 |
+ */
|
|
|
003ee8 |
+void fdasd_check_volser (char *volser, int devno)
|
|
|
003ee8 |
+{
|
|
|
003ee8 |
+ int from, to;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ for (from = 0, to = 0; volser[from] && from < VOLSER_LENGTH; from++) {
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ if ((volser[from] >= 0x23 &&
|
|
|
003ee8 |
+ volser[from] <= 0x25) ||
|
|
|
003ee8 |
+ (volser[from] >= 0x30 &&
|
|
|
003ee8 |
+ volser[from] <= 0x39) ||
|
|
|
003ee8 |
+ (volser[from] >= 0x40 &&
|
|
|
003ee8 |
+ volser[from] <= 0x5a) ||
|
|
|
003ee8 |
+ (volser[from] >= 0x61 &&
|
|
|
003ee8 |
+ volser[from] <= 0x7a))
|
|
|
003ee8 |
+ volser[to++] = toupper(volser[from]);
|
|
|
003ee8 |
+ }
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ volser[to] = 0x00;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ if (volser[0] == 0x00)
|
|
|
003ee8 |
+ sprintf(volser, "0X%04x", devno);
|
|
|
003ee8 |
+}
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+/*
|
|
|
003ee8 |
+ * get volser from vtoc
|
|
|
003ee8 |
+ */
|
|
|
003ee8 |
+int fdasd_get_volser (fdasd_anchor_t *anc, char *volser, int fd)
|
|
|
003ee8 |
+{
|
|
|
003ee8 |
+ volume_label_t vlabel;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ vtoc_read_volume_label(fd, anc->label_pos, &vlabel);
|
|
|
003ee8 |
+ vtoc_volume_label_get_volser(&vlabel, volser);
|
|
|
003ee8 |
+ return 0;
|
|
|
003ee8 |
+}
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+/* Changes the volume serial (menu option)
|
|
|
003ee8 |
+ *
|
|
|
003ee8 |
+ */
|
|
|
003ee8 |
+void fdasd_change_volser (fdasd_anchor_t *anc, char *str)
|
|
|
003ee8 |
+{
|
|
|
003ee8 |
+ fdasd_check_volser(str, anc->devno);
|
|
|
003ee8 |
+ vtoc_volume_label_set_volser(anc->vlabel, str);
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ vtoc_set_cchhb(&anc->vlabel->vtoc, VTOC_START_CC, VTOC_START_HH, 0x01);
|
|
|
003ee8 |
+ anc->vlabel_changed++;
|
|
|
003ee8 |
+ anc->vtoc_changed++;
|
|
|
003ee8 |
+}
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+/*
|
|
|
003ee8 |
+ * re-create all VTOC labels, but use the partition information
|
|
|
003ee8 |
+ * from existing VTOC
|
|
|
003ee8 |
+ */
|
|
|
003ee8 |
+void fdasd_reuse_vtoc (fdasd_anchor_t *anc)
|
|
|
003ee8 |
+{
|
|
|
003ee8 |
+ partition_info_t *part_info = anc->first;
|
|
|
003ee8 |
+ struct fdasd_hd_geometry geo = anc->geo;
|
|
|
003ee8 |
+ format1_label_t f1;
|
|
|
003ee8 |
+ format4_label_t f4;
|
|
|
003ee8 |
+ format5_label_t f5;
|
|
|
003ee8 |
+ format7_label_t f7;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ vtoc_init_format4_label(&f4, geo.cylinders, anc->formatted_cylinders,
|
|
|
003ee8 |
+ geo.heads, geo.sectors,
|
|
|
003ee8 |
+ anc->blksize, anc->dev_type);
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ /* reuse some FMT4 values */
|
|
|
003ee8 |
+ f4.DS4HPCHR = anc->f4->DS4HPCHR;
|
|
|
003ee8 |
+ f4.DS4DSREC = anc->f4->DS4DSREC;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ /* re-initialize both free-space labels */
|
|
|
003ee8 |
+ vtoc_init_format5_label(&f5;;
|
|
|
003ee8 |
+ vtoc_init_format7_label(&f7;;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ if (anc->fspace_trk > 0)
|
|
|
003ee8 |
+ vtoc_set_freespace(&f4, &f5, &f7, '+', anc->verbose,
|
|
|
003ee8 |
+ FIRST_USABLE_TRK,
|
|
|
003ee8 |
+ FIRST_USABLE_TRK + anc->fspace_trk - 1,
|
|
|
003ee8 |
+ anc->formatted_cylinders, geo.heads);
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ while (part_info != NULL) {
|
|
|
003ee8 |
+ if (part_info->used != 0x01) {
|
|
|
003ee8 |
+ part_info = part_info->next;
|
|
|
003ee8 |
+ continue;
|
|
|
003ee8 |
+ }
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ if (anc->formatted_cylinders > LV_COMPAT_CYL)
|
|
|
003ee8 |
+ vtoc_init_format8_label(anc->blksize,
|
|
|
003ee8 |
+ &part_info->f1->DS1EXT1, &f1;;
|
|
|
003ee8 |
+ else
|
|
|
003ee8 |
+ vtoc_init_format1_label(anc->blksize,
|
|
|
003ee8 |
+ &part_info->f1->DS1EXT1, &f1;;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ strncpy(f1.DS1DSNAM, part_info->f1->DS1DSNAM, 44);
|
|
|
003ee8 |
+ strncpy((char *)f1.DS1DSSN, (char *)part_info->f1->DS1DSSN, 6);
|
|
|
003ee8 |
+ f1.DS1CREDT = part_info->f1->DS1CREDT;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ memcpy(part_info->f1, &f1, sizeof(format1_label_t));
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ if (part_info->fspace_trk > 0)
|
|
|
003ee8 |
+ vtoc_set_freespace(&f4, &f5, &f7, '+', anc->verbose,
|
|
|
003ee8 |
+ part_info->end_trk + 1,
|
|
|
003ee8 |
+ part_info->end_trk +
|
|
|
003ee8 |
+ part_info->fspace_trk,
|
|
|
003ee8 |
+ anc->formatted_cylinders, geo.heads);
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ part_info = part_info->next;
|
|
|
003ee8 |
+ }
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ /* over-write old labels with new ones */
|
|
|
003ee8 |
+ memcpy(anc->f4, &f4, sizeof(format4_label_t));
|
|
|
003ee8 |
+ memcpy(anc->f5, &f5, sizeof(format5_label_t));
|
|
|
003ee8 |
+ memcpy(anc->f7, &f7, sizeof(format7_label_t));
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ anc->vtoc_changed++;
|
|
|
003ee8 |
+
|
|
|
003ee8 |
+ return;
|
|
|
003ee8 |
+}
|
|
|
003ee8 |
+
|
|
|
003ee8 |
/* vim:set tabstop=4 shiftwidth=4 softtabstop=4: */
|
|
|
003ee8 |
--
|
|
|
003ee8 |
2.9.3
|
|
|
003ee8 |
|