Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 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 | */ |
| 31 | static inline int |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 32 | cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | 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 | */ |
| 42 | static inline int |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 43 | cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | return ptr->cc * geo->heads * geo->sectors + |
| 45 | ptr->hh * geo->sectors + |
| 46 | ptr->b; |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | */ |
| 51 | int |
| 52 | ibm_partition(struct parsed_partitions *state, struct block_device *bdev) |
| 53 | { |
| 54 | int blocksize, offset, size; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 55 | loff_t i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | dasd_information_t *info; |
| 57 | struct hd_geometry *geo; |
| 58 | char type[5] = {0,}; |
| 59 | char name[7] = {0,}; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 60 | union label_t { |
| 61 | struct vtoc_volume_label vol; |
| 62 | struct vtoc_cms_label cms; |
| 63 | } *label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | unsigned char *data; |
| 65 | Sector sect; |
| 66 | |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 67 | blocksize = bdev_hardsect_size(bdev); |
| 68 | if (blocksize <= 0) |
| 69 | return 0; |
| 70 | i_size = i_size_read(bdev->bd_inode); |
| 71 | if (i_size == 0) |
| 72 | return 0; |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL) |
| 75 | goto out_noinfo; |
| 76 | if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL) |
| 77 | goto out_nogeo; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 78 | if ((label = kmalloc(sizeof(union label_t), GFP_KERNEL)) == NULL) |
| 79 | goto out_nolab; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 || |
| 82 | ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0) |
| 83 | goto out_noioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Get volume label, extract name and type. |
| 87 | */ |
| 88 | data = read_dev_sector(bdev, info->label_block*(blocksize/512), §); |
| 89 | if (data == NULL) |
| 90 | goto out_readerr; |
| 91 | |
| 92 | strncpy (type, data, 4); |
| 93 | if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) |
| 94 | strncpy(name, data + 8, 6); |
| 95 | else |
| 96 | strncpy(name, data + 4, 6); |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 97 | memcpy(label, data, sizeof(union label_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | put_dev_sector(sect); |
| 99 | |
| 100 | EBCASC(type, 4); |
| 101 | EBCASC(name, 6); |
| 102 | |
| 103 | /* |
| 104 | * Three different types: CMS1, VOL1 and LNX1/unlabeled |
| 105 | */ |
| 106 | if (strncmp(type, "CMS1", 4) == 0) { |
| 107 | /* |
| 108 | * VM style CMS1 labeled disk |
| 109 | */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 110 | if (label->cms.disk_offset != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | printk("CMS1/%8s(MDSK):", name); |
| 112 | /* disk is reserved minidisk */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 113 | blocksize = label->cms.block_size; |
| 114 | offset = label->cms.disk_offset; |
| 115 | size = (label->cms.block_count - 1) * (blocksize >> 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } else { |
| 117 | printk("CMS1/%8s:", name); |
| 118 | offset = (info->label_block + 1); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 119 | size = i_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | put_partition(state, 1, offset*(blocksize >> 9), |
| 122 | size-offset*(blocksize >> 9)); |
| 123 | } else if ((strncmp(type, "VOL1", 4) == 0) && |
| 124 | (!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) { |
| 125 | /* |
| 126 | * New style VOL1 labeled disk |
| 127 | */ |
| 128 | unsigned int blk; |
| 129 | int counter; |
| 130 | |
| 131 | printk("VOL1/%8s:", name); |
| 132 | |
| 133 | /* get block number and read then go through format1 labels */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 134 | blk = cchhb2blk(&label->vol.vtoc, geo) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | counter = 0; |
| 136 | while ((data = read_dev_sector(bdev, blk*(blocksize/512), |
| 137 | §)) != NULL) { |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 138 | struct vtoc_format1_label f1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 140 | memcpy(&f1, data, sizeof(struct vtoc_format1_label)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | put_dev_sector(sect); |
| 142 | |
| 143 | /* skip FMT4 / FMT5 / FMT7 labels */ |
| 144 | if (f1.DS1FMTID == _ascebc['4'] |
| 145 | || f1.DS1FMTID == _ascebc['5'] |
| 146 | || f1.DS1FMTID == _ascebc['7']) { |
| 147 | blk++; |
| 148 | continue; |
| 149 | } |
| 150 | |
| 151 | /* only FMT1 valid at this point */ |
| 152 | if (f1.DS1FMTID != _ascebc['1']) |
| 153 | break; |
| 154 | |
| 155 | /* OK, we got valid partition data */ |
| 156 | offset = cchh2blk(&f1.DS1EXT1.llimit, geo); |
| 157 | size = cchh2blk(&f1.DS1EXT1.ulimit, geo) - |
| 158 | offset + geo->sectors; |
| 159 | if (counter >= state->limit) |
| 160 | break; |
| 161 | put_partition(state, counter + 1, |
| 162 | offset * (blocksize >> 9), |
| 163 | size * (blocksize >> 9)); |
| 164 | counter++; |
| 165 | blk++; |
| 166 | } |
| 167 | } else { |
| 168 | /* |
| 169 | * Old style LNX1 or unlabeled disk |
| 170 | */ |
| 171 | if (strncmp(type, "LNX1", 4) == 0) |
| 172 | printk ("LNX1/%8s:", name); |
| 173 | else |
| 174 | printk("(nonl)/%8s:", name); |
| 175 | offset = (info->label_block + 1); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 176 | size = i_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | put_partition(state, 1, offset*(blocksize >> 9), |
| 178 | size-offset*(blocksize >> 9)); |
| 179 | } |
| 180 | |
| 181 | printk("\n"); |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 182 | kfree(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | kfree(geo); |
| 184 | kfree(info); |
| 185 | return 1; |
| 186 | |
| 187 | out_readerr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | out_noioctl: |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 189 | kfree(label); |
| 190 | out_nolab: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | kfree(geo); |
| 192 | out_nogeo: |
| 193 | kfree(info); |
| 194 | out_noinfo: |
| 195 | return 0; |
| 196 | } |