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 #if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
29 defined(CONFIG_ACORN_PARTITION_ADFS)
30 static struct adfs_discrecord
*
31 adfs_partition(struct parsed_partitions
*state
, char *name
, char *data
,
32 unsigned long first_sector
, int slot
)
34 struct adfs_discrecord
*dr
;
35 unsigned int nr_sects
;
37 if (adfs_checkbblk(data
))
40 dr
= (struct adfs_discrecord
*)(data
+ 0x1c0);
42 if (dr
->disc_size
== 0 && dr
->disc_size_high
== 0)
45 nr_sects
= (le32_to_cpu(dr
->disc_size_high
) << 23) |
46 (le32_to_cpu(dr
->disc_size
) >> 9);
49 printk(" [%s]", name
);
50 put_partition(state
, slot
, first_sector
, nr_sects
);
55 #ifdef CONFIG_ACORN_PARTITION_RISCIX
64 struct riscix_record
{
66 #define RISCIX_MAGIC cpu_to_le32(0x4a657320)
68 struct riscix_part part
[8];
71 #if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
72 defined(CONFIG_ACORN_PARTITION_ADFS)
73 static int riscix_partition(struct parsed_partitions
*state
,
74 unsigned long first_sect
, int slot
,
75 unsigned long nr_sects
)
78 struct riscix_record
*rr
;
80 rr
= read_part_sector(state
, first_sect
, §
);
87 if (rr
->magic
== RISCIX_MAGIC
) {
88 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
93 put_partition(state
, slot
++, first_sect
, size
);
94 for (part
= 0; part
< 8; part
++) {
95 if (rr
->part
[part
].one
&&
96 memcmp(rr
->part
[part
].name
, "All\0", 4)) {
97 put_partition(state
, slot
++,
98 le32_to_cpu(rr
->part
[part
].start
),
99 le32_to_cpu(rr
->part
[part
].length
));
100 printk("(%s)", rr
->part
[part
].name
);
106 put_partition(state
, slot
++, first_sect
, nr_sects
);
109 put_dev_sector(sect
);
115 #define LINUX_NATIVE_MAGIC 0xdeafa1de
116 #define LINUX_SWAP_MAGIC 0xdeafab1e
124 #if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
125 defined(CONFIG_ACORN_PARTITION_ADFS)
126 static int linux_partition(struct parsed_partitions
*state
,
127 unsigned long first_sect
, int slot
,
128 unsigned long nr_sects
)
131 struct linux_part
*linuxp
;
132 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
136 put_partition(state
, slot
++, first_sect
, size
);
138 linuxp
= read_part_sector(state
, first_sect
, §
);
143 while (linuxp
->magic
== cpu_to_le32(LINUX_NATIVE_MAGIC
) ||
144 linuxp
->magic
== cpu_to_le32(LINUX_SWAP_MAGIC
)) {
145 if (slot
== state
->limit
)
147 put_partition(state
, slot
++, first_sect
+
148 le32_to_cpu(linuxp
->start_sect
),
149 le32_to_cpu(linuxp
->nr_sects
));
154 put_dev_sector(sect
);
159 #ifdef CONFIG_ACORN_PARTITION_CUMANA
160 int adfspart_check_CUMANA(struct parsed_partitions
*state
)
162 unsigned long first_sector
= 0;
163 unsigned int start_blk
= 0;
166 char *name
= "CUMANA/ADFS";
171 * Try Cumana style partitions - sector 6 contains ADFS boot block
172 * with pointer to next 'drive'.
174 * There are unknowns in this code - is the 'cylinder number' of the
175 * next partition relative to the start of this one - I'm assuming
178 * Also, which ID did Cumana use?
180 * This is totally unfinished, and will require more work to get it
181 * going. Hence it is totally untested.
184 struct adfs_discrecord
*dr
;
185 unsigned int nr_sects
;
187 data
= read_part_sector(state
, start_blk
* 2 + 6, §
);
191 if (slot
== state
->limit
)
194 dr
= adfs_partition(state
, name
, data
, first_sector
, slot
++);
200 nr_sects
= (data
[0x1fd] + (data
[0x1fe] << 8)) *
201 (dr
->heads
+ (dr
->lowsector
& 0x40 ? 1 : 0)) *
208 first_sector
+= nr_sects
;
209 start_blk
+= nr_sects
>> (BLOCK_SIZE_BITS
- 9);
210 nr_sects
= 0; /* hmm - should be partition size */
212 switch (data
[0x1fc] & 15) {
213 case 0: /* No partition / ADFS? */
216 #ifdef CONFIG_ACORN_PARTITION_RISCIX
217 case PARTITION_RISCIX_SCSI
:
218 /* RISCiX - we don't know how to find the next one. */
219 slot
= riscix_partition(state
, first_sector
, slot
,
224 case PARTITION_LINUX
:
225 slot
= linux_partition(state
, first_sector
, slot
,
229 put_dev_sector(sect
);
233 put_dev_sector(sect
);
234 return first
? 0 : 1;
238 #ifdef CONFIG_ACORN_PARTITION_ADFS
240 * Purpose: allocate ADFS partitions.
242 * Params : hd - pointer to gendisk structure to store partition info.
243 * dev - device number to access.
245 * Returns: -1 on error, 0 for no ADFS boot sector, 1 for ok.
247 * Alloc : hda = whole drive
248 * hda1 = ADFS partition on first drive.
249 * hda2 = non-ADFS partition.
251 int adfspart_check_ADFS(struct parsed_partitions
*state
)
253 unsigned long start_sect
, nr_sects
, sectscyl
, heads
;
256 struct adfs_discrecord
*dr
;
260 data
= read_part_sector(state
, 6, §
);
264 dr
= adfs_partition(state
, "ADFS", data
, 0, slot
++);
266 put_dev_sector(sect
);
270 heads
= dr
->heads
+ ((dr
->lowsector
>> 6) & 1);
271 sectscyl
= dr
->secspertrack
* heads
;
272 start_sect
= ((data
[0x1fe] << 8) + data
[0x1fd]) * sectscyl
;
273 id
= data
[0x1fc] & 15;
274 put_dev_sector(sect
);
277 * Work out start of non-adfs partition.
279 nr_sects
= (state
->bdev
->bd_inode
->i_size
>> 9) - start_sect
;
283 #ifdef CONFIG_ACORN_PARTITION_RISCIX
284 case PARTITION_RISCIX_SCSI
:
285 case PARTITION_RISCIX_MFM
:
286 slot
= riscix_partition(state
, start_sect
, slot
,
291 case PARTITION_LINUX
:
292 slot
= linux_partition(state
, start_sect
, slot
,
302 #ifdef CONFIG_ACORN_PARTITION_ICS
309 static int adfspart_check_ICSLinux(struct parsed_partitions
*state
,
313 unsigned char *data
= read_part_sector(state
, block
, §
);
317 if (memcmp(data
, "LinuxPart", 9) == 0)
319 put_dev_sector(sect
);
326 * Check for a valid ICS partition using the checksum.
328 static inline int valid_ics_sector(const unsigned char *data
)
333 for (i
= 0, sum
= 0x50617274; i
< 508; i
++)
336 sum
-= le32_to_cpu(*(__le32
*)(&data
[508]));
342 * Purpose: allocate ICS partitions.
343 * Params : hd - pointer to gendisk structure to store partition info.
344 * dev - device number to access.
345 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
346 * Alloc : hda = whole drive
347 * hda1 = ADFS partition 0 on first drive.
348 * hda2 = ADFS partition 1 on first drive.
351 int adfspart_check_ICS(struct parsed_partitions
*state
)
353 const unsigned char *data
;
354 const struct ics_part
*p
;
359 * Try ICS style partitions - sector 0 contains partition info.
361 data
= read_part_sector(state
, 0, §
);
365 if (!valid_ics_sector(data
)) {
366 put_dev_sector(sect
);
372 for (slot
= 1, p
= (const struct ics_part
*)data
; p
->size
; p
++) {
373 u32 start
= le32_to_cpu(p
->start
);
374 s32 size
= le32_to_cpu(p
->size
); /* yes, it's signed. */
376 if (slot
== state
->limit
)
380 * Negative sizes tell the RISC OS ICS driver to ignore
381 * this partition - in effect it says that this does not
382 * contain an ADFS filesystem.
388 * Our own extension - We use the first sector
389 * of the partition to identify what type this
390 * partition is. We must not make this visible
393 if (size
> 1 && adfspart_check_ICSLinux(state
, start
)) {
400 put_partition(state
, slot
++, start
, size
);
403 put_dev_sector(sect
);
409 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
419 static inline int valid_ptec_sector(const unsigned char *data
)
421 unsigned char checksum
= 0x2a;
425 * If it looks like a PC/BIOS partition, then it
426 * probably isn't PowerTec.
428 if (data
[510] == 0x55 && data
[511] == 0xaa)
431 for (i
= 0; i
< 511; i
++)
434 return checksum
== data
[511];
438 * Purpose: allocate ICS partitions.
439 * Params : hd - pointer to gendisk structure to store partition info.
440 * dev - device number to access.
441 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
442 * Alloc : hda = whole drive
443 * hda1 = ADFS partition 0 on first drive.
444 * hda2 = ADFS partition 1 on first drive.
447 int adfspart_check_POWERTEC(struct parsed_partitions
*state
)
450 const unsigned char *data
;
451 const struct ptec_part
*p
;
455 data
= read_part_sector(state
, 0, §
);
459 if (!valid_ptec_sector(data
)) {
460 put_dev_sector(sect
);
464 printk(" [POWERTEC]");
466 for (i
= 0, p
= (const struct ptec_part
*)data
; i
< 12; i
++, p
++) {
467 u32 start
= le32_to_cpu(p
->start
);
468 u32 size
= le32_to_cpu(p
->size
);
471 put_partition(state
, slot
++, start
, size
);
474 put_dev_sector(sect
);
480 #ifdef CONFIG_ACORN_PARTITION_EESOX
491 * Guess who created this format?
493 static const char eesox_name
[] = {
494 'N', 'e', 'i', 'l', ' ',
495 'C', 'r', 'i', 't', 'c', 'h', 'e', 'l', 'l', ' ', ' '
499 * EESOX SCSI partition format.
501 * This is a goddamned awful partition format. We don't seem to store
502 * the size of the partition in this table, only the start addresses.
504 * There are two possibilities where the size comes from:
505 * 1. The individual ADFS boot block entries that are placed on the disk.
506 * 2. The start address of the next entry.
508 int adfspart_check_EESOX(struct parsed_partitions
*state
)
511 const unsigned char *data
;
512 unsigned char buffer
[256];
513 struct eesox_part
*p
;
517 data
= read_part_sector(state
, 7, §
);
522 * "Decrypt" the partition table. God knows why...
524 for (i
= 0; i
< 256; i
++)
525 buffer
[i
] = data
[i
] ^ eesox_name
[i
& 15];
527 put_dev_sector(sect
);
529 for (i
= 0, p
= (struct eesox_part
*)buffer
; i
< 8; i
++, p
++) {
532 if (memcmp(p
->magic
, "Eesox", 6))
535 next
= le32_to_cpu(p
->start
);
537 put_partition(state
, slot
++, start
, next
- start
);
544 size
= get_capacity(state
->bdev
->bd_disk
);
545 put_partition(state
, slot
++, start
, size
- start
);