Blame view
block/partitions/acorn.c
12.3 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * linux/fs/partitions/acorn.c * * Copyright (c) 1996-2000 Russell King. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Scan ADFS partitions on hard disk drives. Unfortunately, there * isn't a standard for partitioning drives on Acorn machines, so * every single manufacturer of SCSI and IDE cards created their own * method. */ |
1da177e4c Linux-2.6.12-rc2 |
15 16 17 18 19 20 21 22 23 24 25 26 |
#include <linux/buffer_head.h> #include <linux/adfs_fs.h> #include "check.h" #include "acorn.h" /* * Partition types. (Oh for reusability) */ #define PARTITION_RISCIX_MFM 1 #define PARTITION_RISCIX_SCSI 2 #define PARTITION_LINUX 9 |
d05e96fe4 fix compiler warn... |
27 28 |
#if defined(CONFIG_ACORN_PARTITION_CUMANA) || \ defined(CONFIG_ACORN_PARTITION_ADFS) |
1da177e4c Linux-2.6.12-rc2 |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
static struct adfs_discrecord * adfs_partition(struct parsed_partitions *state, char *name, char *data, unsigned long first_sector, int slot) { struct adfs_discrecord *dr; unsigned int nr_sects; if (adfs_checkbblk(data)) return NULL; dr = (struct adfs_discrecord *)(data + 0x1c0); if (dr->disc_size == 0 && dr->disc_size_high == 0) return NULL; nr_sects = (le32_to_cpu(dr->disc_size_high) << 23) | (le32_to_cpu(dr->disc_size) >> 9); |
9c867fbe0 partitions: fix s... |
46 47 48 49 50 |
if (name) { strlcat(state->pp_buf, " [", PAGE_SIZE); strlcat(state->pp_buf, name, PAGE_SIZE); strlcat(state->pp_buf, "]", PAGE_SIZE); } |
1da177e4c Linux-2.6.12-rc2 |
51 52 53 |
put_partition(state, slot, first_sector, nr_sects); return dr; } |
d05e96fe4 fix compiler warn... |
54 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#ifdef CONFIG_ACORN_PARTITION_RISCIX struct riscix_part { __le32 start; __le32 length; __le32 one; char name[16]; }; struct riscix_record { __le32 magic; #define RISCIX_MAGIC cpu_to_le32(0x4a657320) __le32 date; struct riscix_part part[8]; }; |
d05e96fe4 fix compiler warn... |
71 72 |
#if defined(CONFIG_ACORN_PARTITION_CUMANA) || \ defined(CONFIG_ACORN_PARTITION_ADFS) |
1493bf217 block: use struct... |
73 74 75 |
static int riscix_partition(struct parsed_partitions *state, unsigned long first_sect, int slot, unsigned long nr_sects) |
1da177e4c Linux-2.6.12-rc2 |
76 77 78 79 |
{ Sector sect; struct riscix_record *rr; |
1493bf217 block: use struct... |
80 |
rr = read_part_sector(state, first_sect, §); |
1da177e4c Linux-2.6.12-rc2 |
81 82 |
if (!rr) return -1; |
9c867fbe0 partitions: fix s... |
83 |
strlcat(state->pp_buf, " [RISCiX]", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
84 85 86 87 88 |
if (rr->magic == RISCIX_MAGIC) { unsigned long size = nr_sects > 2 ? 2 : nr_sects; int part; |
9c867fbe0 partitions: fix s... |
89 |
strlcat(state->pp_buf, " <", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
90 91 92 93 94 95 96 97 |
put_partition(state, slot++, first_sect, size); for (part = 0; part < 8; part++) { if (rr->part[part].one && memcmp(rr->part[part].name, "All\0", 4)) { put_partition(state, slot++, le32_to_cpu(rr->part[part].start), le32_to_cpu(rr->part[part].length)); |
9c867fbe0 partitions: fix s... |
98 99 100 |
strlcat(state->pp_buf, "(", PAGE_SIZE); strlcat(state->pp_buf, rr->part[part].name, PAGE_SIZE); strlcat(state->pp_buf, ")", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
101 102 |
} } |
9c867fbe0 partitions: fix s... |
103 104 |
strlcat(state->pp_buf, " > ", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
105 106 107 108 109 110 111 112 |
} else { put_partition(state, slot++, first_sect, nr_sects); } put_dev_sector(sect); return slot; } #endif |
d05e96fe4 fix compiler warn... |
113 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
114 115 116 117 118 119 120 121 122 |
#define LINUX_NATIVE_MAGIC 0xdeafa1de #define LINUX_SWAP_MAGIC 0xdeafab1e struct linux_part { __le32 magic; __le32 start_sect; __le32 nr_sects; }; |
d05e96fe4 fix compiler warn... |
123 124 |
#if defined(CONFIG_ACORN_PARTITION_CUMANA) || \ defined(CONFIG_ACORN_PARTITION_ADFS) |
1493bf217 block: use struct... |
125 126 127 |
static int linux_partition(struct parsed_partitions *state, unsigned long first_sect, int slot, unsigned long nr_sects) |
1da177e4c Linux-2.6.12-rc2 |
128 129 130 131 |
{ Sector sect; struct linux_part *linuxp; unsigned long size = nr_sects > 2 ? 2 : nr_sects; |
9c867fbe0 partitions: fix s... |
132 |
strlcat(state->pp_buf, " [Linux]", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
133 134 |
put_partition(state, slot++, first_sect, size); |
1493bf217 block: use struct... |
135 |
linuxp = read_part_sector(state, first_sect, §); |
1da177e4c Linux-2.6.12-rc2 |
136 137 |
if (!linuxp) return -1; |
9c867fbe0 partitions: fix s... |
138 |
strlcat(state->pp_buf, " <", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
139 140 141 142 143 144 145 146 147 |
while (linuxp->magic == cpu_to_le32(LINUX_NATIVE_MAGIC) || linuxp->magic == cpu_to_le32(LINUX_SWAP_MAGIC)) { if (slot == state->limit) break; put_partition(state, slot++, first_sect + le32_to_cpu(linuxp->start_sect), le32_to_cpu(linuxp->nr_sects)); linuxp ++; } |
9c867fbe0 partitions: fix s... |
148 |
strlcat(state->pp_buf, " >", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
149 150 151 152 |
put_dev_sector(sect); return slot; } |
d05e96fe4 fix compiler warn... |
153 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
154 155 |
#ifdef CONFIG_ACORN_PARTITION_CUMANA |
1493bf217 block: use struct... |
156 |
int adfspart_check_CUMANA(struct parsed_partitions *state) |
1da177e4c Linux-2.6.12-rc2 |
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
{ unsigned long first_sector = 0; unsigned int start_blk = 0; Sector sect; unsigned char *data; char *name = "CUMANA/ADFS"; int first = 1; int slot = 1; /* * Try Cumana style partitions - sector 6 contains ADFS boot block * with pointer to next 'drive'. * * There are unknowns in this code - is the 'cylinder number' of the * next partition relative to the start of this one - I'm assuming * it is. * * Also, which ID did Cumana use? * * This is totally unfinished, and will require more work to get it * going. Hence it is totally untested. */ do { struct adfs_discrecord *dr; unsigned int nr_sects; |
1493bf217 block: use struct... |
182 |
data = read_part_sector(state, start_blk * 2 + 6, §); |
1da177e4c Linux-2.6.12-rc2 |
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
if (!data) return -1; if (slot == state->limit) break; dr = adfs_partition(state, name, data, first_sector, slot++); if (!dr) break; name = NULL; nr_sects = (data[0x1fd] + (data[0x1fe] << 8)) * (dr->heads + (dr->lowsector & 0x40 ? 1 : 0)) * dr->secspertrack; if (!nr_sects) break; first = 0; first_sector += nr_sects; start_blk += nr_sects >> (BLOCK_SIZE_BITS - 9); nr_sects = 0; /* hmm - should be partition size */ switch (data[0x1fc] & 15) { case 0: /* No partition / ADFS? */ break; #ifdef CONFIG_ACORN_PARTITION_RISCIX case PARTITION_RISCIX_SCSI: /* RISCiX - we don't know how to find the next one. */ |
1493bf217 block: use struct... |
214 215 |
slot = riscix_partition(state, first_sector, slot, nr_sects); |
1da177e4c Linux-2.6.12-rc2 |
216 217 218 219 |
break; #endif case PARTITION_LINUX: |
1493bf217 block: use struct... |
220 221 |
slot = linux_partition(state, first_sector, slot, nr_sects); |
1da177e4c Linux-2.6.12-rc2 |
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
break; } put_dev_sector(sect); if (slot == -1) return -1; } while (1); put_dev_sector(sect); return first ? 0 : 1; } #endif #ifdef CONFIG_ACORN_PARTITION_ADFS /* * Purpose: allocate ADFS partitions. * * Params : hd - pointer to gendisk structure to store partition info. * dev - device number to access. * * Returns: -1 on error, 0 for no ADFS boot sector, 1 for ok. * * Alloc : hda = whole drive * hda1 = ADFS partition on first drive. * hda2 = non-ADFS partition. */ |
1493bf217 block: use struct... |
246 |
int adfspart_check_ADFS(struct parsed_partitions *state) |
1da177e4c Linux-2.6.12-rc2 |
247 248 249 250 251 252 253 |
{ unsigned long start_sect, nr_sects, sectscyl, heads; Sector sect; unsigned char *data; struct adfs_discrecord *dr; unsigned char id; int slot = 1; |
1493bf217 block: use struct... |
254 |
data = read_part_sector(state, 6, §); |
1da177e4c Linux-2.6.12-rc2 |
255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
if (!data) return -1; dr = adfs_partition(state, "ADFS", data, 0, slot++); if (!dr) { put_dev_sector(sect); return 0; } heads = dr->heads + ((dr->lowsector >> 6) & 1); sectscyl = dr->secspertrack * heads; start_sect = ((data[0x1fe] << 8) + data[0x1fd]) * sectscyl; id = data[0x1fc] & 15; put_dev_sector(sect); |
1da177e4c Linux-2.6.12-rc2 |
269 270 271 |
/* * Work out start of non-adfs partition. */ |
1493bf217 block: use struct... |
272 |
nr_sects = (state->bdev->bd_inode->i_size >> 9) - start_sect; |
1da177e4c Linux-2.6.12-rc2 |
273 274 275 276 277 278 |
if (start_sect) { switch (id) { #ifdef CONFIG_ACORN_PARTITION_RISCIX case PARTITION_RISCIX_SCSI: case PARTITION_RISCIX_MFM: |
1493bf217 block: use struct... |
279 280 |
slot = riscix_partition(state, start_sect, slot, nr_sects); |
1da177e4c Linux-2.6.12-rc2 |
281 282 283 284 |
break; #endif case PARTITION_LINUX: |
1493bf217 block: use struct... |
285 286 |
slot = linux_partition(state, start_sect, slot, nr_sects); |
1da177e4c Linux-2.6.12-rc2 |
287 288 289 |
break; } } |
9c867fbe0 partitions: fix s... |
290 291 |
strlcat(state->pp_buf, " ", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
292 293 294 295 296 297 298 299 300 301 |
return 1; } #endif #ifdef CONFIG_ACORN_PARTITION_ICS struct ics_part { __le32 start; __le32 size; }; |
1493bf217 block: use struct... |
302 303 |
static int adfspart_check_ICSLinux(struct parsed_partitions *state, unsigned long block) |
1da177e4c Linux-2.6.12-rc2 |
304 305 |
{ Sector sect; |
1493bf217 block: use struct... |
306 |
unsigned char *data = read_part_sector(state, block, §); |
1da177e4c Linux-2.6.12-rc2 |
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
int result = 0; if (data) { if (memcmp(data, "LinuxPart", 9) == 0) result = 1; put_dev_sector(sect); } return result; } /* * Check for a valid ICS partition using the checksum. */ static inline int valid_ics_sector(const unsigned char *data) { unsigned long sum; int i; for (i = 0, sum = 0x50617274; i < 508; i++) sum += data[i]; sum -= le32_to_cpu(*(__le32 *)(&data[508])); return sum == 0; } /* * Purpose: allocate ICS partitions. * Params : hd - pointer to gendisk structure to store partition info. * dev - device number to access. * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok. * Alloc : hda = whole drive * hda1 = ADFS partition 0 on first drive. * hda2 = ADFS partition 1 on first drive. * ..etc.. */ |
1493bf217 block: use struct... |
344 |
int adfspart_check_ICS(struct parsed_partitions *state) |
1da177e4c Linux-2.6.12-rc2 |
345 346 347 348 349 350 351 352 353 |
{ const unsigned char *data; const struct ics_part *p; int slot; Sector sect; /* * Try ICS style partitions - sector 0 contains partition info. */ |
1493bf217 block: use struct... |
354 |
data = read_part_sector(state, 0, §); |
1da177e4c Linux-2.6.12-rc2 |
355 356 357 358 359 360 361 |
if (!data) return -1; if (!valid_ics_sector(data)) { put_dev_sector(sect); return 0; } |
9c867fbe0 partitions: fix s... |
362 |
strlcat(state->pp_buf, " [ICS]", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
for (slot = 1, p = (const struct ics_part *)data; p->size; p++) { u32 start = le32_to_cpu(p->start); s32 size = le32_to_cpu(p->size); /* yes, it's signed. */ if (slot == state->limit) break; /* * Negative sizes tell the RISC OS ICS driver to ignore * this partition - in effect it says that this does not * contain an ADFS filesystem. */ if (size < 0) { size = -size; /* * Our own extension - We use the first sector * of the partition to identify what type this * partition is. We must not make this visible * to the filesystem. */ |
1493bf217 block: use struct... |
385 |
if (size > 1 && adfspart_check_ICSLinux(state, start)) { |
1da177e4c Linux-2.6.12-rc2 |
386 387 388 389 390 391 392 393 394 395 |
start += 1; size -= 1; } } if (size) put_partition(state, slot++, start, size); } put_dev_sector(sect); |
9c867fbe0 partitions: fix s... |
396 397 |
strlcat(state->pp_buf, " ", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
return 1; } #endif #ifdef CONFIG_ACORN_PARTITION_POWERTEC struct ptec_part { __le32 unused1; __le32 unused2; __le32 start; __le32 size; __le32 unused5; char type[8]; }; static inline int valid_ptec_sector(const unsigned char *data) { unsigned char checksum = 0x2a; int i; /* * If it looks like a PC/BIOS partition, then it * probably isn't PowerTec. */ if (data[510] == 0x55 && data[511] == 0xaa) return 0; for (i = 0; i < 511; i++) checksum += data[i]; return checksum == data[511]; } /* * Purpose: allocate ICS partitions. * Params : hd - pointer to gendisk structure to store partition info. * dev - device number to access. * Returns: -1 on error, 0 for no ICS table, 1 for partitions ok. * Alloc : hda = whole drive * hda1 = ADFS partition 0 on first drive. * hda2 = ADFS partition 1 on first drive. * ..etc.. */ |
1493bf217 block: use struct... |
440 |
int adfspart_check_POWERTEC(struct parsed_partitions *state) |
1da177e4c Linux-2.6.12-rc2 |
441 442 443 444 445 446 |
{ Sector sect; const unsigned char *data; const struct ptec_part *p; int slot = 1; int i; |
1493bf217 block: use struct... |
447 |
data = read_part_sector(state, 0, §); |
1da177e4c Linux-2.6.12-rc2 |
448 449 450 451 452 453 454 |
if (!data) return -1; if (!valid_ptec_sector(data)) { put_dev_sector(sect); return 0; } |
9c867fbe0 partitions: fix s... |
455 |
strlcat(state->pp_buf, " [POWERTEC]", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
456 457 458 459 460 461 462 463 464 465 |
for (i = 0, p = (const struct ptec_part *)data; i < 12; i++, p++) { u32 start = le32_to_cpu(p->start); u32 size = le32_to_cpu(p->size); if (size) put_partition(state, slot++, start, size); } put_dev_sector(sect); |
9c867fbe0 partitions: fix s... |
466 467 |
strlcat(state->pp_buf, " ", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
return 1; } #endif #ifdef CONFIG_ACORN_PARTITION_EESOX struct eesox_part { char magic[6]; char name[10]; __le32 start; __le32 unused6; __le32 unused7; __le32 unused8; }; /* * Guess who created this format? */ static const char eesox_name[] = { 'N', 'e', 'i', 'l', ' ', 'C', 'r', 'i', 't', 'c', 'h', 'e', 'l', 'l', ' ', ' ' }; /* * EESOX SCSI partition format. * * This is a goddamned awful partition format. We don't seem to store * the size of the partition in this table, only the start addresses. * * There are two possibilities where the size comes from: * 1. The individual ADFS boot block entries that are placed on the disk. * 2. The start address of the next entry. */ |
1493bf217 block: use struct... |
500 |
int adfspart_check_EESOX(struct parsed_partitions *state) |
1da177e4c Linux-2.6.12-rc2 |
501 502 503 504 505 506 507 |
{ Sector sect; const unsigned char *data; unsigned char buffer[256]; struct eesox_part *p; sector_t start = 0; int i, slot = 1; |
1493bf217 block: use struct... |
508 |
data = read_part_sector(state, 7, §); |
1da177e4c Linux-2.6.12-rc2 |
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
if (!data) return -1; /* * "Decrypt" the partition table. God knows why... */ for (i = 0; i < 256; i++) buffer[i] = data[i] ^ eesox_name[i & 15]; put_dev_sector(sect); for (i = 0, p = (struct eesox_part *)buffer; i < 8; i++, p++) { sector_t next; if (memcmp(p->magic, "Eesox", 6)) break; next = le32_to_cpu(p->start); if (i) put_partition(state, slot++, start, next - start); start = next; } if (i != 0) { sector_t size; |
1493bf217 block: use struct... |
534 |
size = get_capacity(state->bdev->bd_disk); |
1da177e4c Linux-2.6.12-rc2 |
535 |
put_partition(state, slot++, start, size - start); |
9c867fbe0 partitions: fix s... |
536 537 |
strlcat(state->pp_buf, " ", PAGE_SIZE); |
1da177e4c Linux-2.6.12-rc2 |
538 539 540 541 542 |
} return i ? 1 : 0; } #endif |