1 // SPDX-License-Identifier: GPL-2.0
3 * fs/partitions/amiga.c
5 * Code extracted from drivers/block/genhd.c
7 * Copyright (C) 1991-1998 Linus Torvalds
8 * Re-organised Feb 1998 Russell King
11 #define pr_fmt(fmt) fmt
13 #include <linux/types.h>
14 #include <linux/affs_hardblocks.h>
20 checksum_block(__be32 *m, int size)
25 sum += be32_to_cpu(*m++);
29 int amiga_partition(struct parsed_partitions *state)
33 struct RigidDiskBlock *rdb;
34 struct PartitionBlock *pb;
35 int start_sect, nr_sects, blk, part, res = 0;
36 int blksize = 1; /* Multiplier for disk block size */
38 char b[BDEVNAME_SIZE];
40 for (blk = 0; ; blk++, put_dev_sector(sect)) {
41 if (blk == RDB_ALLOCATION_LIMIT)
43 data = read_part_sector(state, blk, §);
45 pr_err("Dev %s: unable to read RDB block %d\n",
46 bdevname(state->bdev, b), blk);
50 if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK))
53 rdb = (struct RigidDiskBlock *)data;
54 if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0)
56 /* Try again with 0xdc..0xdf zeroed, Windows might have
59 *(__be32 *)(data+0xdc) = 0;
60 if (checksum_block((__be32 *)data,
61 be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) {
62 pr_err("Trashed word at 0xd0 in block %d ignored in checksum calculation\n",
67 pr_err("Dev %s: RDB in block %d has bad checksum\n",
68 bdevname(state->bdev, b), blk);
71 /* blksize is blocks per 512 byte standard block */
72 blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512;
75 char tmp[7 + 10 + 1 + 1];
77 /* Be more informative */
78 snprintf(tmp, sizeof(tmp), " RDSK (%d)", blksize * 512);
79 strlcat(state->pp_buf, tmp, PAGE_SIZE);
81 blk = be32_to_cpu(rdb->rdb_PartitionList);
83 for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
84 blk *= blksize; /* Read in terms partition table understands */
85 data = read_part_sector(state, blk, §);
87 pr_err("Dev %s: unable to read partition block %d\n",
88 bdevname(state->bdev, b), blk);
92 pb = (struct PartitionBlock *)data;
93 blk = be32_to_cpu(pb->pb_Next);
94 if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION))
96 if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 )
99 /* Tell Kernel about it */
101 nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
102 be32_to_cpu(pb->pb_Environment[9])) *
103 be32_to_cpu(pb->pb_Environment[3]) *
104 be32_to_cpu(pb->pb_Environment[5]) *
108 start_sect = be32_to_cpu(pb->pb_Environment[9]) *
109 be32_to_cpu(pb->pb_Environment[3]) *
110 be32_to_cpu(pb->pb_Environment[5]) *
112 put_partition(state,slot++,start_sect,nr_sects);
114 /* Be even more informative to aid mounting */
118 __be32 *dt = (__be32 *)dostype;
119 *dt = pb->pb_Environment[16];
120 if (dostype[3] < ' ')
121 snprintf(tmp, sizeof(tmp), " (%c%c%c^%c)",
122 dostype[0], dostype[1],
123 dostype[2], dostype[3] + '@' );
125 snprintf(tmp, sizeof(tmp), " (%c%c%c%c)",
126 dostype[0], dostype[1],
127 dostype[2], dostype[3]);
128 strlcat(state->pp_buf, tmp, PAGE_SIZE);
129 snprintf(tmp, sizeof(tmp), "(res %d spb %d)",
130 be32_to_cpu(pb->pb_Environment[6]),
131 be32_to_cpu(pb->pb_Environment[4]));
132 strlcat(state->pp_buf, tmp, PAGE_SIZE);
136 strlcat(state->pp_buf, "\n", PAGE_SIZE);