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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/*
* amiga.c
* Detection of Amiga partition maps and file systems
*
* Copyright (c) 2003 Christoph Pfisterer
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "global.h"
/*
* Amiga partition type codes
*
* Based on the dostypes list of the Ambient file manager
* as of Apr 02, 2005.
*/
struct dostype {
char *typecode;
int isfs; /* true = native Amiga filesystem (affects printout when */
/* found at the start of the boot sector) */
char *name;
};
struct dostype amiga_dostypes[] = {
{ "DOS\x00", 1, "Amiga OFS file system (non-intl.)" },
{ "DOS\x01", 1, "Amiga FFS file system (non-intl.)" },
{ "DOS\x02", 1, "Amiga OFS file system (intl., no dir cache)" },
{ "DOS\x03", 1, "Amiga FFS file system (intl., no dir cache)" },
{ "DOS\x04", 1, "Amiga OFS file system (intl., dir cache)" },
{ "DOS\x05", 1, "Amiga FFS file system (intl., dir cache)" },
{ "DOS\x06", 1, "Amiga OFS file system (LNFS)" },
{ "DOS\x07", 1, "Amiga FFS file system (LNFS)" },
{ "muFS", 1, "Amiga muFS FFS file system (intl., no dir cache)" },
{ "muF\x00", 1, "Amiga muFS OFS file system (non-intl.)" },
{ "muF\x01", 1, "Amiga muFS FFS file system (non-intl.)" },
{ "muF\x02", 1, "Amiga muFS OFS file system (intl., no dir cache)" },
{ "muF\x03", 1, "Amiga muFS FFS file system (intl., no dir cache)" },
{ "muF\x04", 1, "Amiga muFS OFS file system (intl., dir cache)" },
{ "muF\x05", 1, "Amiga muFS FFS file system (intl., dir cache)" },
{ "SFS\x00", 1, "Amiga Smart File System" },
{ "PFS\x00", 1, "Amiga PFS file system 0" },
{ "PFS\x01", 1, "Amiga PFS file system 1" },
{ "PFS\x02", 1, "Amiga PFS file system 2" },
{ "PFS\x03", 1, "Amiga PFS file system 3" },
{ "PDS\x02", 1, "Amiga PFS file system 2, SCSIdirect" },
{ "PDS\x03", 1, "Amiga PFS file system 3, SCSIdirect" },
{ "muPF", 1, "Amiga PFS file system, multiuser" },
{ "AFS\x00", 1, "Amiga AFS file system" },
{ "AFS\x01", 1, "Amiga AFS file system (experimental)" },
{ "UNI\x00", 0, "Amiga Amix 0" },
{ "UNI\x01", 0, "Amiga Amix 1" },
{ "KICK", 1, "Amiga Kickstart disk" },
{ "BOOU", 1, "Amiga generic boot disk" },
{ "BAD\x00", 0, "Unreadable disk" },
{ "NDOS", 0, "Not a DOS disk" },
{ "resv", 0, "reserved" },
{ "CD00", 0, "CD-ROM High Sierra format" },
{ "CD01", 0, "CD-ROM ISO9660 format" },
{ "CDDA", 0, "CD Audio" },
{ "CDFS", 0, "CD-ROM - Amiga CDrive or AmiCDFS" },
{ "\x66\x2d\xab\xac", 0, "CD-ROM - AsimCDFS" },
{ "NBR\x07", 0, "NetBSD root" },
{ "NBS\x01", 0, "NetBSD swap" },
{ "NBU\x07", 0, "NetBSD other" },
{ "LNX\x00", 0, "Linux native" },
{ "EXT2", 0, "Linux ext2" },
{ "SWAP", 0, "Linux swap" },
{ "SWP\x00", 0, "Linux swap" },
{ "MNX\x00", 0, "Linux minix" },
{ "MAC\x00", 0, "Macintosh HFS" },
{ "MSD\x00", 0, "MS-DOS disk" },
{ "MSH\x00", 0, "MS-DOS PC-Task hardfile" },
{ "BFFS", 0, "Berkeley Fast Filesystem" },
{ NULL, 0, NULL },
};
static char * get_name_for_dostype(const unsigned char *dostype)
{
int i;
for (i = 0; amiga_dostypes[i].name; i++)
if (memcmp(dostype, amiga_dostypes[i].typecode, 4) == 0)
return amiga_dostypes[i].name;
return "Unknown";
}
static void format_dostype(char *buf, const unsigned char *dostype)
{
int i;
unsigned char c;
char *p;
p = buf;
for (i = 0; i < 4; i++) {
c = dostype[i];
if (c < 10) {
*p++ = '\\';
*p++ = '0' + c;
} else if (c < 32) {
sprintf(p, "0x%02x", (int)c);
p = strchr(p, 0);
} else {
*p++ = (char)c;
}
}
*p = 0;
}
/*
* Amiga "Rigid Disk" partition map
*/
void detect_amiga_partmap(SECTION *section, int level)
{
int i, off, found;
unsigned char *buf;
char s[256], append[64];
u4 blocksize, part_ptr;
u8 cylsize, start, size;
for (off = 0, found = 0; off < 16; off++) {
if (get_buffer(section, off * 512, 512, (void **)&buf) < 512)
break;
if (memcmp(buf, "RDSK", 4) == 0) {
found = 1;
break;
}
}
if (!found)
return;
if (off == 0)
print_line(level, "Amiga Rigid Disk partition map");
else
print_line(level, "Amiga Rigid Disk partition map at sector %d", off);
/* get device block size (?) */
blocksize = get_be_long(buf + 16);
if (blocksize < 256 || (blocksize & (blocksize-1))) {
print_line(level+1, "Illegal block size %lu", blocksize);
return;
} else if (blocksize != 512) {
print_line(level+1, "Unusual block size %lu, not sure this will work...", blocksize);
}
/* TODO: get geometry data for later use */
/* walk the partition list */
part_ptr = get_be_long(buf + 28);
for (i = 1; part_ptr != 0xffffffffUL; i++) {
if (get_buffer(section, (u8)part_ptr * 512, 256,
(void **)&buf) < 256) {
print_line(level, "Partition %d: Can't read partition info block");
break;
}
/* check signature */
if (memcmp(buf, "PART", 4) != 0) {
print_line(level, "Partition %d: Invalid signature");
break;
}
/* get "next" pointer for next iteration */
part_ptr = get_be_long(buf + 16);
/* get sizes */
cylsize = (u8)get_be_long(buf + 140) * (u8)get_be_long(buf + 148);
start = get_be_long(buf + 164) * cylsize;
size = (get_be_long(buf + 168) + 1 - get_be_long(buf + 164)) * cylsize;
snprintf(append, 63, " from %llu", start);
format_blocky_size(s, size, 512, "sectors", append);
print_line(level, "Partition %d: %s",
i, s);
/* get name */
get_pstring(buf + 36, s);
if (s[0])
print_line(level + 1, "Drive name \"%s\"", s);
/* show dos type */
format_dostype(s, buf + 192);
print_line(level + 1, "Type \"%s\" (%s)", s,
get_name_for_dostype(buf + 192));
/* detect contents */
if (size > 0 && start > 0) {
analyze_recursive(section, level + 1,
start * 512, size * 512, 0);
}
}
}
/*
* Amiga file system
*/
void detect_amiga_fs(SECTION *section, int level)
{
unsigned char *buf;
int i, isfs;
char s[256], *typename;
if (get_buffer(section, 0, 512, (void **)&buf) < 512)
return;
/* look for one of the signatures */
isfs = 0;
typename = NULL;
for (i = 0; amiga_dostypes[i].name; i++)
if (memcmp(buf, amiga_dostypes[i].typecode, 4) == 0) {
isfs = amiga_dostypes[i].isfs;
typename = amiga_dostypes[i].name;
break;
}
if (typename == NULL)
return;
if (isfs) {
print_line(level, "%s", typename);
format_dostype(s, buf);
print_line(level + 1, "Type \"%s\"", s);
if (section->size == 512*11*2*80) {
print_line(level+1, "Size matches DD floppy");
} else if (section->size == 512*22*2*80) {
print_line(level+1, "Size matches HD floppy");
}
} else {
format_dostype(s, buf);
print_line(level, "Amiga type code \"%s\" (%s)", s, typename);
}
}
/* EOF */
|