]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - block/partitions/amiga.c
Merge tag 'linux-kselftest-kunit-fixes-5.8-rc4' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-jammy-kernel.git] / block / partitions / amiga.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * fs/partitions/amiga.c
4 *
5 * Code extracted from drivers/block/genhd.c
6 *
7 * Copyright (C) 1991-1998 Linus Torvalds
8 * Re-organised Feb 1998 Russell King
9 */
10
600ffc5e
FF
11#define pr_fmt(fmt) fmt
12
1da177e4
LT
13#include <linux/types.h>
14#include <linux/affs_hardblocks.h>
15
16#include "check.h"
1da177e4
LT
17
18static __inline__ u32
19checksum_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
1493bf21 28int amiga_partition(struct parsed_partitions *state)
1da177e4
LT
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;
1493bf21 42 data = read_part_sector(state, blk, &sect);
1da177e4 43 if (!data) {
ffa9ed64
CH
44 pr_err("Dev %s: unable to read RDB block %d\n",
45 bdevname(state->bdev, b), blk);
57881dd9 46 res = -1;
1da177e4
LT
47 goto rdb_done;
48 }
49 if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK))
50 continue;
51
52 rdb = (struct RigidDiskBlock *)data;
53 if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0)
54 break;
55 /* Try again with 0xdc..0xdf zeroed, Windows might have
56 * trashed it.
57 */
58 *(__be32 *)(data+0xdc) = 0;
59 if (checksum_block((__be32 *)data,
60 be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) {
600ffc5e
FF
61 pr_err("Trashed word at 0xd0 in block %d ignored in checksum calculation\n",
62 blk);
1da177e4
LT
63 break;
64 }
65
600ffc5e 66 pr_err("Dev %s: RDB in block %d has bad checksum\n",
1493bf21 67 bdevname(state->bdev, b), blk);
1da177e4
LT
68 }
69
70 /* blksize is blocks per 512 byte standard block */
71 blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512;
72
9c867fbe
AD
73 {
74 char tmp[7 + 10 + 1 + 1];
75
76 /* Be more informative */
77 snprintf(tmp, sizeof(tmp), " RDSK (%d)", blksize * 512);
78 strlcat(state->pp_buf, tmp, PAGE_SIZE);
79 }
1da177e4
LT
80 blk = be32_to_cpu(rdb->rdb_PartitionList);
81 put_dev_sector(sect);
82 for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
83 blk *= blksize; /* Read in terms partition table understands */
1493bf21 84 data = read_part_sector(state, blk, &sect);
1da177e4 85 if (!data) {
ffa9ed64
CH
86 pr_err("Dev %s: unable to read partition block %d\n",
87 bdevname(state->bdev, b), blk);
57881dd9 88 res = -1;
1da177e4
LT
89 goto rdb_done;
90 }
91 pb = (struct PartitionBlock *)data;
92 blk = be32_to_cpu(pb->pb_Next);
93 if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION))
94 continue;
95 if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 )
96 continue;
97
98 /* Tell Kernel about it */
99
100 nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
101 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 if (!nr_sects)
106 continue;
107 start_sect = be32_to_cpu(pb->pb_Environment[9]) *
108 be32_to_cpu(pb->pb_Environment[3]) *
109 be32_to_cpu(pb->pb_Environment[5]) *
110 blksize;
111 put_partition(state,slot++,start_sect,nr_sects);
112 {
113 /* Be even more informative to aid mounting */
114 char dostype[4];
9c867fbe
AD
115 char tmp[42];
116
1da177e4
LT
117 __be32 *dt = (__be32 *)dostype;
118 *dt = pb->pb_Environment[16];
119 if (dostype[3] < ' ')
9c867fbe 120 snprintf(tmp, sizeof(tmp), " (%c%c%c^%c)",
1da177e4
LT
121 dostype[0], dostype[1],
122 dostype[2], dostype[3] + '@' );
123 else
9c867fbe 124 snprintf(tmp, sizeof(tmp), " (%c%c%c%c)",
1da177e4
LT
125 dostype[0], dostype[1],
126 dostype[2], dostype[3]);
9c867fbe
AD
127 strlcat(state->pp_buf, tmp, PAGE_SIZE);
128 snprintf(tmp, sizeof(tmp), "(res %d spb %d)",
1da177e4
LT
129 be32_to_cpu(pb->pb_Environment[6]),
130 be32_to_cpu(pb->pb_Environment[4]));
9c867fbe 131 strlcat(state->pp_buf, tmp, PAGE_SIZE);
1da177e4
LT
132 }
133 res = 1;
134 }
9c867fbe 135 strlcat(state->pp_buf, "\n", PAGE_SIZE);
1da177e4
LT
136
137rdb_done:
138 return res;
139}