aboutsummaryrefslogtreecommitdiffstats
path: root/fs/partitions/ibm.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/partitions/ibm.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/partitions/ibm.c')
-rw-r--r--fs/partitions/ibm.c191
1 files changed, 191 insertions, 0 deletions
diff --git a/fs/partitions/ibm.c b/fs/partitions/ibm.c
new file mode 100644
index 000000000000..d59dcbf2bd4a
--- /dev/null
+++ b/fs/partitions/ibm.c
@@ -0,0 +1,191 @@
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 */
31static inline int
32cchh2blk (cchh_t *ptr, struct hd_geometry *geo) {
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 */
42static inline int
43cchhb2blk (cchhb_t *ptr, struct hd_geometry *geo) {
44 return ptr->cc * geo->heads * geo->sectors +
45 ptr->hh * geo->sectors +
46 ptr->b;
47}
48
49/*
50 */
51int
52ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
53{
54 int blocksize, offset, size;
55 dasd_information_t *info;
56 struct hd_geometry *geo;
57 char type[5] = {0,};
58 char name[7] = {0,};
59 volume_label_t *vlabel;
60 unsigned char *data;
61 Sector sect;
62
63 if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
64 goto out_noinfo;
65 if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
66 goto out_nogeo;
67 if ((vlabel = kmalloc(sizeof(volume_label_t), GFP_KERNEL)) == NULL)
68 goto out_novlab;
69
70 if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
71 ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
72 goto out_noioctl;
73
74 if ((blocksize = bdev_hardsect_size(bdev)) <= 0)
75 goto out_badsect;
76
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);
89 memcpy (vlabel, data, sizeof(volume_label_t));
90 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 */
102 int *label = (int *) vlabel;
103
104 if (label[13] != 0) {
105 printk("CMS1/%8s(MDSK):", name);
106 /* disk is reserved minidisk */
107 blocksize = label[3];
108 offset = label[13];
109 size = (label[7] - 1)*(blocksize >> 9);
110 } else {
111 printk("CMS1/%8s:", name);
112 offset = (info->label_block + 1);
113 size = bdev->bd_inode->i_size >> 9;
114 }
115 put_partition(state, 1, offset*(blocksize >> 9),
116 size-offset*(blocksize >> 9));
117 } else if ((strncmp(type, "VOL1", 4) == 0) &&
118 (!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
119 /*
120 * New style VOL1 labeled disk
121 */
122 unsigned int blk;
123 int counter;
124
125 printk("VOL1/%8s:", name);
126
127 /* get block number and read then go through format1 labels */
128 blk = cchhb2blk(&vlabel->vtoc, geo) + 1;
129 counter = 0;
130 while ((data = read_dev_sector(bdev, blk*(blocksize/512),
131 &sect)) != NULL) {
132 format1_label_t f1;
133
134 memcpy(&f1, data, sizeof(format1_label_t));
135 put_dev_sector(sect);
136
137 /* skip FMT4 / FMT5 / FMT7 labels */
138 if (f1.DS1FMTID == _ascebc['4']
139 || f1.DS1FMTID == _ascebc['5']
140 || f1.DS1FMTID == _ascebc['7']) {
141 blk++;
142 continue;
143 }
144
145 /* only FMT1 valid at this point */
146 if (f1.DS1FMTID != _ascebc['1'])
147 break;
148
149 /* OK, we got valid partition data */
150 offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
151 size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
152 offset + geo->sectors;
153 if (counter >= state->limit)
154 break;
155 put_partition(state, counter + 1,
156 offset * (blocksize >> 9),
157 size * (blocksize >> 9));
158 counter++;
159 blk++;
160 }
161 } else {
162 /*
163 * Old style LNX1 or unlabeled disk
164 */
165 if (strncmp(type, "LNX1", 4) == 0)
166 printk ("LNX1/%8s:", name);
167 else
168 printk("(nonl)/%8s:", name);
169 offset = (info->label_block + 1);
170 size = (bdev->bd_inode->i_size >> 9);
171 put_partition(state, 1, offset*(blocksize >> 9),
172 size-offset*(blocksize >> 9));
173 }
174
175 printk("\n");
176 kfree(vlabel);
177 kfree(geo);
178 kfree(info);
179 return 1;
180
181out_readerr:
182out_badsect:
183out_noioctl:
184 kfree(vlabel);
185out_novlab:
186 kfree(geo);
187out_nogeo:
188 kfree(info);
189out_noinfo:
190 return 0;
191}