2 * linux/fs/partitions/acorn.c
4 * Copyright (c) 1996-2000 Russell King.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Scan ADFS partitions on hard disk drives.
12 #include <linux/config.h>
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/kdev_t.h>
16 #include <linux/major.h>
17 #include <linux/string.h>
18 #include <linux/genhd.h>
20 #include <linux/pagemap.h>
26 adfspart_setgeometry(kdev_t dev, unsigned int secspertrack, unsigned int heads)
28 #ifdef CONFIG_BLK_DEV_MFM
29 extern void xd_set_geometry(kdev_t dev, unsigned char, unsigned char,
30 unsigned long, unsigned int);
32 if (MAJOR(dev) == MFM_ACORN_MAJOR) {
33 unsigned long totalblocks = hd->part[MINOR(dev)].nr_sects;
34 xd_set_geometry(dev, secspertrack, heads, totalblocks, 1);
39 static struct adfs_discrecord *
40 adfs_partition(struct gendisk *hd, char *name, char *data,
41 unsigned long first_sector, int minor)
43 struct adfs_discrecord *dr;
44 unsigned int nr_sects;
46 if (adfs_checkbblk(data))
49 dr = (struct adfs_discrecord *)(data + 0x1c0);
51 if (dr->disc_size == 0 && dr->disc_size_high == 0)
54 nr_sects = (le32_to_cpu(dr->disc_size_high) << 23) |
55 (le32_to_cpu(dr->disc_size) >> 9);
58 printk(" [%s]", name);
59 add_gd_partition(hd, minor, first_sector, nr_sects);
63 #ifdef CONFIG_ACORN_PARTITION_RISCIX
65 riscix_partition(struct gendisk *hd, struct block_device *bdev,
66 unsigned long first_sect, int minor, unsigned long nr_sects)
69 struct riscix_record *rr;
71 rr = (struct riscix_record *)read_dev_sector(bdev, first_sect, §);
78 if (rr->magic == RISCIX_MAGIC) {
79 unsigned long size = nr_sects > 2 ? 2 : nr_sects;
84 add_gd_partition(hd, minor++, first_sect, size);
85 for (part = 0; part < 8; part++) {
86 if (rr->part[part].one &&
87 memcmp(rr->part[part].name, "All\0", 4)) {
88 add_gd_partition(hd, minor++,
89 le32_to_cpu(rr->part[part].start),
90 le32_to_cpu(rr->part[part].length));
91 printk("(%s)", rr->part[part].name);
97 add_gd_partition(hd, minor++, first_sect, nr_sects);
100 put_dev_sector(sect);
106 linux_partition(struct gendisk *hd, struct block_device *bdev,
107 unsigned long first_sect, int minor, unsigned long nr_sects)
110 struct linux_part *linuxp;
111 unsigned int mask = (1 << hd->minor_shift) - 1;
112 unsigned long size = nr_sects > 2 ? 2 : nr_sects;
116 add_gd_partition(hd, minor++, first_sect, size);
118 linuxp = (struct linux_part *)read_dev_sector(bdev, first_sect, §);
123 while (linuxp->magic == cpu_to_le32(LINUX_NATIVE_MAGIC) ||
124 linuxp->magic == cpu_to_le32(LINUX_SWAP_MAGIC)) {
127 add_gd_partition(hd, minor++, first_sect +
128 le32_to_cpu(linuxp->start_sect),
129 le32_to_cpu(linuxp->nr_sects));
134 put_dev_sector(sect);
138 #ifdef CONFIG_ACORN_PARTITION_CUMANA
140 adfspart_check_CUMANA(struct gendisk *hd, struct block_device *bdev,
141 unsigned long first_sector, int minor)
143 unsigned int start_blk = 0, mask = (1 << hd->minor_shift) - 1;
146 char *name = "CUMANA/ADFS";
150 * Try Cumana style partitions - sector 3 contains ADFS boot block
151 * with pointer to next 'drive'.
153 * There are unknowns in this code - is the 'cylinder number' of the
154 * next partition relative to the start of this one - I'm assuming
157 * Also, which ID did Cumana use?
159 * This is totally unfinished, and will require more work to get it
160 * going. Hence it is totally untested.
163 struct adfs_discrecord *dr;
164 unsigned int nr_sects;
169 data = read_dev_sector(bdev, start_blk * 2 + 6, §);
173 dr = adfs_partition(hd, name, data, first_sector, minor++);
179 nr_sects = (data[0x1fd] + (data[0x1fe] << 8)) *
180 (dr->heads + (dr->lowsector & 0x40 ? 1 : 0)) *
187 first_sector += nr_sects;
188 start_blk += nr_sects >> (BLOCK_SIZE_BITS - 9);
189 nr_sects = 0; /* hmm - should be partition size */
191 switch (data[0x1fc] & 15) {
192 case 0: /* No partition / ADFS? */
195 #ifdef CONFIG_ACORN_PARTITION_RISCIX
196 case PARTITION_RISCIX_SCSI:
197 /* RISCiX - we don't know how to find the next one. */
198 minor = riscix_partition(hd, bdev, first_sector,
203 case PARTITION_LINUX:
204 minor = linux_partition(hd, bdev, first_sector,
208 put_dev_sector(sect);
212 put_dev_sector(sect);
213 return first ? 0 : 1;
217 #ifdef CONFIG_ACORN_PARTITION_ADFS
219 * Purpose: allocate ADFS partitions.
221 * Params : hd - pointer to gendisk structure to store partition info.
222 * dev - device number to access.
223 * first_sector- first readable sector on the device.
224 * minor - first available minor on device.
226 * Returns: -1 on error, 0 for no ADFS boot sector, 1 for ok.
228 * Alloc : hda = whole drive
229 * hda1 = ADFS partition on first drive.
230 * hda2 = non-ADFS partition.
233 adfspart_check_ADFS(struct gendisk *hd, struct block_device *bdev,
234 unsigned long first_sector, int minor)
236 unsigned long start_sect, nr_sects, sectscyl, heads;
239 struct adfs_discrecord *dr;
242 data = read_dev_sector(bdev, 6, §);
246 dr = adfs_partition(hd, "ADFS", data, first_sector, minor++);
248 put_dev_sector(sect);
252 heads = dr->heads + ((dr->lowsector >> 6) & 1);
253 sectscyl = dr->secspertrack * heads;
254 start_sect = ((data[0x1fe] << 8) + data[0x1fd]) * sectscyl;
255 id = data[0x1fc] & 15;
256 put_dev_sector(sect);
258 adfspart_setgeometry(to_kdev_t(bdev->bd_dev), dr->secspertrack, heads);
259 invalidate_bdev(bdev, 1);
260 truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
263 * Work out start of non-adfs partition.
265 nr_sects = hd->part[MINOR(to_kdev_t(bdev->bd_dev))].nr_sects - start_sect;
268 first_sector += start_sect;
271 #ifdef CONFIG_ACORN_PARTITION_RISCIX
272 case PARTITION_RISCIX_SCSI:
273 case PARTITION_RISCIX_MFM:
274 minor = riscix_partition(hd, bdev, first_sector,
279 case PARTITION_LINUX:
280 minor = linux_partition(hd, bdev, first_sector,
289 #ifdef CONFIG_ACORN_PARTITION_ICS
290 static int adfspart_check_ICSLinux(struct block_device *bdev, unsigned long block)
293 unsigned char *data = read_dev_sector(bdev, block, §);
297 if (memcmp(data, "LinuxPart", 9) == 0)
299 put_dev_sector(sect);
306 * Purpose: allocate ICS partitions.
307 * Params : hd - pointer to gendisk structure to store partition info.
308 * dev - device number to access.
309 * first_sector- first readable sector on the device.
310 * minor - first available minor on device.
311 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
312 * Alloc : hda = whole drive
313 * hda1 = ADFS partition 0 on first drive.
314 * hda2 = ADFS partition 1 on first drive.
318 adfspart_check_ICS(struct gendisk *hd, struct block_device *bdev,
319 unsigned long first_sector, int minor)
324 unsigned int i, mask = (1 << hd->minor_shift) - 1;
328 * Try ICS style partitions - sector 0 contains partition info.
330 data = read_dev_sector(bdev, 0, §);
335 * check for a valid checksum
337 for (i = 0, sum = 0x50617274; i < 508; i++)
340 sum -= le32_to_cpu(*(__u32 *)(&data[508]));
342 put_dev_sector(sect);
343 return 0; /* not ICS partition table */
348 for (p = (struct ics_part *)data; p->size; p++) {
352 if ((minor & mask) == 0)
355 start = le32_to_cpu(p->start);
356 size = le32_to_cpu(p->size);
362 * We use the first sector to identify what type
363 * this partition is...
365 if (size > 1 && adfspart_check_ICSLinux(bdev, start)) {
372 add_gd_partition(hd, minor, first_sector + start, size);
377 put_dev_sector(sect);
383 * Purpose: allocate ICS partitions.
384 * Params : hd - pointer to gendisk structure to store partition info.
385 * dev - device number to access.
386 * first_sector- first readable sector on the device.
387 * minor - first available minor on device.
388 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
389 * Alloc : hda = whole drive
390 * hda1 = ADFS partition 0 on first drive.
391 * hda2 = ADFS partition 1 on first drive.
394 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
396 adfspart_check_POWERTEC(struct gendisk *hd, struct block_device *bdev,
397 unsigned long first_sector, int minor)
401 struct ptec_partition *p;
402 unsigned char checksum;
405 data = read_dev_sector(bdev, 0, §);
409 for (checksum = 0x2a, i = 0; i < 511; i++)
412 if (checksum != data[511]) {
413 put_dev_sector(sect);
417 printk(" [POWERTEC]");
419 for (i = 0, p = (struct ptec_partition *)data; i < 12; i++, p++) {
423 start = le32_to_cpu(p->start);
424 size = le32_to_cpu(p->size);
427 add_gd_partition(hd, minor, first_sector + start,
432 put_dev_sector(sect);
437 static int (*partfn[])(struct gendisk *, struct block_device *, unsigned long, int) = {
438 #ifdef CONFIG_ACORN_PARTITION_ICS
441 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
442 adfspart_check_POWERTEC,
444 #ifdef CONFIG_ACORN_PARTITION_CUMANA
445 adfspart_check_CUMANA,
447 #ifdef CONFIG_ACORN_PARTITION_ADFS
453 * Purpose: initialise all the partitions on an ADFS drive.
454 * These may be other ADFS partitions or a Linux/RiscBSD/RISCiX
457 * Params : hd - pointer to gendisk structure
458 * dev - device number to access
459 * first_sect - first available sector on the disk.
460 * first_minor - first available minor on this device.
462 * Returns: -1 on error, 0 if not ADFS format, 1 if ok.
464 int acorn_partition(struct gendisk *hd, struct block_device *bdev,
465 unsigned long first_sect, int first_minor)
469 for (i = 0; partfn[i]; i++) {
470 int r = partfn[i](hd, bdev, first_sect, first_minor);