]> git.pld-linux.org Git - packages/parted.git/blob - 0060-libparted-dasd-add-new-fdasd-functions.patch
- rel 4; tons of patches from FC
[packages/parted.git] / 0060-libparted-dasd-add-new-fdasd-functions.patch
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
5
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.
8
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
14
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>
18 ---
19  include/parted/fdasd.in.h |   4 ++
20  libparted/labels/fdasd.c  | 123 ++++++++++++++++++++++++++++++++++++++++++++++
21  2 files changed, 127 insertions(+)
22
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);
35  
36  #endif /* FDASD_H */
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,
42         return p;
43  }
44  
45 +/*
46 + * Check for valid volume serial characters (max. 6) - remove invalid.
47 + * If volser is empty, fill with default volser.
48 + */
49 +void fdasd_check_volser (char *volser, int devno)
50 +{
51 +       int from, to;
52 +
53 +       for (from = 0, to = 0; volser[from] && from < VOLSER_LENGTH; from++) {
54 +
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]);
64 +       }
65 +
66 +       volser[to] = 0x00;
67 +
68 +       if (volser[0] == 0x00)
69 +               sprintf(volser, "0X%04x", devno);
70 +}
71 +
72 +/*
73 + * get volser from vtoc
74 + */
75 +int fdasd_get_volser (fdasd_anchor_t *anc, char *volser, int fd)
76 +{
77 +       volume_label_t vlabel;
78 +
79 +       vtoc_read_volume_label(fd, anc->label_pos, &vlabel);
80 +       vtoc_volume_label_get_volser(&vlabel, volser);
81 +       return 0;
82 +}
83 +
84 +/* Changes the volume serial (menu option)
85 + *
86 + */
87 +void fdasd_change_volser (fdasd_anchor_t *anc, char *str)
88 +{
89 +       fdasd_check_volser(str, anc->devno);
90 +       vtoc_volume_label_set_volser(anc->vlabel, str);
91 +
92 +       vtoc_set_cchhb(&anc->vlabel->vtoc, VTOC_START_CC, VTOC_START_HH, 0x01);
93 +       anc->vlabel_changed++;
94 +       anc->vtoc_changed++;
95 +}
96 +
97 +/*
98 + * re-create all VTOC labels, but use the partition information
99 + * from existing VTOC
100 + */
101 +void fdasd_reuse_vtoc (fdasd_anchor_t *anc)
102 +{
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;
109 +
110 +       vtoc_init_format4_label(&f4, geo.cylinders, anc->formatted_cylinders,
111 +                               geo.heads, geo.sectors,
112 +                               anc->blksize, anc->dev_type);
113 +
114 +       /* reuse some FMT4 values */
115 +       f4.DS4HPCHR = anc->f4->DS4HPCHR;
116 +       f4.DS4DSREC = anc->f4->DS4DSREC;
117 +
118 +       /* re-initialize both free-space labels */
119 +       vtoc_init_format5_label(&f5);
120 +       vtoc_init_format7_label(&f7);
121 +
122 +       if (anc->fspace_trk > 0)
123 +               vtoc_set_freespace(&f4, &f5, &f7, '+', anc->verbose,
124 +                                  FIRST_USABLE_TRK,
125 +                                  FIRST_USABLE_TRK + anc->fspace_trk - 1,
126 +                                  anc->formatted_cylinders, geo.heads);
127 +
128 +       while (part_info != NULL) {
129 +               if (part_info->used != 0x01) {
130 +                       part_info = part_info->next;
131 +                       continue;
132 +               }
133 +
134 +               if (anc->formatted_cylinders > LV_COMPAT_CYL)
135 +                       vtoc_init_format8_label(anc->blksize,
136 +                                               &part_info->f1->DS1EXT1, &f1);
137 +               else
138 +                       vtoc_init_format1_label(anc->blksize,
139 +                                               &part_info->f1->DS1EXT1, &f1);
140 +
141 +
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;
145 +
146 +               memcpy(part_info->f1, &f1, sizeof(format1_label_t));
147 +
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);
154 +
155 +               part_info = part_info->next;
156 +       }
157 +
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));
162 +
163 +       anc->vtoc_changed++;
164 +
165 +       return;
166 +}
167 +
168  /* vim:set tabstop=4 shiftwidth=4 softtabstop=4: */
169 -- 
170 2.9.3
171
This page took 0.077889 seconds and 3 git commands to generate.