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 | |
| 9 | #include <linux/config.h> |
| 10 | #include <linux/buffer_head.h> |
| 11 | #include <linux/hdreg.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <asm/dasd.h> |
| 14 | #include <asm/ebcdic.h> |
| 15 | #include <asm/uaccess.h> |
| 16 | #include <asm/vtoc.h> |
| 17 | |
| 18 | #include "check.h" |
| 19 | #include "ibm.h" |
| 20 | |
| 21 | /* |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 22 | * compute the block number from a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * cyl-cyl-head-head structure |
| 24 | */ |
| 25 | static inline int |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 26 | cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | return ptr->cc * geo->heads * geo->sectors + |
| 28 | ptr->hh * geo->sectors; |
| 29 | } |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 32 | * compute the block number from a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * cyl-cyl-head-head-block structure |
| 34 | */ |
| 35 | static inline int |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 36 | cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | return ptr->cc * geo->heads * geo->sectors + |
| 38 | ptr->hh * geo->sectors + |
| 39 | ptr->b; |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | */ |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 44 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | ibm_partition(struct parsed_partitions *state, struct block_device *bdev) |
| 46 | { |
| 47 | int blocksize, offset, size; |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 48 | loff_t i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | dasd_information_t *info; |
| 50 | struct hd_geometry *geo; |
| 51 | char type[5] = {0,}; |
| 52 | char name[7] = {0,}; |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 53 | union label_t { |
| 54 | struct vtoc_volume_label vol; |
| 55 | struct vtoc_cms_label cms; |
| 56 | } *label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | unsigned char *data; |
| 58 | Sector sect; |
| 59 | |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 60 | blocksize = bdev_hardsect_size(bdev); |
| 61 | if (blocksize <= 0) |
| 62 | return 0; |
| 63 | i_size = i_size_read(bdev->bd_inode); |
| 64 | if (i_size == 0) |
| 65 | return 0; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL) |
| 68 | goto out_noinfo; |
| 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) |
| 76 | goto out_noioctl; |
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 | |
| 96 | /* |
| 97 | * Three different types: CMS1, VOL1 and LNX1/unlabeled |
| 98 | */ |
| 99 | if (strncmp(type, "CMS1", 4) == 0) { |
| 100 | /* |
| 101 | * VM style CMS1 labeled disk |
| 102 | */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 103 | if (label->cms.disk_offset != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | printk("CMS1/%8s(MDSK):", name); |
| 105 | /* disk is reserved minidisk */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 106 | blocksize = label->cms.block_size; |
| 107 | offset = label->cms.disk_offset; |
| 108 | size = (label->cms.block_count - 1) * (blocksize >> 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } else { |
| 110 | printk("CMS1/%8s:", name); |
| 111 | offset = (info->label_block + 1); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 112 | size = i_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | put_partition(state, 1, offset*(blocksize >> 9), |
| 115 | size-offset*(blocksize >> 9)); |
| 116 | } else if ((strncmp(type, "VOL1", 4) == 0) && |
| 117 | (!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) { |
| 118 | /* |
| 119 | * New style VOL1 labeled disk |
| 120 | */ |
| 121 | unsigned int blk; |
| 122 | int counter; |
| 123 | |
| 124 | printk("VOL1/%8s:", name); |
| 125 | |
| 126 | /* get block number and read then go through format1 labels */ |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 127 | blk = cchhb2blk(&label->vol.vtoc, geo) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | counter = 0; |
| 129 | while ((data = read_dev_sector(bdev, blk*(blocksize/512), |
| 130 | §)) != NULL) { |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 131 | struct vtoc_format1_label f1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Peter Oberparleiter | 4cd5b9f | 2005-11-07 00:59:09 -0800 | [diff] [blame] | 133 | memcpy(&f1, data, sizeof(struct vtoc_format1_label)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | put_dev_sector(sect); |
| 135 | |
| 136 | /* skip FMT4 / FMT5 / FMT7 labels */ |
| 137 | if (f1.DS1FMTID == _ascebc['4'] |
| 138 | || f1.DS1FMTID == _ascebc['5'] |
| 139 | || f1.DS1FMTID == _ascebc['7']) { |
| 140 | blk++; |
| 141 | continue; |
| 142 | } |
| 143 | |
| 144 | /* only FMT1 valid at this point */ |
| 145 | if (f1.DS1FMTID != _ascebc['1']) |
| 146 | break; |
| 147 | |
| 148 | /* OK, we got valid partition data */ |
| 149 | offset = cchh2blk(&f1.DS1EXT1.llimit, geo); |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 150 | size = cchh2blk(&f1.DS1EXT1.ulimit, geo) - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | offset + geo->sectors; |
| 152 | if (counter >= state->limit) |
| 153 | break; |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 154 | put_partition(state, counter + 1, |
| 155 | offset * (blocksize >> 9), |
| 156 | size * (blocksize >> 9)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | counter++; |
| 158 | blk++; |
| 159 | } |
| 160 | } else { |
| 161 | /* |
| 162 | * Old style LNX1 or unlabeled disk |
| 163 | */ |
| 164 | if (strncmp(type, "LNX1", 4) == 0) |
| 165 | printk ("LNX1/%8s:", name); |
| 166 | else |
| 167 | printk("(nonl)/%8s:", name); |
| 168 | offset = (info->label_block + 1); |
Horst Hummel | 90f0094 | 2006-03-07 21:55:39 -0800 | [diff] [blame] | 169 | size = i_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | put_partition(state, 1, offset*(blocksize >> 9), |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 171 | size-offset*(blocksize >> 9)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | printk("\n"); |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 175 | kfree(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | kfree(geo); |
| 177 | kfree(info); |
| 178 | return 1; |
Horst Hummel | ef1597d | 2006-03-24 03:15:23 -0800 | [diff] [blame] | 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | out_readerr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | out_noioctl: |
Peter Oberparleiter | 56dc6a8 | 2006-01-06 00:19:09 -0800 | [diff] [blame] | 182 | kfree(label); |
| 183 | out_nolab: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | kfree(geo); |
| 185 | out_nogeo: |
| 186 | kfree(info); |
| 187 | out_noinfo: |
| 188 | return 0; |
| 189 | } |