[NETFILTER]: xt_hashlimit: fix ip6tables dependency
[linux-2.6/mini2440.git] / fs / partitions / acorn.c
blob1bc9f372c7d4cbf94c676f128ef66db757afb386
1 /*
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
13 * method.
15 #include <linux/buffer_head.h>
16 #include <linux/adfs_fs.h>
18 #include "check.h"
19 #include "acorn.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))
36 return NULL;
38 dr = (struct adfs_discrecord *)(data + 0x1c0);
40 if (dr->disc_size == 0 && dr->disc_size_high == 0)
41 return NULL;
43 nr_sects = (le32_to_cpu(dr->disc_size_high) << 23) |
44 (le32_to_cpu(dr->disc_size) >> 9);
46 if (name)
47 printk(" [%s]", name);
48 put_partition(state, slot, first_sector, nr_sects);
49 return dr;
52 #ifdef CONFIG_ACORN_PARTITION_RISCIX
54 struct riscix_part {
55 __le32 start;
56 __le32 length;
57 __le32 one;
58 char name[16];
61 struct riscix_record {
62 __le32 magic;
63 #define RISCIX_MAGIC cpu_to_le32(0x4a657320)
64 __le32 date;
65 struct riscix_part part[8];
68 static int
69 riscix_partition(struct parsed_partitions *state, struct block_device *bdev,
70 unsigned long first_sect, int slot, unsigned long nr_sects)
72 Sector sect;
73 struct riscix_record *rr;
75 rr = (struct riscix_record *)read_dev_sector(bdev, first_sect, &sect);
76 if (!rr)
77 return -1;
79 printk(" [RISCiX]");
82 if (rr->magic == RISCIX_MAGIC) {
83 unsigned long size = nr_sects > 2 ? 2 : nr_sects;
84 int part;
86 printk(" <");
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);
99 printk(" >\n");
100 } else {
101 put_partition(state, slot++, first_sect, nr_sects);
104 put_dev_sector(sect);
105 return slot;
107 #endif
109 #define LINUX_NATIVE_MAGIC 0xdeafa1de
110 #define LINUX_SWAP_MAGIC 0xdeafab1e
112 struct linux_part {
113 __le32 magic;
114 __le32 start_sect;
115 __le32 nr_sects;
118 static int
119 linux_partition(struct parsed_partitions *state, struct block_device *bdev,
120 unsigned long first_sect, int slot, unsigned long nr_sects)
122 Sector sect;
123 struct linux_part *linuxp;
124 unsigned long size = nr_sects > 2 ? 2 : nr_sects;
126 printk(" [Linux]");
128 put_partition(state, slot++, first_sect, size);
130 linuxp = (struct linux_part *)read_dev_sector(bdev, first_sect, &sect);
131 if (!linuxp)
132 return -1;
134 printk(" <");
135 while (linuxp->magic == cpu_to_le32(LINUX_NATIVE_MAGIC) ||
136 linuxp->magic == cpu_to_le32(LINUX_SWAP_MAGIC)) {
137 if (slot == state->limit)
138 break;
139 put_partition(state, slot++, first_sect +
140 le32_to_cpu(linuxp->start_sect),
141 le32_to_cpu(linuxp->nr_sects));
142 linuxp ++;
144 printk(" >");
146 put_dev_sector(sect);
147 return slot;
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;
156 Sector sect;
157 unsigned char *data;
158 char *name = "CUMANA/ADFS";
159 int first = 1;
160 int slot = 1;
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
168 * it is.
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.
175 do {
176 struct adfs_discrecord *dr;
177 unsigned int nr_sects;
179 data = read_dev_sector(bdev, start_blk * 2 + 6, &sect);
180 if (!data)
181 return -1;
183 if (slot == state->limit)
184 break;
186 dr = adfs_partition(state, name, data, first_sector, slot++);
187 if (!dr)
188 break;
190 name = NULL;
192 nr_sects = (data[0x1fd] + (data[0x1fe] << 8)) *
193 (dr->heads + (dr->lowsector & 0x40 ? 1 : 0)) *
194 dr->secspertrack;
196 if (!nr_sects)
197 break;
199 first = 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? */
206 break;
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,
212 slot, nr_sects);
213 break;
214 #endif
216 case PARTITION_LINUX:
217 slot = linux_partition(state, bdev, first_sector,
218 slot, nr_sects);
219 break;
221 put_dev_sector(sect);
222 if (slot == -1)
223 return -1;
224 } while (1);
225 put_dev_sector(sect);
226 return first ? 0 : 1;
228 #endif
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;
247 Sector sect;
248 unsigned char *data;
249 struct adfs_discrecord *dr;
250 unsigned char id;
251 int slot = 1;
253 data = read_dev_sector(bdev, 6, &sect);
254 if (!data)
255 return -1;
257 dr = adfs_partition(state, "ADFS", data, 0, slot++);
258 if (!dr) {
259 put_dev_sector(sect);
260 return 0;
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);
277 #endif
280 * Work out start of non-adfs partition.
282 nr_sects = (bdev->bd_inode->i_size >> 9) - start_sect;
284 if (start_sect) {
285 switch (id) {
286 #ifdef CONFIG_ACORN_PARTITION_RISCIX
287 case PARTITION_RISCIX_SCSI:
288 case PARTITION_RISCIX_MFM:
289 slot = riscix_partition(state, bdev, start_sect,
290 slot, nr_sects);
291 break;
292 #endif
294 case PARTITION_LINUX:
295 slot = linux_partition(state, bdev, start_sect,
296 slot, nr_sects);
297 break;
300 printk("\n");
301 return 1;
303 #endif
305 #ifdef CONFIG_ACORN_PARTITION_ICS
307 struct ics_part {
308 __le32 start;
309 __le32 size;
312 static int adfspart_check_ICSLinux(struct block_device *bdev, unsigned long block)
314 Sector sect;
315 unsigned char *data = read_dev_sector(bdev, block, &sect);
316 int result = 0;
318 if (data) {
319 if (memcmp(data, "LinuxPart", 9) == 0)
320 result = 1;
321 put_dev_sector(sect);
324 return result;
328 * Check for a valid ICS partition using the checksum.
330 static inline int valid_ics_sector(const unsigned char *data)
332 unsigned long sum;
333 int i;
335 for (i = 0, sum = 0x50617274; i < 508; i++)
336 sum += data[i];
338 sum -= le32_to_cpu(*(__le32 *)(&data[508]));
340 return sum == 0;
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.
351 * ..etc..
354 adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev)
356 const unsigned char *data;
357 const struct ics_part *p;
358 int slot;
359 Sector sect;
362 * Try ICS style partitions - sector 0 contains partition info.
364 data = read_dev_sector(bdev, 0, &sect);
365 if (!data)
366 return -1;
368 if (!valid_ics_sector(data)) {
369 put_dev_sector(sect);
370 return 0;
373 printk(" [ICS]");
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)
380 break;
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.
387 if (size < 0) {
388 size = -size;
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
394 * to the filesystem.
396 if (size > 1 && adfspart_check_ICSLinux(bdev, start)) {
397 start += 1;
398 size -= 1;
402 if (size)
403 put_partition(state, slot++, start, size);
406 put_dev_sector(sect);
407 printk("\n");
408 return 1;
410 #endif
412 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
413 struct ptec_part {
414 __le32 unused1;
415 __le32 unused2;
416 __le32 start;
417 __le32 size;
418 __le32 unused5;
419 char type[8];
422 static inline int valid_ptec_sector(const unsigned char *data)
424 unsigned char checksum = 0x2a;
425 int i;
428 * If it looks like a PC/BIOS partition, then it
429 * probably isn't PowerTec.
431 if (data[510] == 0x55 && data[511] == 0xaa)
432 return 0;
434 for (i = 0; i < 511; i++)
435 checksum += data[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.
448 * ..etc..
451 adfspart_check_POWERTEC(struct parsed_partitions *state, struct block_device *bdev)
453 Sector sect;
454 const unsigned char *data;
455 const struct ptec_part *p;
456 int slot = 1;
457 int i;
459 data = read_dev_sector(bdev, 0, &sect);
460 if (!data)
461 return -1;
463 if (!valid_ptec_sector(data)) {
464 put_dev_sector(sect);
465 return 0;
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);
474 if (size)
475 put_partition(state, slot++, start, size);
478 put_dev_sector(sect);
479 printk("\n");
480 return 1;
482 #endif
484 #ifdef CONFIG_ACORN_PARTITION_EESOX
485 struct eesox_part {
486 char magic[6];
487 char name[10];
488 __le32 start;
489 __le32 unused6;
490 __le32 unused7;
491 __le32 unused8;
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)
515 Sector sect;
516 const unsigned char *data;
517 unsigned char buffer[256];
518 struct eesox_part *p;
519 sector_t start = 0;
520 int i, slot = 1;
522 data = read_dev_sector(bdev, 7, &sect);
523 if (!data)
524 return -1;
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++) {
535 sector_t next;
537 if (memcmp(p->magic, "Eesox", 6))
538 break;
540 next = le32_to_cpu(p->start);
541 if (i)
542 put_partition(state, slot++, start, next - start);
543 start = next;
546 if (i != 0) {
547 sector_t size;
549 size = get_capacity(bdev->bd_disk);
550 put_partition(state, slot++, start, size - start);
551 printk("\n");
554 return i ? 1 : 0;
556 #endif