blob: 6327bcb2d73df0d99b90dbde3a14e7958e7de330 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
7
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)
13 */
14
15#include <linux/config.h>
16#include <linux/buffer_head.h>
17#include <linux/hdreg.h>
18#include <linux/slab.h>
19#include <asm/dasd.h>
20#include <asm/ebcdic.h>
21#include <asm/uaccess.h>
22#include <asm/vtoc.h>
23
24#include "check.h"
25#include "ibm.h"
26
27/*
28 * compute the block number from a
29 * cyl-cyl-head-head structure
30 */
31static inline int
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -080032cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 return ptr->cc * geo->heads * geo->sectors +
34 ptr->hh * geo->sectors;
35}
36
37
38/*
39 * compute the block number from a
40 * cyl-cyl-head-head-block structure
41 */
42static inline int
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -080043cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 return ptr->cc * geo->heads * geo->sectors +
45 ptr->hh * geo->sectors +
46 ptr->b;
47}
48
49/*
50 */
51int
52ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
53{
54 int blocksize, offset, size;
55 dasd_information_t *info;
56 struct hd_geometry *geo;
57 char type[5] = {0,};
58 char name[7] = {0,};
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -080059 struct vtoc_volume_label *vlabel;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unsigned char *data;
61 Sector sect;
62
63 if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
64 goto out_noinfo;
65 if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
66 goto out_nogeo;
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -080067 if ((vlabel = kmalloc(sizeof(struct vtoc_volume_label),
68 GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 goto out_novlab;
70
71 if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
72 ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
73 goto out_noioctl;
74
75 if ((blocksize = bdev_hardsect_size(bdev)) <= 0)
76 goto out_badsect;
77
78 /*
79 * Get volume label, extract name and type.
80 */
81 data = read_dev_sector(bdev, info->label_block*(blocksize/512), &sect);
82 if (data == NULL)
83 goto out_readerr;
84
85 strncpy (type, data, 4);
86 if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD")))
87 strncpy(name, data + 8, 6);
88 else
89 strncpy(name, data + 4, 6);
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -080090 memcpy (vlabel, data, sizeof(struct vtoc_volume_label));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 put_dev_sector(sect);
92
93 EBCASC(type, 4);
94 EBCASC(name, 6);
95
96 /*
97 * Three different types: CMS1, VOL1 and LNX1/unlabeled
98 */
99 if (strncmp(type, "CMS1", 4) == 0) {
100 /*
101 * VM style CMS1 labeled disk
102 */
103 int *label = (int *) vlabel;
104
105 if (label[13] != 0) {
106 printk("CMS1/%8s(MDSK):", name);
107 /* disk is reserved minidisk */
108 blocksize = label[3];
109 offset = label[13];
110 size = (label[7] - 1)*(blocksize >> 9);
111 } else {
112 printk("CMS1/%8s:", name);
113 offset = (info->label_block + 1);
114 size = bdev->bd_inode->i_size >> 9;
115 }
116 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"))) {
120 /*
121 * New style VOL1 labeled disk
122 */
123 unsigned int blk;
124 int counter;
125
126 printk("VOL1/%8s:", name);
127
128 /* get block number and read then go through format1 labels */
129 blk = cchhb2blk(&vlabel->vtoc, geo) + 1;
130 counter = 0;
131 while ((data = read_dev_sector(bdev, blk*(blocksize/512),
132 &sect)) != NULL) {
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -0800133 struct vtoc_format1_label f1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -0800135 memcpy(&f1, data, sizeof(struct vtoc_format1_label));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 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 } else {
163 /*
164 * Old style LNX1 or unlabeled disk
165 */
166 if (strncmp(type, "LNX1", 4) == 0)
167 printk ("LNX1/%8s:", name);
168 else
169 printk("(nonl)/%8s:", name);
170 offset = (info->label_block + 1);
171 size = (bdev->bd_inode->i_size >> 9);
172 put_partition(state, 1, offset*(blocksize >> 9),
173 size-offset*(blocksize >> 9));
174 }
175
176 printk("\n");
177 kfree(vlabel);
178 kfree(geo);
179 kfree(info);
180 return 1;
181
182out_readerr:
183out_badsect:
184out_noioctl:
185 kfree(vlabel);
186out_novlab:
187 kfree(geo);
188out_nogeo:
189 kfree(info);
190out_noinfo:
191 return 0;
192}