0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define pr_fmt(fmt) fmt
0012
0013 #include <linux/types.h>
0014 #include <linux/affs_hardblocks.h>
0015
0016 #include "check.h"
0017
0018 static __inline__ u32
0019 checksum_block(__be32 *m, int size)
0020 {
0021 u32 sum = 0;
0022
0023 while (size--)
0024 sum += be32_to_cpu(*m++);
0025 return sum;
0026 }
0027
0028 int amiga_partition(struct parsed_partitions *state)
0029 {
0030 Sector sect;
0031 unsigned char *data;
0032 struct RigidDiskBlock *rdb;
0033 struct PartitionBlock *pb;
0034 int start_sect, nr_sects, blk, part, res = 0;
0035 int blksize = 1;
0036 int slot = 1;
0037
0038 for (blk = 0; ; blk++, put_dev_sector(sect)) {
0039 if (blk == RDB_ALLOCATION_LIMIT)
0040 goto rdb_done;
0041 data = read_part_sector(state, blk, §);
0042 if (!data) {
0043 pr_err("Dev %s: unable to read RDB block %d\n",
0044 state->disk->disk_name, blk);
0045 res = -1;
0046 goto rdb_done;
0047 }
0048 if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK))
0049 continue;
0050
0051 rdb = (struct RigidDiskBlock *)data;
0052 if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0)
0053 break;
0054
0055
0056
0057 *(__be32 *)(data+0xdc) = 0;
0058 if (checksum_block((__be32 *)data,
0059 be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) {
0060 pr_err("Trashed word at 0xd0 in block %d ignored in checksum calculation\n",
0061 blk);
0062 break;
0063 }
0064
0065 pr_err("Dev %s: RDB in block %d has bad checksum\n",
0066 state->disk->disk_name, blk);
0067 }
0068
0069
0070 blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512;
0071
0072 {
0073 char tmp[7 + 10 + 1 + 1];
0074
0075
0076 snprintf(tmp, sizeof(tmp), " RDSK (%d)", blksize * 512);
0077 strlcat(state->pp_buf, tmp, PAGE_SIZE);
0078 }
0079 blk = be32_to_cpu(rdb->rdb_PartitionList);
0080 put_dev_sector(sect);
0081 for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
0082 blk *= blksize;
0083 data = read_part_sector(state, blk, §);
0084 if (!data) {
0085 pr_err("Dev %s: unable to read partition block %d\n",
0086 state->disk->disk_name, blk);
0087 res = -1;
0088 goto rdb_done;
0089 }
0090 pb = (struct PartitionBlock *)data;
0091 blk = be32_to_cpu(pb->pb_Next);
0092 if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION))
0093 continue;
0094 if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 )
0095 continue;
0096
0097
0098
0099 nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
0100 be32_to_cpu(pb->pb_Environment[9])) *
0101 be32_to_cpu(pb->pb_Environment[3]) *
0102 be32_to_cpu(pb->pb_Environment[5]) *
0103 blksize;
0104 if (!nr_sects)
0105 continue;
0106 start_sect = be32_to_cpu(pb->pb_Environment[9]) *
0107 be32_to_cpu(pb->pb_Environment[3]) *
0108 be32_to_cpu(pb->pb_Environment[5]) *
0109 blksize;
0110 put_partition(state,slot++,start_sect,nr_sects);
0111 {
0112
0113 char dostype[4];
0114 char tmp[42];
0115
0116 __be32 *dt = (__be32 *)dostype;
0117 *dt = pb->pb_Environment[16];
0118 if (dostype[3] < ' ')
0119 snprintf(tmp, sizeof(tmp), " (%c%c%c^%c)",
0120 dostype[0], dostype[1],
0121 dostype[2], dostype[3] + '@' );
0122 else
0123 snprintf(tmp, sizeof(tmp), " (%c%c%c%c)",
0124 dostype[0], dostype[1],
0125 dostype[2], dostype[3]);
0126 strlcat(state->pp_buf, tmp, PAGE_SIZE);
0127 snprintf(tmp, sizeof(tmp), "(res %d spb %d)",
0128 be32_to_cpu(pb->pb_Environment[6]),
0129 be32_to_cpu(pb->pb_Environment[4]));
0130 strlcat(state->pp_buf, tmp, PAGE_SIZE);
0131 }
0132 res = 1;
0133 }
0134 strlcat(state->pp_buf, "\n", PAGE_SIZE);
0135
0136 rdb_done:
0137 return res;
0138 }