| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "global.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
struct dostype { |
| 38 |
char *typecode; |
| 39 |
int isfs; |
| 40 |
|
| 41 |
char *name; |
| 42 |
}; |
| 43 |
|
| 44 |
struct dostype amiga_dostypes[] = { |
| 45 |
|
| 46 |
{ "DOS\x00", 1, "Amiga OFS file system (non-intl.)" }, |
| 47 |
{ "DOS\x01", 1, "Amiga FFS file system (non-intl.)" }, |
| 48 |
{ "DOS\x02", 1, "Amiga OFS file system (intl., no dir cache)" }, |
| 49 |
{ "DOS\x03", 1, "Amiga FFS file system (intl., no dir cache)" }, |
| 50 |
{ "DOS\x04", 1, "Amiga OFS file system (intl., dir cache)" }, |
| 51 |
{ "DOS\x05", 1, "Amiga FFS file system (intl., dir cache)" }, |
| 52 |
{ "DOS\x06", 1, "Amiga OFS file system (LNFS)" }, |
| 53 |
{ "DOS\x07", 1, "Amiga FFS file system (LNFS)" }, |
| 54 |
|
| 55 |
{ "muFS", 1, "Amiga muFS FFS file system (intl., no dir cache)" }, |
| 56 |
{ "muF\x00", 1, "Amiga muFS OFS file system (non-intl.)" }, |
| 57 |
{ "muF\x01", 1, "Amiga muFS FFS file system (non-intl.)" }, |
| 58 |
{ "muF\x02", 1, "Amiga muFS OFS file system (intl., no dir cache)" }, |
| 59 |
{ "muF\x03", 1, "Amiga muFS FFS file system (intl., no dir cache)" }, |
| 60 |
{ "muF\x04", 1, "Amiga muFS OFS file system (intl., dir cache)" }, |
| 61 |
{ "muF\x05", 1, "Amiga muFS FFS file system (intl., dir cache)" }, |
| 62 |
|
| 63 |
{ "SFS\x00", 1, "Amiga Smart File System" }, |
| 64 |
|
| 65 |
{ "PFS\x00", 1, "Amiga PFS file system 0" }, |
| 66 |
{ "PFS\x01", 1, "Amiga PFS file system 1" }, |
| 67 |
{ "PFS\x02", 1, "Amiga PFS file system 2" }, |
| 68 |
{ "PFS\x03", 1, "Amiga PFS file system 3" }, |
| 69 |
{ "PDS\x02", 1, "Amiga PFS file system 2, SCSIdirect" }, |
| 70 |
{ "PDS\x03", 1, "Amiga PFS file system 3, SCSIdirect" }, |
| 71 |
{ "muPF", 1, "Amiga PFS file system, multiuser" }, |
| 72 |
|
| 73 |
{ "AFS\x00", 1, "Amiga AFS file system" }, |
| 74 |
{ "AFS\x01", 1, "Amiga AFS file system (experimental)" }, |
| 75 |
|
| 76 |
{ "UNI\x00", 0, "Amiga Amix 0" }, |
| 77 |
{ "UNI\x01", 0, "Amiga Amix 1" }, |
| 78 |
|
| 79 |
{ "KICK", 1, "Amiga Kickstart disk" }, |
| 80 |
{ "BOOU", 1, "Amiga generic boot disk" }, |
| 81 |
{ "BAD\x00", 0, "Unreadable disk" }, |
| 82 |
{ "NDOS", 0, "Not a DOS disk" }, |
| 83 |
{ "resv", 0, "reserved" }, |
| 84 |
|
| 85 |
{ "CD00", 0, "CD-ROM High Sierra format" }, |
| 86 |
{ "CD01", 0, "CD-ROM ISO9660 format" }, |
| 87 |
{ "CDDA", 0, "CD Audio" }, |
| 88 |
{ "CDFS", 0, "CD-ROM - Amiga CDrive or AmiCDFS" }, |
| 89 |
{ "\x66\x2d\xab\xac", 0, "CD-ROM - AsimCDFS" }, |
| 90 |
|
| 91 |
{ "NBR\x07", 0, "NetBSD root" }, |
| 92 |
{ "NBS\x01", 0, "NetBSD swap" }, |
| 93 |
{ "NBU\x07", 0, "NetBSD other" }, |
| 94 |
|
| 95 |
{ "LNX\x00", 0, "Linux native" }, |
| 96 |
{ "EXT2", 0, "Linux ext2" }, |
| 97 |
{ "SWAP", 0, "Linux swap" }, |
| 98 |
{ "SWP\x00", 0, "Linux swap" }, |
| 99 |
{ "MNX\x00", 0, "Linux minix" }, |
| 100 |
|
| 101 |
{ "MAC\x00", 0, "Macintosh HFS" }, |
| 102 |
{ "MSD\x00", 0, "MS-DOS disk" }, |
| 103 |
{ "MSH\x00", 0, "MS-DOS PC-Task hardfile" }, |
| 104 |
{ "BFFS", 0, "Berkeley Fast Filesystem" }, |
| 105 |
|
| 106 |
{ NULL, 0, NULL }, |
| 107 |
}; |
| 108 |
|
| 109 |
static char * get_name_for_dostype(const unsigned char *dostype) |
| 110 |
{ |
| 111 |
int i; |
| 112 |
|
| 113 |
for (i = 0; amiga_dostypes[i].name; i++) |
| 114 |
if (memcmp(dostype, amiga_dostypes[i].typecode, 4) == 0) |
| 115 |
return amiga_dostypes[i].name; |
| 116 |
return "Unknown"; |
| 117 |
} |
| 118 |
|
| 119 |
static void format_dostype(char *buf, const unsigned char *dostype) |
| 120 |
{ |
| 121 |
int i; |
| 122 |
unsigned char c; |
| 123 |
char *p; |
| 124 |
|
| 125 |
p = buf; |
| 126 |
for (i = 0; i < 4; i++) { |
| 127 |
c = dostype[i]; |
| 128 |
if (c < 10) { |
| 129 |
*p++ = '\\'; |
| 130 |
*p++ = '0' + c; |
| 131 |
} else if (c < 32) { |
| 132 |
sprintf(p, "0x%02x", (int)c); |
| 133 |
p = strchr(p, 0); |
| 134 |
} else { |
| 135 |
*p++ = (char)c; |
| 136 |
} |
| 137 |
} |
| 138 |
*p = 0; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
void detect_amiga_partmap(SECTION *section, int level) |
| 146 |
{ |
| 147 |
int i, off, found; |
| 148 |
unsigned char *buf; |
| 149 |
char s[256], append[64]; |
| 150 |
u4 blocksize, part_ptr; |
| 151 |
u8 cylsize, start, size; |
| 152 |
|
| 153 |
for (off = 0, found = 0; off < 16; off++) { |
| 154 |
if (get_buffer(section, off * 512, 512, (void **)&buf) < 512) |
| 155 |
break; |
| 156 |
|
| 157 |
if (memcmp(buf, "RDSK", 4) == 0) { |
| 158 |
found = 1; |
| 159 |
break; |
| 160 |
} |
| 161 |
} |
| 162 |
if (!found) |
| 163 |
return; |
| 164 |
|
| 165 |
if (off == 0) |
| 166 |
print_line(level, "Amiga Rigid Disk partition map"); |
| 167 |
else |
| 168 |
print_line(level, "Amiga Rigid Disk partition map at sector %d", off); |
| 169 |
|
| 170 |
|
| 171 |
blocksize = get_be_long(buf + 16); |
| 172 |
if (blocksize < 256 || (blocksize & (blocksize-1))) { |
| 173 |
print_line(level+1, "Illegal block size %lu", blocksize); |
| 174 |
return; |
| 175 |
} else if (blocksize != 512) { |
| 176 |
print_line(level+1, "Unusual block size %lu, not sure this will work...", blocksize); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
part_ptr = get_be_long(buf + 28); |
| 182 |
for (i = 1; part_ptr != 0xffffffffUL; i++) { |
| 183 |
if (get_buffer(section, (u8)part_ptr * 512, 256, |
| 184 |
(void **)&buf) < 256) { |
| 185 |
print_line(level, "Partition %d: Can't read partition info block"); |
| 186 |
break; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
if (memcmp(buf, "PART", 4) != 0) { |
| 191 |
print_line(level, "Partition %d: Invalid signature"); |
| 192 |
break; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
part_ptr = get_be_long(buf + 16); |
| 197 |
|
| 198 |
|
| 199 |
cylsize = (u8)get_be_long(buf + 140) * (u8)get_be_long(buf + 148); |
| 200 |
start = get_be_long(buf + 164) * cylsize; |
| 201 |
size = (get_be_long(buf + 168) + 1 - get_be_long(buf + 164)) * cylsize; |
| 202 |
|
| 203 |
snprintf(append, 63, " from %llu", start); |
| 204 |
format_blocky_size(s, size, 512, "sectors", append); |
| 205 |
print_line(level, "Partition %d: %s", |
| 206 |
i, s); |
| 207 |
|
| 208 |
|
| 209 |
get_pstring(buf + 36, s); |
| 210 |
if (s[0]) |
| 211 |
print_line(level + 1, "Drive name \"%s\"", s); |
| 212 |
|
| 213 |
|
| 214 |
format_dostype(s, buf + 192); |
| 215 |
print_line(level + 1, "Type \"%s\" (%s)", s, |
| 216 |
get_name_for_dostype(buf + 192)); |
| 217 |
|
| 218 |
|
| 219 |
if (size > 0 && start > 0) { |
| 220 |
analyze_recursive(section, level + 1, |
| 221 |
start * 512, size * 512, 0); |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
void detect_amiga_fs(SECTION *section, int level) |
| 231 |
{ |
| 232 |
unsigned char *buf; |
| 233 |
int i, isfs; |
| 234 |
char s[256], *typename; |
| 235 |
|
| 236 |
if (get_buffer(section, 0, 512, (void **)&buf) < 512) |
| 237 |
return; |
| 238 |
|
| 239 |
|
| 240 |
isfs = 0; |
| 241 |
typename = NULL; |
| 242 |
for (i = 0; amiga_dostypes[i].name; i++) |
| 243 |
if (memcmp(buf, amiga_dostypes[i].typecode, 4) == 0) { |
| 244 |
isfs = amiga_dostypes[i].isfs; |
| 245 |
typename = amiga_dostypes[i].name; |
| 246 |
break; |
| 247 |
} |
| 248 |
if (typename == NULL) |
| 249 |
return; |
| 250 |
|
| 251 |
if (isfs) { |
| 252 |
|
| 253 |
print_line(level, "%s", typename); |
| 254 |
|
| 255 |
format_dostype(s, buf); |
| 256 |
print_line(level + 1, "Type \"%s\"", s); |
| 257 |
|
| 258 |
if (section->size == 512*11*2*80) { |
| 259 |
print_line(level+1, "Size matches DD floppy"); |
| 260 |
} else if (section->size == 512*22*2*80) { |
| 261 |
print_line(level+1, "Size matches HD floppy"); |
| 262 |
} |
| 263 |
|
| 264 |
} else { |
| 265 |
|
| 266 |
format_dostype(s, buf); |
| 267 |
print_line(level, "Amiga type code \"%s\" (%s)", s, typename); |
| 268 |
|
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
|