diff options
author | Martin Reindl <martin@cvs.openbsd.org> | 2006-04-27 19:52:22 +0000 |
---|---|---|
committer | Martin Reindl <martin@cvs.openbsd.org> | 2006-04-27 19:52:22 +0000 |
commit | ed27cd970afc6b5a1f13bcbcfa6e6f2c17383ea3 (patch) | |
tree | 1705907342ecd5f075b44fae6b75b82b0a5d413d /sbin/pdisk/dump.c | |
parent | e317d0527a2e9963eb4d77f7416c9714f02efcfd (diff) |
update for pdisk 0.8a2, from NetBSD, retaining our local changes;
summing it up:
- Clean up sources - fix naming, delete old email addresses
- Added support for display of Mac volume names
- Fix block 0 display to show logical offset of drivers
- Require confirmation of quit without write
- Fix iteration to not complain about missing devices
- Warn when creating/writing a map with more than 15 entries
and, most important, add do_update_dpme() which allows us to partition
OpenBSD slices without previous MacOS setup.
Tested with shared MacOS install on macppc, procedure there remains the
same.
grammer and spelling help and ok jmc@
ok miod@
Diffstat (limited to 'sbin/pdisk/dump.c')
-rw-r--r-- | sbin/pdisk/dump.c | 158 |
1 files changed, 137 insertions, 21 deletions
diff --git a/sbin/pdisk/dump.c b/sbin/pdisk/dump.c index bd1bee0872b..d5b25cd22a4 100644 --- a/sbin/pdisk/dump.c +++ b/sbin/pdisk/dump.c @@ -1,7 +1,7 @@ // // dump.c - dumping partition maps // -// Written by Eryk Vershen (eryk@apple.com) +// Written by Eryk Vershen // /* @@ -63,17 +63,44 @@ // Types // typedef struct names { - char *abbr; - char *full; + const char *abbr; + const char *full; } NAMES; +#ifdef __unix__ +typedef unsigned long OSType; +#endif + +typedef struct PatchDescriptor { + OSType patchSig; + unsigned short majorVers; + unsigned short minorVers; + unsigned long flags; + unsigned long patchOffset; + unsigned long patchSize; + unsigned long patchCRC; + unsigned long patchDescriptorLen; + unsigned char patchName[33]; + unsigned char patchVendor[1]; +} PatchDescriptor; +typedef PatchDescriptor * PatchDescriptorPtr; + +typedef struct PatchList { + unsigned short numPatchBlocks; // number of disk blocks to hold the patch list + unsigned short numPatches; // number of patches in list + PatchDescriptor thePatch[1]; +} PatchList; +typedef PatchList *PatchListPtr; + // // Global Constants // NAMES plist[] = { {"Drvr", "Apple_Driver"}, + {"Drv4", "Apple_Driver43"}, {"Free", "Apple_Free"}, + {"Patc", "Apple_Patches"}, {" HFS", "Apple_HFS"}, {" MFS", "Apple_MFS"}, {"PDOS", "Apple_PRODOS"}, @@ -92,6 +119,7 @@ const char * kStringNot = " not"; // int aflag = AFLAG_DEFAULT; /* abbreviate partition types */ int pflag = PFLAG_DEFAULT; /* show physical limits of partition */ +int fflag = FFLAG_DEFAULT; /* show HFS volume names */ // @@ -137,6 +165,7 @@ dump_block_zero(partition_map_header *map) int i; double value; int prefix; + long t; p = map->misc; if (p->sbSig != BLOCK0_SIGNATURE) { @@ -154,9 +183,16 @@ dump_block_zero(partition_map_header *map) printf("Drivers-\n"); m = (DDMap *) p->sbMap; for (i = 0; i < p->sbDrvrCount; i++) { - printf("%u: @ %lu for %u, type=0x%x\n", i+1, - get_align_long(&m[i].ddBlock), - m[i].ddSize, m[i].ddType); + printf("%u: %3u @ %lu, ", i+1, + m[i].ddSize, get_align_long(&m[i].ddBlock)); + if (map->logical_block != p->sbBlkSize) { + t = (m[i].ddSize * p->sbBlkSize) / map->logical_block; + printf("(%lu@", t); + t = (get_align_long(&m[i].ddBlock) * p->sbBlkSize) + / map->logical_block; + printf("%lu) ", t); + } + printf("type=0x%x\n", m[i].ddType); } } printf("\n"); @@ -176,7 +212,7 @@ dump_partition_map(partition_map_header *map, int disk_order) bad_input("No partition map exists"); return; } - alternate = get_mklinux_name(map->name); + alternate = get_linux_name(map->name); if (alternate) { printf("\nPartition map (with %d byte blocks) on '%s' (%s)\n", map->logical_block, map->name, alternate); @@ -230,10 +266,15 @@ dump_partition_entry(partition_map *entry, int type_length, int name_length, int partition_map_header *map; int j; DPME *p; - char *s; + const char *s; u32 size; double bytes; int driver; + // int kind; + char *buf; +#if 1 + BZB *bp; +#endif map = entry->the_map; p = entry->data; @@ -246,14 +287,31 @@ dump_partition_entry(partition_map *entry, int type_length, int name_length, int break; } } - printf("%2ld: %.4s%c%-*.32s ", - entry->disk_address, s, driver, name_length, p->dpme_name); + printf("%2ld: %.4s", entry->disk_address, s); } else { - printf("%2ld: %*.32s%c%-*.32s ", - entry->disk_address, type_length, p->dpme_type, - driver, name_length, p->dpme_name); + printf("%2ld: %*.32s", entry->disk_address, type_length, p->dpme_type); } + buf = (char *) malloc(name_length+1); + if (entry->HFS_name == NULL || fflag == 0) { + strncpy(buf, p->dpme_name, name_length); + buf[name_length] = 0; + } else { + snprintf(buf, name_length + 1, "\"%s\"", entry->HFS_name); + } + printf("%c%-*.32s ", driver, name_length, buf); + free(buf); + /* + switch (entry->HFS_kind) { + case kHFS_std: kind = 'h'; break; + case kHFS_embed: kind = 'e'; break; + case kHFS_plus: kind = '+'; break; + default: + case kHFS_not: kind = ' '; break; + } + printf("%c ", kind); + */ + if (pflag) { printf("%*lu ", digits, p->dpme_pblocks); size = p->dpme_pblocks; @@ -279,7 +337,7 @@ dump_partition_entry(partition_map *entry, int type_length, int name_length, int printf(" (%#5.1f%c)", bytes, j); } -#if 0 +#if 1 // Old A/UX fields that no one pays attention to anymore. bp = (BZB *) (p->dpme_bzb); j = -1; @@ -310,7 +368,7 @@ dump_partition_entry(partition_map *entry, int type_length, int name_length, int break; } if (bzb_slice_get(bp) != 0) { - printf(" s%1d %4s", bzb_slice_get(bp)-1, s); + printf(" s%1ld %4s", bzb_slice_get(bp)-1, s); } else if (j >= 0) { printf(" S%1d %4s", j, s); } else { @@ -352,7 +410,9 @@ list_all_disks() while ((name = step_media_iterator(iter)) != 0) { if ((m = open_pathname_as_media(name, O_RDONLY)) == 0) { +#if defined(__linux__) || defined(__unix__) error(errno, "can't open file '%s'", name); +#endif } else { close_media(m); @@ -378,7 +438,7 @@ show_data_structures(partition_map_header *map) partition_map * entry; DPME *p; BZB *bp; - char *s; + const char *s; if (map == NULL) { printf("No partition map exists\n"); @@ -388,8 +448,9 @@ show_data_structures(partition_map_header *map) printf("map %d blocks out of %d, media %lu blocks (%d byte blocks)\n", map->blocks_in_map, map->maximum_in_map, map->media_size, map->logical_block); - printf("Map is%s writable", (map->writeable)?kStringEmpty:kStringNot); - printf(", but%s changed\n", (map->changed)?kStringEmpty:kStringNot); + printf("Map is%s writable", (map->writable)?kStringEmpty:kStringNot); + printf(", but%s changed", (map->changed)?kStringEmpty:kStringNot); + printf(" and has%s been written\n", (map->written)?kStringEmpty:kStringNot); printf("\n"); if (map->misc == NULL) { @@ -519,14 +580,14 @@ xx: cccc RU *dd s... void -full_dump_partition_entry(partition_map_header *map, int index) +full_dump_partition_entry(partition_map_header *map, int ix) { partition_map * cur; DPME *p; int i; u32 t; - cur = find_entry_by_disk_address(index, map); + cur = find_entry_by_disk_address(ix, map); if (cur == NULL) { printf("No such partition\n"); return; @@ -657,12 +718,18 @@ full_dump_block_zero(partition_map_header *map) dump_block((unsigned char *)&m[i].ddBlock, (&zp->sbMap[247]-((unsigned short *)&m[i].ddBlock))*2); } + void display_patches(partition_map *entry) { long long offset; MEDIA m; static unsigned char *patch_block; + PatchListPtr p; + PatchDescriptorPtr q; + unsigned char *next; + unsigned char *s; + int i; offset = entry->data->dpme_pblock_start; m = entry->the_map->m; @@ -678,7 +745,45 @@ display_patches(partition_map *entry) error(errno, "Can't read patch block"); return; } - dump_block(patch_block, PBLOCK_SIZE); + p = (PatchListPtr) patch_block; + if (p->numPatchBlocks != 1) { + i = p->numPatchBlocks; + free(patch_block); + patch_block = (unsigned char *) malloc(PBLOCK_SIZE*i); + if (patch_block == NULL) { + error(errno, "can't allocate memory for patch blocks buffer"); + return; + } + s = patch_block + PBLOCK_SIZE*i; + while (i > 0) { + s -= PBLOCK_SIZE; + i -= 1; + if (read_media(m, offset+i, PBLOCK_SIZE, (char *)s) == 0) { + error(errno, "Can't read patch block %d", i); + return; + } + } + p = (PatchListPtr) patch_block; + } + printf("Patch list (%d entries)\n", p->numPatches); + q = p->thePatch; + for (i = 0; i < p->numPatches; i++) { + printf("%2d signature: '%.4s'\n", i+1, (char *)&q->patchSig); + printf(" version: %d.%d\n", q->majorVers, q->minorVers); + printf(" flags: 0x%lx\n", q->flags); + printf(" offset: %ld\n", q->patchOffset); + printf(" size: %ld\n", q->patchSize); + printf(" CRC: 0x%lx\n", q->patchCRC); + printf(" name: '%.*s'\n", q->patchName[0], &q->patchName[1]); + printf(" vendor: '%.*s'\n", q->patchVendor[0], &q->patchVendor[1]); + next = ((unsigned char *)q) + q->patchDescriptorLen; + s = &q->patchVendor[q->patchVendor[0]+1]; + if (next > s) { + printf("remainder of entry -"); + dump_block(s, next-s); + } + q = (PatchDescriptorPtr)next; + } } int @@ -736,6 +841,17 @@ get_max_name_string_length(partition_map_header *map) if (length > max) { max = length; } + + if (fflag) { + if (entry->HFS_name == NULL) { + length = 0; + } else { + length = strlen(entry->HFS_name) + 2; + } + if (length > max) { + max = length; + } + } } return max; |