perf: Better fit max unprivileged mlock pages for tools needs
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / partitions / ibm.c
blobbae725b7febd3019772b21e97e16832c06875d80
1 /*
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 */
9 #include <linux/buffer_head.h>
10 #include <linux/hdreg.h>
11 #include <linux/slab.h>
12 #include <asm/dasd.h>
13 #include <asm/ebcdic.h>
14 #include <asm/uaccess.h>
15 #include <asm/vtoc.h>
17 #include "check.h"
18 #include "ibm.h"
21 * compute the block number from a
22 * cyl-cyl-head-head structure
24 static sector_t
25 cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
27 sector_t cyl;
28 __u16 head;
30 /*decode cylinder and heads for large volumes */
31 cyl = ptr->hh & 0xFFF0;
32 cyl <<= 12;
33 cyl |= ptr->cc;
34 head = ptr->hh & 0x000F;
35 return cyl * geo->heads * geo->sectors +
36 head * geo->sectors;
40 * compute the block number from a
41 * cyl-cyl-head-head-block structure
43 static sector_t
44 cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
46 sector_t cyl;
47 __u16 head;
49 /*decode cylinder and heads for large volumes */
50 cyl = ptr->hh & 0xFFF0;
51 cyl <<= 12;
52 cyl |= ptr->cc;
53 head = ptr->hh & 0x000F;
54 return cyl * geo->heads * geo->sectors +
55 head * geo->sectors +
56 ptr->b;
61 int
62 ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
64 int blocksize, res;
65 loff_t i_size, offset, size, fmt_size;
66 dasd_information2_t *info;
67 struct hd_geometry *geo;
68 char type[5] = {0,};
69 char name[7] = {0,};
70 union label_t {
71 struct vtoc_volume_label_cdl vol;
72 struct vtoc_volume_label_ldl lnx;
73 struct vtoc_cms_label cms;
74 } *label;
75 unsigned char *data;
76 Sector sect;
77 sector_t labelsect;
79 res = 0;
80 blocksize = bdev_logical_block_size(bdev);
81 if (blocksize <= 0)
82 goto out_exit;
83 i_size = i_size_read(bdev->bd_inode);
84 if (i_size == 0)
85 goto out_exit;
87 info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
88 if (info == NULL)
89 goto out_exit;
90 geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL);
91 if (geo == NULL)
92 goto out_nogeo;
93 label = kmalloc(sizeof(union label_t), GFP_KERNEL);
94 if (label == NULL)
95 goto out_nolab;
97 if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0 ||
98 ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
99 goto out_freeall;
102 * Special case for FBA disks: label sector does not depend on
103 * blocksize.
105 if ((info->cu_type == 0x6310 && info->dev_type == 0x9336) ||
106 (info->cu_type == 0x3880 && info->dev_type == 0x3370))
107 labelsect = info->label_block;
108 else
109 labelsect = info->label_block * (blocksize >> 9);
112 * Get volume label, extract name and type.
114 data = read_dev_sector(bdev, labelsect, &sect);
115 if (data == NULL)
116 goto out_readerr;
118 memcpy(label, data, sizeof(union label_t));
119 put_dev_sector(sect);
121 if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
122 strncpy(type, label->vol.vollbl, 4);
123 strncpy(name, label->vol.volid, 6);
124 } else {
125 strncpy(type, label->lnx.vollbl, 4);
126 strncpy(name, label->lnx.volid, 6);
128 EBCASC(type, 4);
129 EBCASC(name, 6);
131 res = 1;
134 * Three different formats: LDL, CDL and unformated disk
136 * identified by info->format
138 * unformated disks we do not have to care about
140 if (info->format == DASD_FORMAT_LDL) {
141 if (strncmp(type, "CMS1", 4) == 0) {
143 * VM style CMS1 labeled disk
145 blocksize = label->cms.block_size;
146 if (label->cms.disk_offset != 0) {
147 printk("CMS1/%8s(MDSK):", name);
148 /* disk is reserved minidisk */
149 offset = label->cms.disk_offset;
150 size = (label->cms.block_count - 1)
151 * (blocksize >> 9);
152 } else {
153 printk("CMS1/%8s:", name);
154 offset = (info->label_block + 1);
155 size = label->cms.block_count
156 * (blocksize >> 9);
158 put_partition(state, 1, offset*(blocksize >> 9),
159 size-offset*(blocksize >> 9));
160 } else {
161 if (strncmp(type, "LNX1", 4) == 0) {
162 printk("LNX1/%8s:", name);
163 if (label->lnx.ldl_version == 0xf2) {
164 fmt_size = label->lnx.formatted_blocks
165 * (blocksize >> 9);
166 } else if (!strcmp(info->type, "ECKD")) {
167 /* formated w/o large volume support */
168 fmt_size = geo->cylinders * geo->heads
169 * geo->sectors * (blocksize >> 9);
170 } else {
171 /* old label and no usable disk geometry
172 * (e.g. DIAG) */
173 fmt_size = i_size >> 9;
175 size = i_size >> 9;
176 if (fmt_size < size)
177 size = fmt_size;
178 offset = (info->label_block + 1);
179 } else {
180 /* unlabeled disk */
181 printk("(nonl)");
182 size = i_size >> 9;
183 offset = (info->label_block + 1);
185 put_partition(state, 1, offset*(blocksize >> 9),
186 size-offset*(blocksize >> 9));
188 } else if (info->format == DASD_FORMAT_CDL) {
190 * New style CDL formatted disk
192 sector_t blk;
193 int counter;
196 * check if VOL1 label is available
197 * if not, something is wrong, skipping partition detection
199 if (strncmp(type, "VOL1", 4) == 0) {
200 printk("VOL1/%8s:", name);
202 * get block number and read then go through format1
203 * labels
205 blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
206 counter = 0;
207 data = read_dev_sector(bdev, blk * (blocksize/512),
208 &sect);
209 while (data != NULL) {
210 struct vtoc_format1_label f1;
212 memcpy(&f1, data,
213 sizeof(struct vtoc_format1_label));
214 put_dev_sector(sect);
216 /* skip FMT4 / FMT5 / FMT7 labels */
217 if (f1.DS1FMTID == _ascebc['4']
218 || f1.DS1FMTID == _ascebc['5']
219 || f1.DS1FMTID == _ascebc['7']
220 || f1.DS1FMTID == _ascebc['9']) {
221 blk++;
222 data = read_dev_sector(bdev, blk *
223 (blocksize/512),
224 &sect);
225 continue;
228 /* only FMT1 and 8 labels valid at this point */
229 if (f1.DS1FMTID != _ascebc['1'] &&
230 f1.DS1FMTID != _ascebc['8'])
231 break;
233 /* OK, we got valid partition data */
234 offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
235 size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
236 offset + geo->sectors;
237 if (counter >= state->limit)
238 break;
239 put_partition(state, counter + 1,
240 offset * (blocksize >> 9),
241 size * (blocksize >> 9));
242 counter++;
243 blk++;
244 data = read_dev_sector(bdev,
245 blk * (blocksize/512),
246 &sect);
249 if (!data)
250 /* Are we not supposed to report this ? */
251 goto out_readerr;
252 } else
253 printk(KERN_WARNING "Warning, expected Label VOL1 not "
254 "found, treating as CDL formated Disk");
258 printk("\n");
259 goto out_freeall;
262 out_readerr:
263 res = -1;
264 out_freeall:
265 kfree(label);
266 out_nolab:
267 kfree(geo);
268 out_nogeo:
269 kfree(info);
270 out_exit:
271 return res;