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. Unfortunately, there
11 * isn't a standard for partitioning drives on Acorn machines, so
12 * every single manufacturer of SCSI and IDE cards created their own
15 #include <linux/buffer_head.h>
16 #include <linux/adfs_fs.h>
22 * Partition types. (Oh for reusability)
24 #define PARTITION_RISCIX_MFM 1
25 #define PARTITION_RISCIX_SCSI 2
26 #define PARTITION_LINUX 9
28 static struct adfs_discrecord
*
29 adfs_partition(struct parsed_partitions
*state
, char *name
, char *data
,
30 unsigned long first_sector
, int slot
)
32 struct adfs_discrecord
*dr
;
33 unsigned int nr_sects
;
35 if (adfs_checkbblk(data
))
38 dr
= (struct adfs_discrecord
*)(data
+ 0x1c0);
40 if (dr
->disc_size
== 0 && dr
->disc_size_high
== 0)
43 nr_sects
= (le32_to_cpu(dr
->disc_size_high
) << 23) |
44 (le32_to_cpu(dr
->disc_size
) >> 9);
47 printk(" [%s]", name
);
48 put_partition(state
, slot
, first_sector
, nr_sects
);
52 #ifdef CONFIG_ACORN_PARTITION_RISCIX
61 struct riscix_record
{
63 #define RISCIX_MAGIC cpu_to_le32(0x4a657320)
65 struct riscix_part part
[8];
69 riscix_partition(struct parsed_partitions
*state
, struct block_device
*bdev
,
70 unsigned long first_sect
, int slot
, unsigned long nr_sects
)
73 struct riscix_record
*rr
;
75 rr
= (struct riscix_record
*)read_dev_sector(bdev
, first_sect
, §
);
82 if (rr
->magic
== RISCIX_MAGIC
) {
83 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
88 put_partition(state
, slot
++, first_sect
, size
);
89 for (part
= 0; part
< 8; part
++) {
90 if (rr
->part
[part
].one
&&
91 memcmp(rr
->part
[part
].name
, "All\0", 4)) {
92 put_partition(state
, slot
++,
93 le32_to_cpu(rr
->part
[part
].start
),
94 le32_to_cpu(rr
->part
[part
].length
));
95 printk("(%s)", rr
->part
[part
].name
);
101 put_partition(state
, slot
++, first_sect
, nr_sects
);
104 put_dev_sector(sect
);
109 #define LINUX_NATIVE_MAGIC 0xdeafa1de
110 #define LINUX_SWAP_MAGIC 0xdeafab1e
119 linux_partition(struct parsed_partitions
*state
, struct block_device
*bdev
,
120 unsigned long first_sect
, int slot
, unsigned long nr_sects
)
123 struct linux_part
*linuxp
;
124 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
128 put_partition(state
, slot
++, first_sect
, size
);
130 linuxp
= (struct linux_part
*)read_dev_sector(bdev
, first_sect
, §
);
135 while (linuxp
->magic
== cpu_to_le32(LINUX_NATIVE_MAGIC
) ||
136 linuxp
->magic
== cpu_to_le32(LINUX_SWAP_MAGIC
)) {
137 if (slot
== state
->limit
)
139 put_partition(state
, slot
++, first_sect
+
140 le32_to_cpu(linuxp
->start_sect
),
141 le32_to_cpu(linuxp
->nr_sects
));
146 put_dev_sector(sect
);
150 #ifdef CONFIG_ACORN_PARTITION_CUMANA
152 adfspart_check_CUMANA(struct parsed_partitions
*state
, struct block_device
*bdev
)
154 unsigned long first_sector
= 0;
155 unsigned int start_blk
= 0;
158 char *name
= "CUMANA/ADFS";
163 * Try Cumana style partitions - sector 6 contains ADFS boot block
164 * with pointer to next 'drive'.
166 * There are unknowns in this code - is the 'cylinder number' of the
167 * next partition relative to the start of this one - I'm assuming
170 * Also, which ID did Cumana use?
172 * This is totally unfinished, and will require more work to get it
173 * going. Hence it is totally untested.
176 struct adfs_discrecord
*dr
;
177 unsigned int nr_sects
;
179 data
= read_dev_sector(bdev
, start_blk
* 2 + 6, §
);
183 if (slot
== state
->limit
)
186 dr
= adfs_partition(state
, name
, data
, first_sector
, slot
++);
192 nr_sects
= (data
[0x1fd] + (data
[0x1fe] << 8)) *
193 (dr
->heads
+ (dr
->lowsector
& 0x40 ? 1 : 0)) *
200 first_sector
+= nr_sects
;
201 start_blk
+= nr_sects
>> (BLOCK_SIZE_BITS
- 9);
202 nr_sects
= 0; /* hmm - should be partition size */
204 switch (data
[0x1fc] & 15) {
205 case 0: /* No partition / ADFS? */
208 #ifdef CONFIG_ACORN_PARTITION_RISCIX
209 case PARTITION_RISCIX_SCSI
:
210 /* RISCiX - we don't know how to find the next one. */
211 slot
= riscix_partition(state
, bdev
, first_sector
,
216 case PARTITION_LINUX
:
217 slot
= linux_partition(state
, bdev
, first_sector
,
221 put_dev_sector(sect
);
225 put_dev_sector(sect
);
226 return first
? 0 : 1;
230 #ifdef CONFIG_ACORN_PARTITION_ADFS
232 * Purpose: allocate ADFS partitions.
234 * Params : hd - pointer to gendisk structure to store partition info.
235 * dev - device number to access.
237 * Returns: -1 on error, 0 for no ADFS boot sector, 1 for ok.
239 * Alloc : hda = whole drive
240 * hda1 = ADFS partition on first drive.
241 * hda2 = non-ADFS partition.
244 adfspart_check_ADFS(struct parsed_partitions
*state
, struct block_device
*bdev
)
246 unsigned long start_sect
, nr_sects
, sectscyl
, heads
;
249 struct adfs_discrecord
*dr
;
253 data
= read_dev_sector(bdev
, 6, §
);
257 dr
= adfs_partition(state
, "ADFS", data
, 0, slot
++);
259 put_dev_sector(sect
);
263 heads
= dr
->heads
+ ((dr
->lowsector
>> 6) & 1);
264 sectscyl
= dr
->secspertrack
* heads
;
265 start_sect
= ((data
[0x1fe] << 8) + data
[0x1fd]) * sectscyl
;
266 id
= data
[0x1fc] & 15;
267 put_dev_sector(sect
);
269 #ifdef CONFIG_BLK_DEV_MFM
270 if (MAJOR(bdev
->bd_dev
) == MFM_ACORN_MAJOR
) {
271 extern void xd_set_geometry(struct block_device
*,
272 unsigned char, unsigned char, unsigned int);
273 xd_set_geometry(bdev
, dr
->secspertrack
, heads
, 1);
274 invalidate_bdev(bdev
, 1);
275 truncate_inode_pages(bdev
->bd_inode
->i_mapping
, 0);
280 * Work out start of non-adfs partition.
282 nr_sects
= (bdev
->bd_inode
->i_size
>> 9) - start_sect
;
286 #ifdef CONFIG_ACORN_PARTITION_RISCIX
287 case PARTITION_RISCIX_SCSI
:
288 case PARTITION_RISCIX_MFM
:
289 slot
= riscix_partition(state
, bdev
, start_sect
,
294 case PARTITION_LINUX
:
295 slot
= linux_partition(state
, bdev
, start_sect
,
305 #ifdef CONFIG_ACORN_PARTITION_ICS
312 static int adfspart_check_ICSLinux(struct block_device
*bdev
, unsigned long block
)
315 unsigned char *data
= read_dev_sector(bdev
, block
, §
);
319 if (memcmp(data
, "LinuxPart", 9) == 0)
321 put_dev_sector(sect
);
328 * Check for a valid ICS partition using the checksum.
330 static inline int valid_ics_sector(const unsigned char *data
)
335 for (i
= 0, sum
= 0x50617274; i
< 508; i
++)
338 sum
-= le32_to_cpu(*(__le32
*)(&data
[508]));
344 * Purpose: allocate ICS partitions.
345 * Params : hd - pointer to gendisk structure to store partition info.
346 * dev - device number to access.
347 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
348 * Alloc : hda = whole drive
349 * hda1 = ADFS partition 0 on first drive.
350 * hda2 = ADFS partition 1 on first drive.
354 adfspart_check_ICS(struct parsed_partitions
*state
, struct block_device
*bdev
)
356 const unsigned char *data
;
357 const struct ics_part
*p
;
362 * Try ICS style partitions - sector 0 contains partition info.
364 data
= read_dev_sector(bdev
, 0, §
);
368 if (!valid_ics_sector(data
)) {
369 put_dev_sector(sect
);
375 for (slot
= 1, p
= (const struct ics_part
*)data
; p
->size
; p
++) {
376 u32 start
= le32_to_cpu(p
->start
);
377 s32 size
= le32_to_cpu(p
->size
); /* yes, it's signed. */
379 if (slot
== state
->limit
)
383 * Negative sizes tell the RISC OS ICS driver to ignore
384 * this partition - in effect it says that this does not
385 * contain an ADFS filesystem.
391 * Our own extension - We use the first sector
392 * of the partition to identify what type this
393 * partition is. We must not make this visible
396 if (size
> 1 && adfspart_check_ICSLinux(bdev
, start
)) {
403 put_partition(state
, slot
++, start
, size
);
406 put_dev_sector(sect
);
412 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
422 static inline int valid_ptec_sector(const unsigned char *data
)
424 unsigned char checksum
= 0x2a;
428 * If it looks like a PC/BIOS partition, then it
429 * probably isn't PowerTec.
431 if (data
[510] == 0x55 && data
[511] == 0xaa)
434 for (i
= 0; i
< 511; i
++)
437 return checksum
== data
[511];
441 * Purpose: allocate ICS partitions.
442 * Params : hd - pointer to gendisk structure to store partition info.
443 * dev - device number to access.
444 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
445 * Alloc : hda = whole drive
446 * hda1 = ADFS partition 0 on first drive.
447 * hda2 = ADFS partition 1 on first drive.
451 adfspart_check_POWERTEC(struct parsed_partitions
*state
, struct block_device
*bdev
)
454 const unsigned char *data
;
455 const struct ptec_part
*p
;
459 data
= read_dev_sector(bdev
, 0, §
);
463 if (!valid_ptec_sector(data
)) {
464 put_dev_sector(sect
);
468 printk(" [POWERTEC]");
470 for (i
= 0, p
= (const struct ptec_part
*)data
; i
< 12; i
++, p
++) {
471 u32 start
= le32_to_cpu(p
->start
);
472 u32 size
= le32_to_cpu(p
->size
);
475 put_partition(state
, slot
++, start
, size
);
478 put_dev_sector(sect
);
484 #ifdef CONFIG_ACORN_PARTITION_EESOX
495 * Guess who created this format?
497 static const char eesox_name
[] = {
498 'N', 'e', 'i', 'l', ' ',
499 'C', 'r', 'i', 't', 'c', 'h', 'e', 'l', 'l', ' ', ' '
503 * EESOX SCSI partition format.
505 * This is a goddamned awful partition format. We don't seem to store
506 * the size of the partition in this table, only the start addresses.
508 * There are two possibilities where the size comes from:
509 * 1. The individual ADFS boot block entries that are placed on the disk.
510 * 2. The start address of the next entry.
513 adfspart_check_EESOX(struct parsed_partitions
*state
, struct block_device
*bdev
)
516 const unsigned char *data
;
517 unsigned char buffer
[256];
518 struct eesox_part
*p
;
522 data
= read_dev_sector(bdev
, 7, §
);
527 * "Decrypt" the partition table. God knows why...
529 for (i
= 0; i
< 256; i
++)
530 buffer
[i
] = data
[i
] ^ eesox_name
[i
& 15];
532 put_dev_sector(sect
);
534 for (i
= 0, p
= (struct eesox_part
*)buffer
; i
< 8; i
++, p
++) {
537 if (memcmp(p
->magic
, "Eesox", 6))
540 next
= le32_to_cpu(p
->start
);
542 put_partition(state
, slot
++, start
, next
- start
);
549 size
= get_capacity(bdev
->bd_disk
);
550 put_partition(state
, slot
++, start
, size
- start
);