blob: d352a7381fed88ff20f5f1c7b9b6365a2264e436 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Horst Hummelef1597d2006-03-24 03:15:23 -08002 * File...........: linux/fs/partitions/ibm.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#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 Hummelef1597d2006-03-24 03:15:23 -080021 * compute the block number from a
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * cyl-cyl-head-head structure
23 */
24static inline int
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -080025cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 return ptr->cc * geo->heads * geo->sectors +
27 ptr->hh * geo->sectors;
28}
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/*
Horst Hummelef1597d2006-03-24 03:15:23 -080031 * compute the block number from a
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * cyl-cyl-head-head-block structure
33 */
34static inline int
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -080035cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 return ptr->cc * geo->heads * geo->sectors +
37 ptr->hh * geo->sectors +
38 ptr->b;
39}
40
41/*
42 */
Horst Hummelef1597d2006-03-24 03:15:23 -080043int
Linus Torvalds1da177e2005-04-16 15:20:36 -070044ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
45{
46 int blocksize, offset, size;
Horst Hummel90f00942006-03-07 21:55:39 -080047 loff_t i_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 dasd_information_t *info;
49 struct hd_geometry *geo;
50 char type[5] = {0,};
51 char name[7] = {0,};
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -080052 union label_t {
53 struct vtoc_volume_label vol;
54 struct vtoc_cms_label cms;
55 } *label;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 unsigned char *data;
57 Sector sect;
58
Horst Hummel90f00942006-03-07 21:55:39 -080059 blocksize = bdev_hardsect_size(bdev);
60 if (blocksize <= 0)
61 return 0;
62 i_size = i_size_read(bdev->bd_inode);
63 if (i_size == 0)
64 return 0;
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
67 goto out_noinfo;
68 if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
69 goto out_nogeo;
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -080070 if ((label = kmalloc(sizeof(union label_t), GFP_KERNEL)) == NULL)
71 goto out_nolab;
Horst Hummelef1597d2006-03-24 03:15:23 -080072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
74 ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
75 goto out_noioctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 /*
78 * Get volume label, extract name and type.
79 */
80 data = read_dev_sector(bdev, info->label_block*(blocksize/512), &sect);
81 if (data == NULL)
82 goto out_readerr;
83
84 strncpy (type, data, 4);
85 if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD")))
86 strncpy(name, data + 8, 6);
87 else
88 strncpy(name, data + 4, 6);
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -080089 memcpy(label, data, sizeof(union label_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 put_dev_sector(sect);
91
92 EBCASC(type, 4);
93 EBCASC(name, 6);
94
95 /*
96 * Three different types: CMS1, VOL1 and LNX1/unlabeled
97 */
98 if (strncmp(type, "CMS1", 4) == 0) {
99 /*
100 * VM style CMS1 labeled disk
101 */
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -0800102 if (label->cms.disk_offset != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 printk("CMS1/%8s(MDSK):", name);
104 /* disk is reserved minidisk */
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -0800105 blocksize = label->cms.block_size;
106 offset = label->cms.disk_offset;
107 size = (label->cms.block_count - 1) * (blocksize >> 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 } else {
109 printk("CMS1/%8s:", name);
110 offset = (info->label_block + 1);
Horst Hummel90f00942006-03-07 21:55:39 -0800111 size = i_size >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113 put_partition(state, 1, offset*(blocksize >> 9),
114 size-offset*(blocksize >> 9));
115 } else if ((strncmp(type, "VOL1", 4) == 0) &&
116 (!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
117 /*
118 * New style VOL1 labeled disk
119 */
120 unsigned int blk;
121 int counter;
122
123 printk("VOL1/%8s:", name);
124
125 /* get block number and read then go through format1 labels */
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -0800126 blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 counter = 0;
128 while ((data = read_dev_sector(bdev, blk*(blocksize/512),
129 &sect)) != NULL) {
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -0800130 struct vtoc_format1_label f1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Peter Oberparleiter4cd5b9f2005-11-07 00:59:09 -0800132 memcpy(&f1, data, sizeof(struct vtoc_format1_label));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 put_dev_sector(sect);
134
135 /* skip FMT4 / FMT5 / FMT7 labels */
136 if (f1.DS1FMTID == _ascebc['4']
137 || f1.DS1FMTID == _ascebc['5']
138 || f1.DS1FMTID == _ascebc['7']) {
139 blk++;
140 continue;
141 }
142
143 /* only FMT1 valid at this point */
144 if (f1.DS1FMTID != _ascebc['1'])
145 break;
146
147 /* OK, we got valid partition data */
148 offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
Horst Hummelef1597d2006-03-24 03:15:23 -0800149 size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 offset + geo->sectors;
151 if (counter >= state->limit)
152 break;
Horst Hummelef1597d2006-03-24 03:15:23 -0800153 put_partition(state, counter + 1,
154 offset * (blocksize >> 9),
155 size * (blocksize >> 9));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 counter++;
157 blk++;
158 }
159 } else {
160 /*
161 * Old style LNX1 or unlabeled disk
162 */
163 if (strncmp(type, "LNX1", 4) == 0)
164 printk ("LNX1/%8s:", name);
165 else
166 printk("(nonl)/%8s:", name);
167 offset = (info->label_block + 1);
Horst Hummel90f00942006-03-07 21:55:39 -0800168 size = i_size >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 put_partition(state, 1, offset*(blocksize >> 9),
Horst Hummelef1597d2006-03-24 03:15:23 -0800170 size-offset*(blocksize >> 9));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172
173 printk("\n");
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -0800174 kfree(label);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 kfree(geo);
176 kfree(info);
177 return 1;
Horst Hummelef1597d2006-03-24 03:15:23 -0800178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179out_readerr:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180out_noioctl:
Peter Oberparleiter56dc6a82006-01-06 00:19:09 -0800181 kfree(label);
182out_nolab:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 kfree(geo);
184out_nogeo:
185 kfree(info);
186out_noinfo:
187 return 0;
188}