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/config.h>
16 #include <linux/buffer_head.h>
17 #include <linux/adfs_fs.h>
23 * Partition types. (Oh for reusability)
25 #define PARTITION_RISCIX_MFM 1
26 #define PARTITION_RISCIX_SCSI 2
27 #define PARTITION_LINUX 9
29 static struct adfs_discrecord
*
30 adfs_partition(struct parsed_partitions
*state
, char *name
, char *data
,
31 unsigned long first_sector
, int slot
)
33 struct adfs_discrecord
*dr
;
34 unsigned int nr_sects
;
36 if (adfs_checkbblk(data
))
39 dr
= (struct adfs_discrecord
*)(data
+ 0x1c0);
41 if (dr
->disc_size
== 0 && dr
->disc_size_high
== 0)
44 nr_sects
= (le32_to_cpu(dr
->disc_size_high
) << 23) |
45 (le32_to_cpu(dr
->disc_size
) >> 9);
48 printk(" [%s]", name
);
49 put_partition(state
, slot
, first_sector
, nr_sects
);
53 #ifdef CONFIG_ACORN_PARTITION_RISCIX
62 struct riscix_record
{
64 #define RISCIX_MAGIC cpu_to_le32(0x4a657320)
66 struct riscix_part part
[8];
70 riscix_partition(struct parsed_partitions
*state
, struct block_device
*bdev
,
71 unsigned long first_sect
, int slot
, unsigned long nr_sects
)
74 struct riscix_record
*rr
;
76 rr
= (struct riscix_record
*)read_dev_sector(bdev
, first_sect
, §
);
83 if (rr
->magic
== RISCIX_MAGIC
) {
84 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
89 put_partition(state
, slot
++, first_sect
, size
);
90 for (part
= 0; part
< 8; part
++) {
91 if (rr
->part
[part
].one
&&
92 memcmp(rr
->part
[part
].name
, "All\0", 4)) {
93 put_partition(state
, slot
++,
94 le32_to_cpu(rr
->part
[part
].start
),
95 le32_to_cpu(rr
->part
[part
].length
));
96 printk("(%s)", rr
->part
[part
].name
);
102 put_partition(state
, slot
++, first_sect
, nr_sects
);
105 put_dev_sector(sect
);
110 #define LINUX_NATIVE_MAGIC 0xdeafa1de
111 #define LINUX_SWAP_MAGIC 0xdeafab1e
120 linux_partition(struct parsed_partitions
*state
, struct block_device
*bdev
,
121 unsigned long first_sect
, int slot
, unsigned long nr_sects
)
124 struct linux_part
*linuxp
;
125 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
129 put_partition(state
, slot
++, first_sect
, size
);
131 linuxp
= (struct linux_part
*)read_dev_sector(bdev
, first_sect
, §
);
136 while (linuxp
->magic
== cpu_to_le32(LINUX_NATIVE_MAGIC
) ||
137 linuxp
->magic
== cpu_to_le32(LINUX_SWAP_MAGIC
)) {
138 if (slot
== state
->limit
)
140 put_partition(state
, slot
++, first_sect
+
141 le32_to_cpu(linuxp
->start_sect
),
142 le32_to_cpu(linuxp
->nr_sects
));
147 put_dev_sector(sect
);
151 #ifdef CONFIG_ACORN_PARTITION_CUMANA
153 adfspart_check_CUMANA(struct parsed_partitions
*state
, struct block_device
*bdev
)
155 unsigned long first_sector
= 0;
156 unsigned int start_blk
= 0;
159 char *name
= "CUMANA/ADFS";
164 * Try Cumana style partitions - sector 6 contains ADFS boot block
165 * with pointer to next 'drive'.
167 * There are unknowns in this code - is the 'cylinder number' of the
168 * next partition relative to the start of this one - I'm assuming
171 * Also, which ID did Cumana use?
173 * This is totally unfinished, and will require more work to get it
174 * going. Hence it is totally untested.
177 struct adfs_discrecord
*dr
;
178 unsigned int nr_sects
;
180 data
= read_dev_sector(bdev
, start_blk
* 2 + 6, §
);
184 if (slot
== state
->limit
)
187 dr
= adfs_partition(state
, name
, data
, first_sector
, slot
++);
193 nr_sects
= (data
[0x1fd] + (data
[0x1fe] << 8)) *
194 (dr
->heads
+ (dr
->lowsector
& 0x40 ? 1 : 0)) *
201 first_sector
+= nr_sects
;
202 start_blk
+= nr_sects
>> (BLOCK_SIZE_BITS
- 9);
203 nr_sects
= 0; /* hmm - should be partition size */
205 switch (data
[0x1fc] & 15) {
206 case 0: /* No partition / ADFS? */
209 #ifdef CONFIG_ACORN_PARTITION_RISCIX
210 case PARTITION_RISCIX_SCSI
:
211 /* RISCiX - we don't know how to find the next one. */
212 slot
= riscix_partition(state
, bdev
, first_sector
,
217 case PARTITION_LINUX
:
218 slot
= linux_partition(state
, bdev
, first_sector
,
222 put_dev_sector(sect
);
226 put_dev_sector(sect
);
227 return first
? 0 : 1;
231 #ifdef CONFIG_ACORN_PARTITION_ADFS
233 * Purpose: allocate ADFS partitions.
235 * Params : hd - pointer to gendisk structure to store partition info.
236 * dev - device number to access.
238 * Returns: -1 on error, 0 for no ADFS boot sector, 1 for ok.
240 * Alloc : hda = whole drive
241 * hda1 = ADFS partition on first drive.
242 * hda2 = non-ADFS partition.
245 adfspart_check_ADFS(struct parsed_partitions
*state
, struct block_device
*bdev
)
247 unsigned long start_sect
, nr_sects
, sectscyl
, heads
;
250 struct adfs_discrecord
*dr
;
254 data
= read_dev_sector(bdev
, 6, §
);
258 dr
= adfs_partition(state
, "ADFS", data
, 0, slot
++);
260 put_dev_sector(sect
);
264 heads
= dr
->heads
+ ((dr
->lowsector
>> 6) & 1);
265 sectscyl
= dr
->secspertrack
* heads
;
266 start_sect
= ((data
[0x1fe] << 8) + data
[0x1fd]) * sectscyl
;
267 id
= data
[0x1fc] & 15;
268 put_dev_sector(sect
);
270 #ifdef CONFIG_BLK_DEV_MFM
271 if (MAJOR(bdev
->bd_dev
) == MFM_ACORN_MAJOR
) {
272 extern void xd_set_geometry(struct block_device
*,
273 unsigned char, unsigned char, unsigned int);
274 xd_set_geometry(bdev
, dr
->secspertrack
, heads
, 1);
275 invalidate_bdev(bdev
, 1);
276 truncate_inode_pages(bdev
->bd_inode
->i_mapping
, 0);
281 * Work out start of non-adfs partition.
283 nr_sects
= (bdev
->bd_inode
->i_size
>> 9) - start_sect
;
287 #ifdef CONFIG_ACORN_PARTITION_RISCIX
288 case PARTITION_RISCIX_SCSI
:
289 case PARTITION_RISCIX_MFM
:
290 slot
= riscix_partition(state
, bdev
, start_sect
,
295 case PARTITION_LINUX
:
296 slot
= linux_partition(state
, bdev
, start_sect
,
306 #ifdef CONFIG_ACORN_PARTITION_ICS
313 static int adfspart_check_ICSLinux(struct block_device
*bdev
, unsigned long block
)
316 unsigned char *data
= read_dev_sector(bdev
, block
, §
);
320 if (memcmp(data
, "LinuxPart", 9) == 0)
322 put_dev_sector(sect
);
329 * Check for a valid ICS partition using the checksum.
331 static inline int valid_ics_sector(const unsigned char *data
)
336 for (i
= 0, sum
= 0x50617274; i
< 508; i
++)
339 sum
-= le32_to_cpu(*(__le32
*)(&data
[508]));
345 * Purpose: allocate ICS partitions.
346 * Params : hd - pointer to gendisk structure to store partition info.
347 * dev - device number to access.
348 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
349 * Alloc : hda = whole drive
350 * hda1 = ADFS partition 0 on first drive.
351 * hda2 = ADFS partition 1 on first drive.
355 adfspart_check_ICS(struct parsed_partitions
*state
, struct block_device
*bdev
)
357 const unsigned char *data
;
358 const struct ics_part
*p
;
363 * Try ICS style partitions - sector 0 contains partition info.
365 data
= read_dev_sector(bdev
, 0, §
);
369 if (!valid_ics_sector(data
)) {
370 put_dev_sector(sect
);
376 for (slot
= 1, p
= (const struct ics_part
*)data
; p
->size
; p
++) {
377 u32 start
= le32_to_cpu(p
->start
);
378 s32 size
= le32_to_cpu(p
->size
); /* yes, it's signed. */
380 if (slot
== state
->limit
)
384 * Negative sizes tell the RISC OS ICS driver to ignore
385 * this partition - in effect it says that this does not
386 * contain an ADFS filesystem.
392 * Our own extension - We use the first sector
393 * of the partition to identify what type this
394 * partition is. We must not make this visible
397 if (size
> 1 && adfspart_check_ICSLinux(bdev
, start
)) {
404 put_partition(state
, slot
++, start
, size
);
407 put_dev_sector(sect
);
413 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
423 static inline int valid_ptec_sector(const unsigned char *data
)
425 unsigned char checksum
= 0x2a;
429 * If it looks like a PC/BIOS partition, then it
430 * probably isn't PowerTec.
432 if (data
[510] == 0x55 && data
[511] == 0xaa)
435 for (i
= 0; i
< 511; i
++)
438 return checksum
== data
[511];
442 * Purpose: allocate ICS partitions.
443 * Params : hd - pointer to gendisk structure to store partition info.
444 * dev - device number to access.
445 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
446 * Alloc : hda = whole drive
447 * hda1 = ADFS partition 0 on first drive.
448 * hda2 = ADFS partition 1 on first drive.
452 adfspart_check_POWERTEC(struct parsed_partitions
*state
, struct block_device
*bdev
)
455 const unsigned char *data
;
456 const struct ptec_part
*p
;
460 data
= read_dev_sector(bdev
, 0, §
);
464 if (!valid_ptec_sector(data
)) {
465 put_dev_sector(sect
);
469 printk(" [POWERTEC]");
471 for (i
= 0, p
= (const struct ptec_part
*)data
; i
< 12; i
++, p
++) {
472 u32 start
= le32_to_cpu(p
->start
);
473 u32 size
= le32_to_cpu(p
->size
);
476 put_partition(state
, slot
++, start
, size
);
479 put_dev_sector(sect
);
485 #ifdef CONFIG_ACORN_PARTITION_EESOX
496 * Guess who created this format?
498 static const char eesox_name
[] = {
499 'N', 'e', 'i', 'l', ' ',
500 'C', 'r', 'i', 't', 'c', 'h', 'e', 'l', 'l', ' ', ' '
504 * EESOX SCSI partition format.
506 * This is a goddamned awful partition format. We don't seem to store
507 * the size of the partition in this table, only the start addresses.
509 * There are two possibilities where the size comes from:
510 * 1. The individual ADFS boot block entries that are placed on the disk.
511 * 2. The start address of the next entry.
514 adfspart_check_EESOX(struct parsed_partitions
*state
, struct block_device
*bdev
)
517 const unsigned char *data
;
518 unsigned char buffer
[256];
519 struct eesox_part
*p
;
523 data
= read_dev_sector(bdev
, 7, §
);
528 * "Decrypt" the partition table. God knows why...
530 for (i
= 0; i
< 256; i
++)
531 buffer
[i
] = data
[i
] ^ eesox_name
[i
& 15];
533 put_dev_sector(sect
);
535 for (i
= 0, p
= (struct eesox_part
*)buffer
; i
< 8; i
++, p
++) {
538 if (memcmp(p
->magic
, "Eesox", 6))
541 next
= le32_to_cpu(p
->start
);
543 put_partition(state
, slot
++, start
, next
- start
);
550 size
= get_capacity(bdev
->bd_disk
);
551 put_partition(state
, slot
++, start
, size
- start
);