Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/partitions/amiga.c |
| 3 | * |
| 4 | * Code extracted from drivers/block/genhd.c |
| 5 | * |
| 6 | * Copyright (C) 1991-1998 Linus Torvalds |
| 7 | * Re-organised Feb 1998 Russell King |
| 8 | */ |
| 9 | |
Fabian Frederick | 600ffc5 | 2014-06-12 20:04:52 +0200 | [diff] [blame] | 10 | #define pr_fmt(fmt) fmt |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | #include <linux/affs_hardblocks.h> |
| 14 | |
| 15 | #include "check.h" |
| 16 | #include "amiga.h" |
| 17 | |
| 18 | static __inline__ u32 |
| 19 | checksum_block(__be32 *m, int size) |
| 20 | { |
| 21 | u32 sum = 0; |
| 22 | |
| 23 | while (size--) |
| 24 | sum += be32_to_cpu(*m++); |
| 25 | return sum; |
| 26 | } |
| 27 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 28 | int amiga_partition(struct parsed_partitions *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
| 30 | Sector sect; |
| 31 | unsigned char *data; |
| 32 | struct RigidDiskBlock *rdb; |
| 33 | struct PartitionBlock *pb; |
| 34 | int start_sect, nr_sects, blk, part, res = 0; |
| 35 | int blksize = 1; /* Multiplier for disk block size */ |
| 36 | int slot = 1; |
| 37 | char b[BDEVNAME_SIZE]; |
| 38 | |
| 39 | for (blk = 0; ; blk++, put_dev_sector(sect)) { |
| 40 | if (blk == RDB_ALLOCATION_LIMIT) |
| 41 | goto rdb_done; |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 42 | data = read_part_sector(state, blk, §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | if (!data) { |
| 44 | if (warn_no_part) |
Fabian Frederick | 600ffc5 | 2014-06-12 20:04:52 +0200 | [diff] [blame] | 45 | pr_err("Dev %s: unable to read RDB block %d\n", |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 46 | bdevname(state->bdev, b), blk); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 47 | res = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | goto rdb_done; |
| 49 | } |
| 50 | if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK)) |
| 51 | continue; |
| 52 | |
| 53 | rdb = (struct RigidDiskBlock *)data; |
| 54 | if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0) |
| 55 | break; |
| 56 | /* Try again with 0xdc..0xdf zeroed, Windows might have |
| 57 | * trashed it. |
| 58 | */ |
| 59 | *(__be32 *)(data+0xdc) = 0; |
| 60 | if (checksum_block((__be32 *)data, |
| 61 | be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) { |
Fabian Frederick | 600ffc5 | 2014-06-12 20:04:52 +0200 | [diff] [blame] | 62 | pr_err("Trashed word at 0xd0 in block %d ignored in checksum calculation\n", |
| 63 | blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | break; |
| 65 | } |
| 66 | |
Fabian Frederick | 600ffc5 | 2014-06-12 20:04:52 +0200 | [diff] [blame] | 67 | pr_err("Dev %s: RDB in block %d has bad checksum\n", |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 68 | bdevname(state->bdev, b), blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /* blksize is blocks per 512 byte standard block */ |
| 72 | blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512; |
| 73 | |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 74 | { |
| 75 | char tmp[7 + 10 + 1 + 1]; |
| 76 | |
| 77 | /* Be more informative */ |
| 78 | snprintf(tmp, sizeof(tmp), " RDSK (%d)", blksize * 512); |
| 79 | strlcat(state->pp_buf, tmp, PAGE_SIZE); |
| 80 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | blk = be32_to_cpu(rdb->rdb_PartitionList); |
| 82 | put_dev_sector(sect); |
| 83 | for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) { |
| 84 | blk *= blksize; /* Read in terms partition table understands */ |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 85 | data = read_part_sector(state, blk, §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | if (!data) { |
| 87 | if (warn_no_part) |
Fabian Frederick | 600ffc5 | 2014-06-12 20:04:52 +0200 | [diff] [blame] | 88 | pr_err("Dev %s: unable to read partition block %d\n", |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 89 | bdevname(state->bdev, b), blk); |
Suzuki K P | 57881dd | 2006-12-06 20:35:16 -0800 | [diff] [blame] | 90 | res = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | goto rdb_done; |
| 92 | } |
| 93 | pb = (struct PartitionBlock *)data; |
| 94 | blk = be32_to_cpu(pb->pb_Next); |
| 95 | if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION)) |
| 96 | continue; |
| 97 | if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 ) |
| 98 | continue; |
| 99 | |
| 100 | /* Tell Kernel about it */ |
| 101 | |
| 102 | nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 - |
| 103 | be32_to_cpu(pb->pb_Environment[9])) * |
| 104 | be32_to_cpu(pb->pb_Environment[3]) * |
| 105 | be32_to_cpu(pb->pb_Environment[5]) * |
| 106 | blksize; |
| 107 | if (!nr_sects) |
| 108 | continue; |
| 109 | start_sect = be32_to_cpu(pb->pb_Environment[9]) * |
| 110 | be32_to_cpu(pb->pb_Environment[3]) * |
| 111 | be32_to_cpu(pb->pb_Environment[5]) * |
| 112 | blksize; |
| 113 | put_partition(state,slot++,start_sect,nr_sects); |
| 114 | { |
| 115 | /* Be even more informative to aid mounting */ |
| 116 | char dostype[4]; |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 117 | char tmp[42]; |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | __be32 *dt = (__be32 *)dostype; |
| 120 | *dt = pb->pb_Environment[16]; |
| 121 | if (dostype[3] < ' ') |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 122 | snprintf(tmp, sizeof(tmp), " (%c%c%c^%c)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | dostype[0], dostype[1], |
| 124 | dostype[2], dostype[3] + '@' ); |
| 125 | else |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 126 | snprintf(tmp, sizeof(tmp), " (%c%c%c%c)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | dostype[0], dostype[1], |
| 128 | dostype[2], dostype[3]); |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 129 | strlcat(state->pp_buf, tmp, PAGE_SIZE); |
| 130 | snprintf(tmp, sizeof(tmp), "(res %d spb %d)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | be32_to_cpu(pb->pb_Environment[6]), |
| 132 | be32_to_cpu(pb->pb_Environment[4])); |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 133 | strlcat(state->pp_buf, tmp, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | res = 1; |
| 136 | } |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 137 | strlcat(state->pp_buf, "\n", PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | rdb_done: |
| 140 | return res; |
| 141 | } |