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 | */ |
| 24 | static inline int |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 25 | cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | return ptr->cc * geo->heads * geo->sectors + |
| 27 | ptr->hh * geo->sectors; |
| 28 | } |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | /* |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 31 | * compute the block number from a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * cyl-cyl-head-head-block structure |
| 33 | */ |
| 34 | static inline int |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 35 | cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | return ptr->cc * geo->heads * geo->sectors + |
| 37 | ptr->hh * geo->sectors + |
| 38 | ptr->b; |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | */ |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 43 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | ibm_partition(struct parsed_partitions *state, struct block_device *bdev) |
| 45 | { |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 46 | int blocksize, offset, size,res; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 47 | loff_t i_size; |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 48 | dasd_information2_t *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | struct hd_geometry *geo; |
| 50 | char type[5] = {0,}; |
| 51 | char name[7] = {0,}; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 52 | union label_t { |
| 53 | struct vtoc_volume_label vol; |
| 54 | struct vtoc_cms_label cms; |
| 55 | } *label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | unsigned char *data; |
| 57 | Sector sect; |
| 58 | |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 59 | res = 0; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 60 | blocksize = bdev_hardsect_size(bdev); |
| 61 | if (blocksize <= 0) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 62 | goto out_exit; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 63 | i_size = i_size_read(bdev->bd_inode); |
| 64 | if (i_size == 0) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 65 | goto out_exit; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 66 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 67 | info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL); |
| 68 | if (info == NULL) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 69 | goto out_exit; |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 70 | geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL); |
| 71 | if (geo == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | goto out_nogeo; |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 73 | label = kmalloc(sizeof(union label_t), GFP_KERNEL); |
| 74 | if (label == NULL) |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 75 | goto out_nolab; |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 76 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 77 | if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 79 | goto out_freeall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * Get volume label, extract name and type. |
| 83 | */ |
| 84 | data = read_dev_sector(bdev, info->label_block*(blocksize/512), §); |
| 85 | if (data == NULL) |
| 86 | goto out_readerr; |
| 87 | |
| 88 | strncpy (type, data, 4); |
| 89 | if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) |
| 90 | strncpy(name, data + 8, 6); |
| 91 | else |
| 92 | strncpy(name, data + 4, 6); |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 93 | memcpy(label, data, sizeof(union label_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | put_dev_sector(sect); |
| 95 | |
| 96 | EBCASC(type, 4); |
| 97 | EBCASC(name, 6); |
| 98 | |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 99 | res = 1; |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | */ |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 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 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } else { |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 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)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | offset = (info->label_block + 1); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 134 | size = i_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | put_partition(state, 1, offset*(blocksize >> 9), |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 137 | size-offset*(blocksize >> 9)); |
| 138 | } else if (info->format == DASD_FORMAT_CDL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /* |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 140 | * New style CDL formatted disk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | */ |
| 142 | unsigned int blk; |
| 143 | int counter; |
| 144 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 145 | /* |
| 146 | * check if VOL1 label is available |
| 147 | * if not, something is wrong, skipping partition detection |
| 148 | */ |
| 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 | §); |
| 159 | while (data != NULL) { |
| 160 | struct vtoc_format1_label f1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 162 | memcpy(&f1, data, |
| 163 | sizeof(struct vtoc_format1_label)); |
| 164 | put_dev_sector(sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 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 | §); |
| 174 | continue; |
| 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 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 | §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Stefan Haberland | bf1a95a | 2007-07-10 11:24:11 +0200 | [diff] [blame] | 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"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | printk("\n"); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 207 | goto out_freeall; |
| 208 | |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | out_readerr: |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 211 | res = -1; |
| 212 | out_freeall: |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 213 | kfree(label); |
| 214 | out_nolab: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | kfree(geo); |
| 216 | out_nogeo: |
| 217 | kfree(info); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 218 | out_exit: |
| 219 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |