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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | dasd_information_t *info; |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame^] | 68 | goto out_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL) |
| 70 | goto out_nogeo; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 71 | if ((label = kmalloc(sizeof(union label_t), GFP_KERNEL)) == NULL) |
| 72 | goto out_nolab; |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 || |
| 75 | ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0) |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame^] | 76 | goto out_freeall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Get volume label, extract name and type. |
| 80 | */ |
| 81 | data = read_dev_sector(bdev, info->label_block*(blocksize/512), §); |
| 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 Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 90 | memcpy(label, data, sizeof(union label_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | put_dev_sector(sect); |
| 92 | |
| 93 | EBCASC(type, 4); |
| 94 | EBCASC(name, 6); |
| 95 | |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame^] | 96 | res = 1; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* |
| 99 | * Three different types: CMS1, VOL1 and LNX1/unlabeled |
| 100 | */ |
| 101 | if (strncmp(type, "CMS1", 4) == 0) { |
| 102 | /* |
| 103 | * VM style CMS1 labeled disk |
| 104 | */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 105 | if (label->cms.disk_offset != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | printk("CMS1/%8s(MDSK):", name); |
| 107 | /* disk is reserved minidisk */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 108 | blocksize = label->cms.block_size; |
| 109 | offset = label->cms.disk_offset; |
| 110 | size = (label->cms.block_count - 1) * (blocksize >> 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } else { |
| 112 | printk("CMS1/%8s:", name); |
| 113 | offset = (info->label_block + 1); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 114 | size = i_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 129 | blk = cchhb2blk(&label->vol.vtoc, geo) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | counter = 0; |
| 131 | while ((data = read_dev_sector(bdev, blk*(blocksize/512), |
| 132 | §)) != NULL) { |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 133 | struct vtoc_format1_label f1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 135 | memcpy(&f1, data, sizeof(struct vtoc_format1_label)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | 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); |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 152 | size = cchh2blk(&f1.DS1EXT1.ulimit, geo) - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | offset + geo->sectors; |
| 154 | if (counter >= state->limit) |
| 155 | break; |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 156 | put_partition(state, counter + 1, |
| 157 | offset * (blocksize >> 9), |
| 158 | size * (blocksize >> 9)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | counter++; |
| 160 | blk++; |
| 161 | } |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame^] | 162 | if (!data) |
| 163 | /* Are we not supposed to report this ? */ |
| 164 | goto out_readerr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } else { |
| 166 | /* |
| 167 | * Old style LNX1 or unlabeled disk |
| 168 | */ |
| 169 | if (strncmp(type, "LNX1", 4) == 0) |
| 170 | printk ("LNX1/%8s:", name); |
| 171 | else |
| 172 | printk("(nonl)/%8s:", name); |
| 173 | offset = (info->label_block + 1); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 174 | size = i_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | put_partition(state, 1, offset*(blocksize >> 9), |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 176 | size-offset*(blocksize >> 9)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | printk("\n"); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame^] | 180 | goto out_freeall; |
| 181 | |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | out_readerr: |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame^] | 184 | res = -1; |
| 185 | out_freeall: |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 186 | kfree(label); |
| 187 | out_nolab: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | kfree(geo); |
| 189 | out_nogeo: |
| 190 | kfree(info); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame^] | 191 | out_exit: |
| 192 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |