Linux 2.6.35-rc2
[linux/fpc-iii.git] / fs / partitions / amiga.c
blobba443d4229f8c968b59476c3ed454f5c541a4bd5
1 /*
2 * fs/partitions/amiga.c
4 * Code extracted from drivers/block/genhd.c
6 * Copyright (C) 1991-1998 Linus Torvalds
7 * Re-organised Feb 1998 Russell King
8 */
10 #include <linux/types.h>
11 #include <linux/affs_hardblocks.h>
13 #include "check.h"
14 #include "amiga.h"
16 static __inline__ u32
17 checksum_block(__be32 *m, int size)
19 u32 sum = 0;
21 while (size--)
22 sum += be32_to_cpu(*m++);
23 return sum;
26 int amiga_partition(struct parsed_partitions *state)
28 Sector sect;
29 unsigned char *data;
30 struct RigidDiskBlock *rdb;
31 struct PartitionBlock *pb;
32 int start_sect, nr_sects, blk, part, res = 0;
33 int blksize = 1; /* Multiplier for disk block size */
34 int slot = 1;
35 char b[BDEVNAME_SIZE];
37 for (blk = 0; ; blk++, put_dev_sector(sect)) {
38 if (blk == RDB_ALLOCATION_LIMIT)
39 goto rdb_done;
40 data = read_part_sector(state, blk, &sect);
41 if (!data) {
42 if (warn_no_part)
43 printk("Dev %s: unable to read RDB block %d\n",
44 bdevname(state->bdev, b), blk);
45 res = -1;
46 goto rdb_done;
48 if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK))
49 continue;
51 rdb = (struct RigidDiskBlock *)data;
52 if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0)
53 break;
54 /* Try again with 0xdc..0xdf zeroed, Windows might have
55 * trashed it.
57 *(__be32 *)(data+0xdc) = 0;
58 if (checksum_block((__be32 *)data,
59 be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) {
60 printk("Warning: Trashed word at 0xd0 in block %d "
61 "ignored in checksum calculation\n",blk);
62 break;
65 printk("Dev %s: RDB in block %d has bad checksum\n",
66 bdevname(state->bdev, b), blk);
69 /* blksize is blocks per 512 byte standard block */
70 blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512;
72 printk(" RDSK (%d)", blksize * 512); /* Be more informative */
73 blk = be32_to_cpu(rdb->rdb_PartitionList);
74 put_dev_sector(sect);
75 for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
76 blk *= blksize; /* Read in terms partition table understands */
77 data = read_part_sector(state, blk, &sect);
78 if (!data) {
79 if (warn_no_part)
80 printk("Dev %s: unable to read partition block %d\n",
81 bdevname(state->bdev, b), blk);
82 res = -1;
83 goto rdb_done;
85 pb = (struct PartitionBlock *)data;
86 blk = be32_to_cpu(pb->pb_Next);
87 if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION))
88 continue;
89 if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 )
90 continue;
92 /* Tell Kernel about it */
94 nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
95 be32_to_cpu(pb->pb_Environment[9])) *
96 be32_to_cpu(pb->pb_Environment[3]) *
97 be32_to_cpu(pb->pb_Environment[5]) *
98 blksize;
99 if (!nr_sects)
100 continue;
101 start_sect = be32_to_cpu(pb->pb_Environment[9]) *
102 be32_to_cpu(pb->pb_Environment[3]) *
103 be32_to_cpu(pb->pb_Environment[5]) *
104 blksize;
105 put_partition(state,slot++,start_sect,nr_sects);
107 /* Be even more informative to aid mounting */
108 char dostype[4];
109 __be32 *dt = (__be32 *)dostype;
110 *dt = pb->pb_Environment[16];
111 if (dostype[3] < ' ')
112 printk(" (%c%c%c^%c)",
113 dostype[0], dostype[1],
114 dostype[2], dostype[3] + '@' );
115 else
116 printk(" (%c%c%c%c)",
117 dostype[0], dostype[1],
118 dostype[2], dostype[3]);
119 printk("(res %d spb %d)",
120 be32_to_cpu(pb->pb_Environment[6]),
121 be32_to_cpu(pb->pb_Environment[4]));
123 res = 1;
125 printk("\n");
127 rdb_done:
128 return res;