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 strlcat(state
->pp_buf
, " [", PAGE_SIZE
);
50 strlcat(state
->pp_buf
, name
, PAGE_SIZE
);
51 strlcat(state
->pp_buf
, "]", PAGE_SIZE
);
53 put_partition(state
, slot
, first_sector
, nr_sects
);
58 #ifdef CONFIG_ACORN_PARTITION_RISCIX
67 struct riscix_record
{
69 #define RISCIX_MAGIC cpu_to_le32(0x4a657320)
71 struct riscix_part part
[8];
74 #if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
75 defined(CONFIG_ACORN_PARTITION_ADFS)
76 static int riscix_partition(struct parsed_partitions
*state
,
77 unsigned long first_sect
, int slot
,
78 unsigned long nr_sects
)
81 struct riscix_record
*rr
;
83 rr
= read_part_sector(state
, first_sect
, §
);
87 strlcat(state
->pp_buf
, " [RISCiX]", PAGE_SIZE
);
90 if (rr
->magic
== RISCIX_MAGIC
) {
91 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
94 strlcat(state
->pp_buf
, " <", PAGE_SIZE
);
96 put_partition(state
, slot
++, first_sect
, size
);
97 for (part
= 0; part
< 8; part
++) {
98 if (rr
->part
[part
].one
&&
99 memcmp(rr
->part
[part
].name
, "All\0", 4)) {
100 put_partition(state
, slot
++,
101 le32_to_cpu(rr
->part
[part
].start
),
102 le32_to_cpu(rr
->part
[part
].length
));
103 strlcat(state
->pp_buf
, "(", PAGE_SIZE
);
104 strlcat(state
->pp_buf
, rr
->part
[part
].name
, PAGE_SIZE
);
105 strlcat(state
->pp_buf
, ")", PAGE_SIZE
);
109 strlcat(state
->pp_buf
, " >\n", PAGE_SIZE
);
111 put_partition(state
, slot
++, first_sect
, nr_sects
);
114 put_dev_sector(sect
);
120 #define LINUX_NATIVE_MAGIC 0xdeafa1de
121 #define LINUX_SWAP_MAGIC 0xdeafab1e
129 #if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
130 defined(CONFIG_ACORN_PARTITION_ADFS)
131 static int linux_partition(struct parsed_partitions
*state
,
132 unsigned long first_sect
, int slot
,
133 unsigned long nr_sects
)
136 struct linux_part
*linuxp
;
137 unsigned long size
= nr_sects
> 2 ? 2 : nr_sects
;
139 strlcat(state
->pp_buf
, " [Linux]", PAGE_SIZE
);
141 put_partition(state
, slot
++, first_sect
, size
);
143 linuxp
= read_part_sector(state
, first_sect
, §
);
147 strlcat(state
->pp_buf
, " <", PAGE_SIZE
);
148 while (linuxp
->magic
== cpu_to_le32(LINUX_NATIVE_MAGIC
) ||
149 linuxp
->magic
== cpu_to_le32(LINUX_SWAP_MAGIC
)) {
150 if (slot
== state
->limit
)
152 put_partition(state
, slot
++, first_sect
+
153 le32_to_cpu(linuxp
->start_sect
),
154 le32_to_cpu(linuxp
->nr_sects
));
157 strlcat(state
->pp_buf
, " >", PAGE_SIZE
);
159 put_dev_sector(sect
);
164 #ifdef CONFIG_ACORN_PARTITION_CUMANA
165 int adfspart_check_CUMANA(struct parsed_partitions
*state
)
167 unsigned long first_sector
= 0;
168 unsigned int start_blk
= 0;
171 char *name
= "CUMANA/ADFS";
176 * Try Cumana style partitions - sector 6 contains ADFS boot block
177 * with pointer to next 'drive'.
179 * There are unknowns in this code - is the 'cylinder number' of the
180 * next partition relative to the start of this one - I'm assuming
183 * Also, which ID did Cumana use?
185 * This is totally unfinished, and will require more work to get it
186 * going. Hence it is totally untested.
189 struct adfs_discrecord
*dr
;
190 unsigned int nr_sects
;
192 data
= read_part_sector(state
, start_blk
* 2 + 6, §
);
196 if (slot
== state
->limit
)
199 dr
= adfs_partition(state
, name
, data
, first_sector
, slot
++);
205 nr_sects
= (data
[0x1fd] + (data
[0x1fe] << 8)) *
206 (dr
->heads
+ (dr
->lowsector
& 0x40 ? 1 : 0)) *
213 first_sector
+= nr_sects
;
214 start_blk
+= nr_sects
>> (BLOCK_SIZE_BITS
- 9);
215 nr_sects
= 0; /* hmm - should be partition size */
217 switch (data
[0x1fc] & 15) {
218 case 0: /* No partition / ADFS? */
221 #ifdef CONFIG_ACORN_PARTITION_RISCIX
222 case PARTITION_RISCIX_SCSI
:
223 /* RISCiX - we don't know how to find the next one. */
224 slot
= riscix_partition(state
, first_sector
, slot
,
229 case PARTITION_LINUX
:
230 slot
= linux_partition(state
, first_sector
, slot
,
234 put_dev_sector(sect
);
238 put_dev_sector(sect
);
239 return first
? 0 : 1;
243 #ifdef CONFIG_ACORN_PARTITION_ADFS
245 * Purpose: allocate ADFS partitions.
247 * Params : hd - pointer to gendisk structure to store partition info.
248 * dev - device number to access.
250 * Returns: -1 on error, 0 for no ADFS boot sector, 1 for ok.
252 * Alloc : hda = whole drive
253 * hda1 = ADFS partition on first drive.
254 * hda2 = non-ADFS partition.
256 int adfspart_check_ADFS(struct parsed_partitions
*state
)
258 unsigned long start_sect
, nr_sects
, sectscyl
, heads
;
261 struct adfs_discrecord
*dr
;
265 data
= read_part_sector(state
, 6, §
);
269 dr
= adfs_partition(state
, "ADFS", data
, 0, slot
++);
271 put_dev_sector(sect
);
275 heads
= dr
->heads
+ ((dr
->lowsector
>> 6) & 1);
276 sectscyl
= dr
->secspertrack
* heads
;
277 start_sect
= ((data
[0x1fe] << 8) + data
[0x1fd]) * sectscyl
;
278 id
= data
[0x1fc] & 15;
279 put_dev_sector(sect
);
282 * Work out start of non-adfs partition.
284 nr_sects
= (state
->bdev
->bd_inode
->i_size
>> 9) - start_sect
;
288 #ifdef CONFIG_ACORN_PARTITION_RISCIX
289 case PARTITION_RISCIX_SCSI
:
290 case PARTITION_RISCIX_MFM
:
291 slot
= riscix_partition(state
, start_sect
, slot
,
296 case PARTITION_LINUX
:
297 slot
= linux_partition(state
, start_sect
, slot
,
302 strlcat(state
->pp_buf
, "\n", PAGE_SIZE
);
307 #ifdef CONFIG_ACORN_PARTITION_ICS
314 static int adfspart_check_ICSLinux(struct parsed_partitions
*state
,
318 unsigned char *data
= read_part_sector(state
, block
, §
);
322 if (memcmp(data
, "LinuxPart", 9) == 0)
324 put_dev_sector(sect
);
331 * Check for a valid ICS partition using the checksum.
333 static inline int valid_ics_sector(const unsigned char *data
)
338 for (i
= 0, sum
= 0x50617274; i
< 508; i
++)
341 sum
-= le32_to_cpu(*(__le32
*)(&data
[508]));
347 * Purpose: allocate ICS partitions.
348 * Params : hd - pointer to gendisk structure to store partition info.
349 * dev - device number to access.
350 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
351 * Alloc : hda = whole drive
352 * hda1 = ADFS partition 0 on first drive.
353 * hda2 = ADFS partition 1 on first drive.
356 int adfspart_check_ICS(struct parsed_partitions
*state
)
358 const unsigned char *data
;
359 const struct ics_part
*p
;
364 * Try ICS style partitions - sector 0 contains partition info.
366 data
= read_part_sector(state
, 0, §
);
370 if (!valid_ics_sector(data
)) {
371 put_dev_sector(sect
);
375 strlcat(state
->pp_buf
, " [ICS]", PAGE_SIZE
);
377 for (slot
= 1, p
= (const struct ics_part
*)data
; p
->size
; p
++) {
378 u32 start
= le32_to_cpu(p
->start
);
379 s32 size
= le32_to_cpu(p
->size
); /* yes, it's signed. */
381 if (slot
== state
->limit
)
385 * Negative sizes tell the RISC OS ICS driver to ignore
386 * this partition - in effect it says that this does not
387 * contain an ADFS filesystem.
393 * Our own extension - We use the first sector
394 * of the partition to identify what type this
395 * partition is. We must not make this visible
398 if (size
> 1 && adfspart_check_ICSLinux(state
, start
)) {
405 put_partition(state
, slot
++, start
, size
);
408 put_dev_sector(sect
);
409 strlcat(state
->pp_buf
, "\n", PAGE_SIZE
);
414 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
424 static inline int valid_ptec_sector(const unsigned char *data
)
426 unsigned char checksum
= 0x2a;
430 * If it looks like a PC/BIOS partition, then it
431 * probably isn't PowerTec.
433 if (data
[510] == 0x55 && data
[511] == 0xaa)
436 for (i
= 0; i
< 511; i
++)
439 return checksum
== data
[511];
443 * Purpose: allocate ICS partitions.
444 * Params : hd - pointer to gendisk structure to store partition info.
445 * dev - device number to access.
446 * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok.
447 * Alloc : hda = whole drive
448 * hda1 = ADFS partition 0 on first drive.
449 * hda2 = ADFS partition 1 on first drive.
452 int adfspart_check_POWERTEC(struct parsed_partitions
*state
)
455 const unsigned char *data
;
456 const struct ptec_part
*p
;
460 data
= read_part_sector(state
, 0, §
);
464 if (!valid_ptec_sector(data
)) {
465 put_dev_sector(sect
);
469 strlcat(state
->pp_buf
, " [POWERTEC]", PAGE_SIZE
);
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
);
480 strlcat(state
->pp_buf
, "\n", PAGE_SIZE
);
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.
513 int adfspart_check_EESOX(struct parsed_partitions
*state
)
516 const unsigned char *data
;
517 unsigned char buffer
[256];
518 struct eesox_part
*p
;
522 data
= read_part_sector(state
, 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(state
->bdev
->bd_disk
);
550 put_partition(state
, slot
++, start
, size
- start
);
551 strlcat(state
->pp_buf
, "\n", PAGE_SIZE
);