Commit | Line | Data |
---|---|---|
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 | |
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 | ||
1493bf21 | 28 | int 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; | |
1da177e4 LT |
37 | |
38 | for (blk = 0; ; blk++, put_dev_sector(sect)) { | |
39 | if (blk == RDB_ALLOCATION_LIMIT) | |
40 | goto rdb_done; | |
1493bf21 | 41 | data = read_part_sector(state, blk, §); |
1da177e4 | 42 | if (!data) { |
ffa9ed64 | 43 | pr_err("Dev %s: unable to read RDB block %d\n", |
a08aa9bc | 44 | state->disk->disk_name, blk); |
57881dd9 | 45 | res = -1; |
1da177e4 LT |
46 | goto rdb_done; |
47 | } | |
48 | if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK)) | |
49 | continue; | |
50 | ||
51 | rdb = (struct RigidDiskBlock *)data; | |
52 | if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0) | |
53 | break; | |
54 | /* Try again with 0xdc..0xdf zeroed, Windows might have | |
55 | * trashed it. | |
56 | */ | |
57 | *(__be32 *)(data+0xdc) = 0; | |
58 | if (checksum_block((__be32 *)data, | |
59 | be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) { | |
600ffc5e FF |
60 | pr_err("Trashed word at 0xd0 in block %d ignored in checksum calculation\n", |
61 | blk); | |
1da177e4 LT |
62 | break; |
63 | } | |
64 | ||
600ffc5e | 65 | pr_err("Dev %s: RDB in block %d has bad checksum\n", |
a08aa9bc | 66 | state->disk->disk_name, blk); |
1da177e4 LT |
67 | } |
68 | ||
69 | /* blksize is blocks per 512 byte standard block */ | |
70 | blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512; | |
71 | ||
9c867fbe AD |
72 | { |
73 | char tmp[7 + 10 + 1 + 1]; | |
74 | ||
75 | /* Be more informative */ | |
76 | snprintf(tmp, sizeof(tmp), " RDSK (%d)", blksize * 512); | |
77 | strlcat(state->pp_buf, tmp, PAGE_SIZE); | |
78 | } | |
1da177e4 LT |
79 | blk = be32_to_cpu(rdb->rdb_PartitionList); |
80 | put_dev_sector(sect); | |
81 | for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) { | |
82 | blk *= blksize; /* Read in terms partition table understands */ | |
1493bf21 | 83 | data = read_part_sector(state, blk, §); |
1da177e4 | 84 | if (!data) { |
ffa9ed64 | 85 | pr_err("Dev %s: unable to read partition block %d\n", |
a08aa9bc | 86 | state->disk->disk_name, blk); |
57881dd9 | 87 | res = -1; |
1da177e4 LT |
88 | goto rdb_done; |
89 | } | |
90 | pb = (struct PartitionBlock *)data; | |
91 | blk = be32_to_cpu(pb->pb_Next); | |
92 | if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION)) | |
93 | continue; | |
94 | if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 ) | |
95 | continue; | |
96 | ||
97 | /* Tell Kernel about it */ | |
98 | ||
99 | nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 - | |
100 | be32_to_cpu(pb->pb_Environment[9])) * | |
101 | be32_to_cpu(pb->pb_Environment[3]) * | |
102 | be32_to_cpu(pb->pb_Environment[5]) * | |
103 | blksize; | |
104 | if (!nr_sects) | |
105 | continue; | |
106 | start_sect = be32_to_cpu(pb->pb_Environment[9]) * | |
107 | be32_to_cpu(pb->pb_Environment[3]) * | |
108 | be32_to_cpu(pb->pb_Environment[5]) * | |
109 | blksize; | |
110 | put_partition(state,slot++,start_sect,nr_sects); | |
111 | { | |
112 | /* Be even more informative to aid mounting */ | |
113 | char dostype[4]; | |
9c867fbe AD |
114 | char tmp[42]; |
115 | ||
1da177e4 LT |
116 | __be32 *dt = (__be32 *)dostype; |
117 | *dt = pb->pb_Environment[16]; | |
118 | if (dostype[3] < ' ') | |
9c867fbe | 119 | snprintf(tmp, sizeof(tmp), " (%c%c%c^%c)", |
1da177e4 LT |
120 | dostype[0], dostype[1], |
121 | dostype[2], dostype[3] + '@' ); | |
122 | else | |
9c867fbe | 123 | snprintf(tmp, sizeof(tmp), " (%c%c%c%c)", |
1da177e4 LT |
124 | dostype[0], dostype[1], |
125 | dostype[2], dostype[3]); | |
9c867fbe AD |
126 | strlcat(state->pp_buf, tmp, PAGE_SIZE); |
127 | snprintf(tmp, sizeof(tmp), "(res %d spb %d)", | |
1da177e4 LT |
128 | be32_to_cpu(pb->pb_Environment[6]), |
129 | be32_to_cpu(pb->pb_Environment[4])); | |
9c867fbe | 130 | strlcat(state->pp_buf, tmp, PAGE_SIZE); |
1da177e4 LT |
131 | } |
132 | res = 1; | |
133 | } | |
9c867fbe | 134 | strlcat(state->pp_buf, "\n", PAGE_SIZE); |
1da177e4 LT |
135 | |
136 | rdb_done: | |
137 | return res; | |
138 | } |