Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 2 | * File...........: linux/fs/partitions/ibm.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 16 | |
| 17 | #include "check.h" |
| 18 | #include "ibm.h" |
| 19 | |
| 20 | /* |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 21 | * compute the block number from a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * cyl-cyl-head-head structure |
| 23 | */ |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 24 | static sector_t |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 25 | cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) { |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 26 | |
| 27 | sector_t cyl; |
| 28 | __u16 head; |
| 29 | |
| 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /* |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 40 | * compute the block number from a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * cyl-cyl-head-head-block structure |
| 42 | */ |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 43 | static sector_t |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 44 | cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) { |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 45 | |
| 46 | sector_t cyl; |
| 47 | __u16 head; |
| 48 | |
| 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 + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | ptr->b; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | */ |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 61 | int ibm_partition(struct parsed_partitions *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 63 | struct block_device *bdev = state->bdev; |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 64 | int blocksize, res; |
| 65 | loff_t i_size, offset, size, fmt_size; |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 66 | dasd_information2_t *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | struct hd_geometry *geo; |
| 68 | char type[5] = {0,}; |
| 69 | char name[7] = {0,}; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 70 | union label_t { |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 71 | struct vtoc_volume_label_cdl vol; |
| 72 | struct vtoc_volume_label_ldl lnx; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 73 | struct vtoc_cms_label cms; |
| 74 | } *label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | unsigned char *data; |
| 76 | Sector sect; |
| 77 | |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 78 | res = 0; |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 79 | blocksize = bdev_logical_block_size(bdev); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 80 | if (blocksize <= 0) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 81 | goto out_exit; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 82 | i_size = i_size_read(bdev->bd_inode); |
| 83 | if (i_size == 0) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 84 | goto out_exit; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 85 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 86 | info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL); |
| 87 | if (info == NULL) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 88 | goto out_exit; |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 89 | geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL); |
| 90 | if (geo == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | goto out_nogeo; |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 92 | label = kmalloc(sizeof(union label_t), GFP_KERNEL); |
| 93 | if (label == NULL) |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 94 | goto out_nolab; |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 95 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 96 | if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 98 | goto out_freeall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Get volume label, extract name and type. |
| 102 | */ |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 103 | data = read_part_sector(state, info->label_block*(blocksize/512), |
| 104 | §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | if (data == NULL) |
| 106 | goto out_readerr; |
| 107 | |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 108 | memcpy(label, data, sizeof(union label_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | put_dev_sector(sect); |
| 110 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 111 | if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) { |
| 112 | strncpy(type, label->vol.vollbl, 4); |
| 113 | strncpy(name, label->vol.volid, 6); |
| 114 | } else { |
| 115 | strncpy(type, label->lnx.vollbl, 4); |
| 116 | strncpy(name, label->lnx.volid, 6); |
| 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | EBCASC(type, 4); |
| 119 | EBCASC(name, 6); |
| 120 | |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 121 | res = 1; |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 124 | * Three different formats: LDL, CDL and unformated disk |
| 125 | * |
| 126 | * identified by info->format |
| 127 | * |
| 128 | * unformated disks we do not have to care about |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | */ |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 130 | if (info->format == DASD_FORMAT_LDL) { |
| 131 | if (strncmp(type, "CMS1", 4) == 0) { |
| 132 | /* |
| 133 | * VM style CMS1 labeled disk |
| 134 | */ |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 135 | blocksize = label->cms.block_size; |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 136 | if (label->cms.disk_offset != 0) { |
| 137 | printk("CMS1/%8s(MDSK):", name); |
| 138 | /* disk is reserved minidisk */ |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 139 | offset = label->cms.disk_offset; |
| 140 | size = (label->cms.block_count - 1) |
| 141 | * (blocksize >> 9); |
| 142 | } else { |
| 143 | printk("CMS1/%8s:", name); |
| 144 | offset = (info->label_block + 1); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 145 | size = label->cms.block_count |
| 146 | * (blocksize >> 9); |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 147 | } |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 148 | put_partition(state, 1, offset*(blocksize >> 9), |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 149 | size-offset*(blocksize >> 9)); |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 150 | } else { |
| 151 | if (strncmp(type, "LNX1", 4) == 0) { |
| 152 | printk("LNX1/%8s:", name); |
| 153 | if (label->lnx.ldl_version == 0xf2) { |
| 154 | fmt_size = label->lnx.formatted_blocks |
| 155 | * (blocksize >> 9); |
| 156 | } else if (!strcmp(info->type, "ECKD")) { |
| 157 | /* formated w/o large volume support */ |
| 158 | fmt_size = geo->cylinders * geo->heads |
| 159 | * geo->sectors * (blocksize >> 9); |
| 160 | } else { |
| 161 | /* old label and no usable disk geometry |
| 162 | * (e.g. DIAG) */ |
| 163 | fmt_size = i_size >> 9; |
| 164 | } |
| 165 | size = i_size >> 9; |
| 166 | if (fmt_size < size) |
| 167 | size = fmt_size; |
| 168 | offset = (info->label_block + 1); |
| 169 | } else { |
| 170 | /* unlabeled disk */ |
| 171 | printk("(nonl)"); |
| 172 | size = i_size >> 9; |
| 173 | offset = (info->label_block + 1); |
| 174 | } |
| 175 | put_partition(state, 1, offset*(blocksize >> 9), |
| 176 | size-offset*(blocksize >> 9)); |
| 177 | } |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 178 | } else if (info->format == DASD_FORMAT_CDL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 180 | * New style CDL formatted disk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | */ |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 182 | sector_t blk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | int counter; |
| 184 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 185 | /* |
| 186 | * check if VOL1 label is available |
| 187 | * if not, something is wrong, skipping partition detection |
| 188 | */ |
| 189 | if (strncmp(type, "VOL1", 4) == 0) { |
| 190 | printk("VOL1/%8s:", name); |
| 191 | /* |
| 192 | * get block number and read then go through format1 |
| 193 | * labels |
| 194 | */ |
| 195 | blk = cchhb2blk(&label->vol.vtoc, geo) + 1; |
| 196 | counter = 0; |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 197 | data = read_part_sector(state, blk * (blocksize/512), |
| 198 | §); |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 199 | while (data != NULL) { |
| 200 | struct vtoc_format1_label f1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 202 | memcpy(&f1, data, |
| 203 | sizeof(struct vtoc_format1_label)); |
| 204 | put_dev_sector(sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 206 | /* skip FMT4 / FMT5 / FMT7 labels */ |
| 207 | if (f1.DS1FMTID == _ascebc['4'] |
| 208 | || f1.DS1FMTID == _ascebc['5'] |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 209 | || f1.DS1FMTID == _ascebc['7'] |
| 210 | || f1.DS1FMTID == _ascebc['9']) { |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 211 | blk++; |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 212 | data = read_part_sector(state, |
| 213 | blk * (blocksize/512), §); |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 214 | continue; |
| 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 217 | /* only FMT1 and 8 labels valid at this point */ |
| 218 | if (f1.DS1FMTID != _ascebc['1'] && |
| 219 | f1.DS1FMTID != _ascebc['8']) |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 220 | break; |
| 221 | |
| 222 | /* OK, we got valid partition data */ |
| 223 | offset = cchh2blk(&f1.DS1EXT1.llimit, geo); |
| 224 | size = cchh2blk(&f1.DS1EXT1.ulimit, geo) - |
| 225 | offset + geo->sectors; |
| 226 | if (counter >= state->limit) |
| 227 | break; |
| 228 | put_partition(state, counter + 1, |
| 229 | offset * (blocksize >> 9), |
| 230 | size * (blocksize >> 9)); |
| 231 | counter++; |
| 232 | blk++; |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 233 | data = read_part_sector(state, |
| 234 | blk * (blocksize/512), §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 237 | if (!data) |
| 238 | /* Are we not supposed to report this ? */ |
| 239 | goto out_readerr; |
| 240 | } else |
| 241 | printk(KERN_WARNING "Warning, expected Label VOL1 not " |
| 242 | "found, treating as CDL formated Disk"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | printk("\n"); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 247 | goto out_freeall; |
| 248 | |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | out_readerr: |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 251 | res = -1; |
| 252 | out_freeall: |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 253 | kfree(label); |
| 254 | out_nolab: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | kfree(geo); |
| 256 | out_nogeo: |
| 257 | kfree(info); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 258 | out_exit: |
| 259 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |