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
|
/*
* 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 "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);
/*
192/c0 char4DosType 'DOS' and the FFS/OFS flag only
also 'UNI'\0 = AT&T SysV filesystem
'UNI'\1 = UNIX boot filesystem
'UNI'\2 = BSD filesystem for SysV
'resv' = reserved (swap space)
*/
/* 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 flags;
char s[256];
if (get_buffer(section, 0, 512, (void **)&buf) < 512)
return;
if (memcmp(buf, "DOS", 3) == 0){
flags = buf[4];
if (flags & 1)
strcpy(s, "Amiga FFS file system");
else
strcpy(s, "Amiga OFS file system");
if (flags & 4)
strcat(s, " (intl., dir cache)");
else if (flags & 2)
strcat(s, " (intl., no dir cache)");
else
strcat(s, " (non-intl., no dir cache)");
print_line(level, "%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 if (memcmp(buf, "PFS", 3) == 0) {
print_line(level, "Amiga Professional File System");
}
}
/* EOF */
|