2 * File...........: linux/fs/partitions/ibm.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Volker Sameske <sameske@de.ibm.com>
5 * Bugreports.to..: <Linux390@de.ibm.com>
6 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
8 * History of changes (starts July 2000)
9 * 07/10/00 Fixed detection of CMS formatted disks
10 * 02/13/00 VTOC partition support added
11 * 12/27/01 fixed PL030593 (CMS reserved minidisk not detected on 64 bit)
12 * 07/24/03 no longer using contents of freed page for CMS label recognition (BZ3611)
15 #include <linux/config.h>
16 #include <linux/buffer_head.h>
17 #include <linux/hdreg.h>
18 #include <linux/slab.h>
20 #include <asm/ebcdic.h>
21 #include <asm/uaccess.h>
28 * compute the block number from a
29 * cyl-cyl-head-head structure
32 cchh2blk (cchh_t
*ptr
, struct hd_geometry
*geo
) {
33 return ptr
->cc
* geo
->heads
* geo
->sectors
+
34 ptr
->hh
* geo
->sectors
;
39 * compute the block number from a
40 * cyl-cyl-head-head-block structure
43 cchhb2blk (cchhb_t
*ptr
, struct hd_geometry
*geo
) {
44 return ptr
->cc
* geo
->heads
* geo
->sectors
+
45 ptr
->hh
* geo
->sectors
+
52 ibm_partition(struct parsed_partitions
*state
, struct block_device
*bdev
)
54 int blocksize
, offset
, size
;
55 dasd_information_t
*info
;
56 struct hd_geometry
*geo
;
59 volume_label_t
*vlabel
;
63 if ((info
= kmalloc(sizeof(dasd_information_t
), GFP_KERNEL
)) == NULL
)
65 if ((geo
= kmalloc(sizeof(struct hd_geometry
), GFP_KERNEL
)) == NULL
)
67 if ((vlabel
= kmalloc(sizeof(volume_label_t
), GFP_KERNEL
)) == NULL
)
70 if (ioctl_by_bdev(bdev
, BIODASDINFO
, (unsigned long)info
) != 0 ||
71 ioctl_by_bdev(bdev
, HDIO_GETGEO
, (unsigned long)geo
) != 0)
74 if ((blocksize
= bdev_hardsect_size(bdev
)) <= 0)
78 * Get volume label, extract name and type.
80 data
= read_dev_sector(bdev
, info
->label_block
*(blocksize
/512), §
);
84 strncpy (type
, data
, 4);
85 if ((!info
->FBA_layout
) && (!strcmp(info
->type
, "ECKD")))
86 strncpy(name
, data
+ 8, 6);
88 strncpy(name
, data
+ 4, 6);
89 memcpy (vlabel
, data
, sizeof(volume_label_t
));
96 * Three different types: CMS1, VOL1 and LNX1/unlabeled
98 if (strncmp(type
, "CMS1", 4) == 0) {
100 * VM style CMS1 labeled disk
102 int *label
= (int *) vlabel
;
104 if (label
[13] != 0) {
105 printk("CMS1/%8s(MDSK):", name
);
106 /* disk is reserved minidisk */
107 blocksize
= label
[3];
109 size
= (label
[7] - 1)*(blocksize
>> 9);
111 printk("CMS1/%8s:", name
);
112 offset
= (info
->label_block
+ 1);
113 size
= bdev
->bd_inode
->i_size
>> 9;
115 put_partition(state
, 1, offset
*(blocksize
>> 9),
116 size
-offset
*(blocksize
>> 9));
117 } else if ((strncmp(type
, "VOL1", 4) == 0) &&
118 (!info
->FBA_layout
) && (!strcmp(info
->type
, "ECKD"))) {
120 * New style VOL1 labeled disk
125 printk("VOL1/%8s:", name
);
127 /* get block number and read then go through format1 labels */
128 blk
= cchhb2blk(&vlabel
->vtoc
, geo
) + 1;
130 while ((data
= read_dev_sector(bdev
, blk
*(blocksize
/512),
134 memcpy(&f1
, data
, sizeof(format1_label_t
));
135 put_dev_sector(sect
);
137 /* skip FMT4 / FMT5 / FMT7 labels */
138 if (f1
.DS1FMTID
== _ascebc
['4']
139 || f1
.DS1FMTID
== _ascebc
['5']
140 || f1
.DS1FMTID
== _ascebc
['7']) {
145 /* only FMT1 valid at this point */
146 if (f1
.DS1FMTID
!= _ascebc
['1'])
149 /* OK, we got valid partition data */
150 offset
= cchh2blk(&f1
.DS1EXT1
.llimit
, geo
);
151 size
= cchh2blk(&f1
.DS1EXT1
.ulimit
, geo
) -
152 offset
+ geo
->sectors
;
153 if (counter
>= state
->limit
)
155 put_partition(state
, counter
+ 1,
156 offset
* (blocksize
>> 9),
157 size
* (blocksize
>> 9));
163 * Old style LNX1 or unlabeled disk
165 if (strncmp(type
, "LNX1", 4) == 0)
166 printk ("LNX1/%8s:", name
);
168 printk("(nonl)/%8s:", name
);
169 offset
= (info
->label_block
+ 1);
170 size
= (bdev
->bd_inode
->i_size
>> 9);
171 put_partition(state
, 1, offset
*(blocksize
>> 9),
172 size
-offset
*(blocksize
>> 9));