Hello tech,

This diff solves a problem with pdisk(8): it is disabling the Mac OS 9
drivers on the disk.  I use pdisk(8) to share a disk with Mac OS 9 and
OpenBSD macppc.  After pdisk(8) disabled my drivers, my Mac OS 9 boot
got stuck at the blinking '?' on the floppy icon.  I fixed it by
booting a CD and using Apple's Drive Setup to update the drivers.

pdisk(8) overwrote the list of drivers in block 0 with malloc garbage:

$ MALLOC_OPTIONS=S pdisk -l wd0
...
Drivers-
1: 56283 @ 3688618971, type=0xdbdb
2: 56283 @ 3688618971, type=0xdbdb
3: 56283 @ 3688618971, type=0xdbdb
4: 56283 @ 3688618971, type=0xdbdb

read_block0() should read the bytes from block0_ondisk->sbDDMap, not
the uninitialized garbage from map->sbDDMap; and write_block0() should
write to block0_ondisk->sbDDMap.  I also change some betoh32 to
betoh16, but the macppc host is already big-endian.  I am editing code
that krw@ edited in 2016.

Today, I redid my macppc partitions.  I built a bsd.rd (with gcc) with
this diff.  I reinstalled Mac OS 9, then OpenBSD.  While in bsd.rd, I
used pdisk to change my free space (left from Apple's Drive Setup)
to an OpenBSD partition.  Mac OS 9 still boots.  --George

Index: file_media.c
===================================================================
RCS file: /cvs/src/sbin/pdisk/file_media.c,v
retrieving revision 1.48
diff -u -p -r1.48 file_media.c
--- file_media.c        30 Jan 2016 17:21:10 -0000      1.48
+++ file_media.c        15 Mar 2020 15:58:51 -0000
@@ -152,7 +152,7 @@ read_block0(int fd, struct partition_map
 
        for (i = 0; i < 8; i++) {
                memcpy(&ddmap_ondisk,
-                   map->sbDDMap+i*sizeof(struct ddmap_ondisk),
+                   block0_ondisk->sbDDMap+i*sizeof(struct ddmap_ondisk),
                    sizeof(ddmap_ondisk));
                memcpy(&map->sbDDMap[i].ddBlock, &ddmap_ondisk.ddBlock,
                    sizeof(map->sbDDMap[i].ddBlock));
@@ -163,7 +163,7 @@ read_block0(int fd, struct partition_map
                map->sbDDMap[i].ddSize = betoh16(map->sbDDMap[i].ddSize);
                memcpy(&map->sbDDMap[i].ddType, &ddmap_ondisk.ddType,
                    sizeof(map->sbDDMap[i].ddType));
-               map->sbDDMap[i].ddType = betoh32(map->sbDDMap[i].ddType);
+               map->sbDDMap[i].ddType = betoh16(map->sbDDMap[i].ddType);
        }
 
        free(block0_ondisk);
@@ -212,10 +212,10 @@ write_block0(int fd, struct partition_ma
                tmp16 = htobe16(map->sbDDMap[i].ddSize);
                memcpy(&ddmap_ondisk.ddSize, &tmp16,
                    sizeof(ddmap_ondisk.ddSize));
-               tmp16 = betoh32(map->sbDDMap[i].ddType);
+               tmp16 = betoh16(map->sbDDMap[i].ddType);
                memcpy(&ddmap_ondisk.ddType, &tmp16,
                    sizeof(ddmap_ondisk.ddType));
-               memcpy(map->sbDDMap+i*sizeof(struct ddmap_ondisk),
+               memcpy(block0_ondisk->sbDDMap+i*sizeof(struct ddmap_ondisk),
                    &ddmap_ondisk, sizeof(ddmap_ondisk));
        }
 

Reply via email to