1 From 3267b55ff764840cf267fd1e02fa467e4d87d388 Mon Sep 17 00:00:00 2001
2 From: Wang Dong <dongdwdw@linux.vnet.ibm.com>
3 Date: Wed, 26 Oct 2016 04:22:48 +0200
4 Subject: [PATCH 60/75] libparted/dasd: add new fdasd functions
6 Introduce a set of new functions from the fdasd utility of the s390-tools
7 to keep the code base in parted and s390-tools in sync.
9 These new functions are:
10 fdasd_check_volser(): validate the volser input
11 fdasd_get_volser(): get volume serial (volser)
12 fdasd_change_volser(): change volser with string
13 fdasd_reuse_vtoc(): re-create vtoc labels based on the existing vtoc
15 Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
16 Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
17 Signed-off-by: Brian C. Lane <bcl@redhat.com>
19 include/parted/fdasd.in.h | 4 ++
20 libparted/labels/fdasd.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++
21 2 files changed, 127 insertions(+)
23 diff --git a/include/parted/fdasd.in.h b/include/parted/fdasd.in.h
24 index 09a35a0..9e5d7d1 100644
25 --- a/include/parted/fdasd.in.h
26 +++ b/include/parted/fdasd.in.h
27 @@ -293,5 +293,9 @@ void fdasd_recreate_vtoc(fdasd_anchor_t *anc);
28 partition_info_t * fdasd_add_partition (fdasd_anchor_t *anc,
29 unsigned int start, unsigned int stop);
30 int fdasd_prepare_labels (fdasd_anchor_t *anc, int fd) ;
31 +void fdasd_check_volser(char *volser, int devno);
32 +int fdasd_get_volser(fdasd_anchor_t *anc, char *volser, int fd);
33 +void fdasd_change_volser(fdasd_anchor_t *anc, char *str);
34 +void fdasd_reuse_vtoc(fdasd_anchor_t *anc);
37 diff --git a/libparted/labels/fdasd.c b/libparted/labels/fdasd.c
38 index e5df5cf..713ed6b 100644
39 --- a/libparted/labels/fdasd.c
40 +++ b/libparted/labels/fdasd.c
41 @@ -1320,4 +1320,127 @@ fdasd_add_partition (fdasd_anchor_t *anc, unsigned int start,
46 + * Check for valid volume serial characters (max. 6) - remove invalid.
47 + * If volser is empty, fill with default volser.
49 +void fdasd_check_volser (char *volser, int devno)
53 + for (from = 0, to = 0; volser[from] && from < VOLSER_LENGTH; from++) {
55 + if ((volser[from] >= 0x23 &&
56 + volser[from] <= 0x25) ||
57 + (volser[from] >= 0x30 &&
58 + volser[from] <= 0x39) ||
59 + (volser[from] >= 0x40 &&
60 + volser[from] <= 0x5a) ||
61 + (volser[from] >= 0x61 &&
62 + volser[from] <= 0x7a))
63 + volser[to++] = toupper(volser[from]);
68 + if (volser[0] == 0x00)
69 + sprintf(volser, "0X%04x", devno);
73 + * get volser from vtoc
75 +int fdasd_get_volser (fdasd_anchor_t *anc, char *volser, int fd)
77 + volume_label_t vlabel;
79 + vtoc_read_volume_label(fd, anc->label_pos, &vlabel);
80 + vtoc_volume_label_get_volser(&vlabel, volser);
84 +/* Changes the volume serial (menu option)
87 +void fdasd_change_volser (fdasd_anchor_t *anc, char *str)
89 + fdasd_check_volser(str, anc->devno);
90 + vtoc_volume_label_set_volser(anc->vlabel, str);
92 + vtoc_set_cchhb(&anc->vlabel->vtoc, VTOC_START_CC, VTOC_START_HH, 0x01);
93 + anc->vlabel_changed++;
94 + anc->vtoc_changed++;
98 + * re-create all VTOC labels, but use the partition information
99 + * from existing VTOC
101 +void fdasd_reuse_vtoc (fdasd_anchor_t *anc)
103 + partition_info_t *part_info = anc->first;
104 + struct fdasd_hd_geometry geo = anc->geo;
105 + format1_label_t f1;
106 + format4_label_t f4;
107 + format5_label_t f5;
108 + format7_label_t f7;
110 + vtoc_init_format4_label(&f4, geo.cylinders, anc->formatted_cylinders,
111 + geo.heads, geo.sectors,
112 + anc->blksize, anc->dev_type);
114 + /* reuse some FMT4 values */
115 + f4.DS4HPCHR = anc->f4->DS4HPCHR;
116 + f4.DS4DSREC = anc->f4->DS4DSREC;
118 + /* re-initialize both free-space labels */
119 + vtoc_init_format5_label(&f5);
120 + vtoc_init_format7_label(&f7);
122 + if (anc->fspace_trk > 0)
123 + vtoc_set_freespace(&f4, &f5, &f7, '+', anc->verbose,
125 + FIRST_USABLE_TRK + anc->fspace_trk - 1,
126 + anc->formatted_cylinders, geo.heads);
128 + while (part_info != NULL) {
129 + if (part_info->used != 0x01) {
130 + part_info = part_info->next;
134 + if (anc->formatted_cylinders > LV_COMPAT_CYL)
135 + vtoc_init_format8_label(anc->blksize,
136 + &part_info->f1->DS1EXT1, &f1);
138 + vtoc_init_format1_label(anc->blksize,
139 + &part_info->f1->DS1EXT1, &f1);
142 + strncpy(f1.DS1DSNAM, part_info->f1->DS1DSNAM, 44);
143 + strncpy((char *)f1.DS1DSSN, (char *)part_info->f1->DS1DSSN, 6);
144 + f1.DS1CREDT = part_info->f1->DS1CREDT;
146 + memcpy(part_info->f1, &f1, sizeof(format1_label_t));
148 + if (part_info->fspace_trk > 0)
149 + vtoc_set_freespace(&f4, &f5, &f7, '+', anc->verbose,
150 + part_info->end_trk + 1,
151 + part_info->end_trk +
152 + part_info->fspace_trk,
153 + anc->formatted_cylinders, geo.heads);
155 + part_info = part_info->next;
158 + /* over-write old labels with new ones */
159 + memcpy(anc->f4, &f4, sizeof(format4_label_t));
160 + memcpy(anc->f5, &f5, sizeof(format5_label_t));
161 + memcpy(anc->f7, &f7, sizeof(format7_label_t));
163 + anc->vtoc_changed++;
168 /* vim:set tabstop=4 shiftwidth=4 softtabstop=4: */