Skip to content

Commit bf1a95a

Browse files
stefan-haberlandMartin Schwidefsky
authored andcommitted
[S390] fixed cdl-format detection.
CDL formated DASDs are now detected correctly even if no VOL1 label is on the disk. This prevents possible loss of data. Signed-off-by: Stefan Haberland <stefan.haberland@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 83119ad commit bf1a95a

1 file changed

Lines changed: 97 additions & 70 deletions

File tree

‎fs/partitions/ibm.c‎

Lines changed: 97 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
4545
{
4646
int blocksize, offset, size,res;
4747
loff_t i_size;
48-
dasd_information_t *info;
48+
dasd_information2_t *info;
4949
struct hd_geometry *geo;
5050
char type[5] = {0,};
5151
char name[7] = {0,};
@@ -64,14 +64,17 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
6464
if (i_size == 0)
6565
goto out_exit;
6666

67-
if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
67+
info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
68+
if (info == NULL)
6869
goto out_exit;
69-
if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
70+
geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL);
71+
if (geo == NULL)
7072
goto out_nogeo;
71-
if ((label = kmalloc(sizeof(union label_t), GFP_KERNEL)) == NULL)
73+
label = kmalloc(sizeof(union label_t), GFP_KERNEL);
74+
if (label == NULL)
7275
goto out_nolab;
7376

74-
if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
77+
if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0 ||
7578
ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
7679
goto out_freeall;
7780

@@ -96,84 +99,108 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
9699
res = 1;
97100

98101
/*
99-
* Three different types: CMS1, VOL1 and LNX1/unlabeled
102+
* Three different formats: LDL, CDL and unformated disk
103+
*
104+
* identified by info->format
105+
*
106+
* unformated disks we do not have to care about
100107
*/
101-
if (strncmp(type, "CMS1", 4) == 0) {
102-
/*
103-
* VM style CMS1 labeled disk
104-
*/
105-
if (label->cms.disk_offset != 0) {
106-
printk("CMS1/%8s(MDSK):", name);
107-
/* disk is reserved minidisk */
108-
blocksize = label->cms.block_size;
109-
offset = label->cms.disk_offset;
110-
size = (label->cms.block_count - 1) * (blocksize >> 9);
108+
if (info->format == DASD_FORMAT_LDL) {
109+
if (strncmp(type, "CMS1", 4) == 0) {
110+
/*
111+
* VM style CMS1 labeled disk
112+
*/
113+
if (label->cms.disk_offset != 0) {
114+
printk("CMS1/%8s(MDSK):", name);
115+
/* disk is reserved minidisk */
116+
blocksize = label->cms.block_size;
117+
offset = label->cms.disk_offset;
118+
size = (label->cms.block_count - 1)
119+
* (blocksize >> 9);
120+
} else {
121+
printk("CMS1/%8s:", name);
122+
offset = (info->label_block + 1);
123+
size = i_size >> 9;
124+
}
111125
} else {
112-
printk("CMS1/%8s:", name);
126+
/*
127+
* Old style LNX1 or unlabeled disk
128+
*/
129+
if (strncmp(type, "LNX1", 4) == 0)
130+
printk ("LNX1/%8s:", name);
131+
else
132+
printk("(nonl)");
113133
offset = (info->label_block + 1);
114134
size = i_size >> 9;
115135
}
116136
put_partition(state, 1, offset*(blocksize >> 9),
117-
size-offset*(blocksize >> 9));
118-
} else if ((strncmp(type, "VOL1", 4) == 0) &&
119-
(!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
137+
size-offset*(blocksize >> 9));
138+
} else if (info->format == DASD_FORMAT_CDL) {
120139
/*
121-
* New style VOL1 labeled disk
140+
* New style CDL formatted disk
122141
*/
123142
unsigned int blk;
124143
int counter;
125144

126-
printk("VOL1/%8s:", name);
127-
128-
/* get block number and read then go through format1 labels */
129-
blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
130-
counter = 0;
131-
while ((data = read_dev_sector(bdev, blk*(blocksize/512),
132-
&sect)) != NULL) {
133-
struct vtoc_format1_label f1;
134-
135-
memcpy(&f1, data, sizeof(struct vtoc_format1_label));
136-
put_dev_sector(sect);
137-
138-
/* skip FMT4 / FMT5 / FMT7 labels */
139-
if (f1.DS1FMTID == _ascebc['4']
140-
|| f1.DS1FMTID == _ascebc['5']
141-
|| f1.DS1FMTID == _ascebc['7']) {
142-
blk++;
143-
continue;
144-
}
145-
146-
/* only FMT1 valid at this point */
147-
if (f1.DS1FMTID != _ascebc['1'])
148-
break;
149-
150-
/* OK, we got valid partition data */
151-
offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
152-
size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
153-
offset + geo->sectors;
154-
if (counter >= state->limit)
155-
break;
156-
put_partition(state, counter + 1,
157-
offset * (blocksize >> 9),
158-
size * (blocksize >> 9));
159-
counter++;
160-
blk++;
161-
}
162-
if (!data)
163-
/* Are we not supposed to report this ? */
164-
goto out_readerr;
165-
} else {
166145
/*
167-
* Old style LNX1 or unlabeled disk
146+
* check if VOL1 label is available
147+
* if not, something is wrong, skipping partition detection
168148
*/
169-
if (strncmp(type, "LNX1", 4) == 0)
170-
printk ("LNX1/%8s:", name);
171-
else
172-
printk("(nonl)/%8s:", name);
173-
offset = (info->label_block + 1);
174-
size = i_size >> 9;
175-
put_partition(state, 1, offset*(blocksize >> 9),
176-
size-offset*(blocksize >> 9));
149+
if (strncmp(type, "VOL1", 4) == 0) {
150+
printk("VOL1/%8s:", name);
151+
/*
152+
* get block number and read then go through format1
153+
* labels
154+
*/
155+
blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
156+
counter = 0;
157+
data = read_dev_sector(bdev, blk * (blocksize/512),
158+
&sect);
159+
while (data != NULL) {
160+
struct vtoc_format1_label f1;
161+
162+
memcpy(&f1, data,
163+
sizeof(struct vtoc_format1_label));
164+
put_dev_sector(sect);
165+
166+
/* skip FMT4 / FMT5 / FMT7 labels */
167+
if (f1.DS1FMTID == _ascebc['4']
168+
|| f1.DS1FMTID == _ascebc['5']
169+
|| f1.DS1FMTID == _ascebc['7']) {
170+
blk++;
171+
data = read_dev_sector(bdev, blk *
172+
(blocksize/512),
173+
&sect);
174+
continue;
175+
}
176+
177+
/* only FMT1 valid at this point */
178+
if (f1.DS1FMTID != _ascebc['1'])
179+
break;
180+
181+
/* OK, we got valid partition data */
182+
offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
183+
size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
184+
offset + geo->sectors;
185+
if (counter >= state->limit)
186+
break;
187+
put_partition(state, counter + 1,
188+
offset * (blocksize >> 9),
189+
size * (blocksize >> 9));
190+
counter++;
191+
blk++;
192+
data = read_dev_sector(bdev,
193+
blk * (blocksize/512),
194+
&sect);
195+
}
196+
197+
if (!data)
198+
/* Are we not supposed to report this ? */
199+
goto out_readerr;
200+
} else
201+
printk(KERN_WARNING "Warning, expected Label VOL1 not "
202+
"found, treating as CDL formated Disk");
203+
177204
}
178205

179206
printk("\n");

0 commit comments

Comments
 (0)