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
10 #include <linux/types.h>
11 #include <linux/affs_hardblocks.h>
17 checksum_block(__be32 *m, int size)
22 sum += be32_to_cpu(*m++);
27 amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
31 struct RigidDiskBlock *rdb;
32 struct PartitionBlock *pb;
33 int start_sect, nr_sects, blk, part, res = 0;
34 int blksize = 1; /* Multiplier for disk block size */
36 char b[BDEVNAME_SIZE];
38 for (blk = 0; ; blk++, put_dev_sector(sect)) {
39 if (blk == RDB_ALLOCATION_LIMIT)
41 data = read_dev_sector(bdev, blk, §);
44 printk("Dev %s: unable to read RDB block %d\n",
45 bdevname(bdev, b), blk);
48 if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK))
51 rdb = (struct RigidDiskBlock *)data;
52 if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0)
54 /* Try again with 0xdc..0xdf zeroed, Windows might have
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);
65 printk("Dev %s: RDB in block %d has bad checksum\n",
66 bdevname(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);
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_dev_sector(bdev, blk, §);
80 printk("Dev %s: unable to read partition block %d\n",
81 bdevname(bdev, b), blk);
84 pb = (struct PartitionBlock *)data;
85 blk = be32_to_cpu(pb->pb_Next);
86 if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION))
88 if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 )
91 /* Tell Kernel about it */
93 nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
94 be32_to_cpu(pb->pb_Environment[9])) *
95 be32_to_cpu(pb->pb_Environment[3]) *
96 be32_to_cpu(pb->pb_Environment[5]) *
100 start_sect = be32_to_cpu(pb->pb_Environment[9]) *
101 be32_to_cpu(pb->pb_Environment[3]) *
102 be32_to_cpu(pb->pb_Environment[5]) *
104 put_partition(state,slot++,start_sect,nr_sects);
106 /* Be even more informative to aid mounting */
108 __be32 *dt = (__be32 *)dostype;
109 *dt = pb->pb_Environment[16];
110 if (dostype[3] < ' ')
111 printk(" (%c%c%c^%c)",
112 dostype[0], dostype[1],
113 dostype[2], dostype[3] + '@' );
115 printk(" (%c%c%c%c)",
116 dostype[0], dostype[1],
117 dostype[2], dostype[3]);
118 printk("(res %d spb %d)",
119 be32_to_cpu(pb->pb_Environment[6]),
120 be32_to_cpu(pb->pb_Environment[4]));