Subject: Re: Changes for installboot
To: Bill Studenmund <wrstuden@zembu.com>
From: Bob Nestor <rnestor@augustmail.com>
List: port-macppc
Date: 08/16/2000 19:14:57
Bill Studenmund wrote:

>I tested this code to make sure it compiled. I have not actually used it.
>Use with caution!
>
While I haven't run the code (my system is trashed right now due to a 
MacOS crash), I did notice some things that might be of interest.
>
>Here's the intended logic flow:
>
>We now go into the partiton map groveling even if we have the -n flag. We
>won't write anything (partition is opened r/o), but we will look at what's
>around. Can be combined with the -v flag to see what will be done.
>
There are some errors in the way the fake APM is configured right now.  
The disk size isn't correct and the APM has some minor errors in it.  I 
don't know if you want to fix these along the way or if it's even 
important to do so at this time.  The only reason I found them is that I 
relied on some of these fields in sysinst/mac68k.

>Otherwise we scan the partition map to see what is there. During this
>scan, we look for the partition map entry, the smallest free space entry
>which will fit the boot blocks, and an existing bootblock entry. The
>existing entry will be of type "NetBSD/macppc". We make the comparison
>happen case-insensitivly by manually upper-casing the name.
>
I noticed the #define's for the most common partition types.  The list 
isn't completely defined in NetBSD at the moment. There are driver 
partition types defined for ATA, ATAPI, and CDROM drivers that I've found 
looking at a number of disks and CDs.  Also these names are all 
case-insensitive although one gets the impression from reading Apple's 
docs that they are all upper-case.  This was a problem for Mkfs on the 
68k port a few years ago.

>If we find the partition map entry, we note how big it is. The way Apple
>part maps work, each partition has an entry of the number of valid
>partition entries. There is one partition entry which is the
>"Apple_Partition_Map". This partition entry starts at block 1, and covers
>all the valid entries. Its size also dictates how many partition entries
>can be added. Thus the number of partitions in use is strictly less than
>or equal to the size of this special partition.
>
The Partition Entry usually starts in block 1, but you can't count on 
this!  There are many disk formatters that scramble the blocks in the 
Partition Map and I've found that I always had to hunt for the entry that 
mapped the Partition Table itself.  Some disk formatters and disk setup 
routines improperly initialize the size of the Partition Table to be just 
the number of blocks used rather than the number allocated as the 
documentation calls for.  Mkhybrid is guilty of this error.  I've found 
that it's best to scan for the lowest allocated partition which is 
adjacent to the Map to determine the actual size of the Partition Map. 
(Apple docs indicate that all blocks on a disk are mapped by the 
Parititon Map except for Block0.) The other thing that many disk 
formatters do, which is incorrect, is to hide boot code in blocks in the 
Partition Map that are allocated but unused.  Apple even does this on 
some of their CDs in violation of their documentation.  Its not a problem 
on CDRs since the CD can't be modifed, but on a disk it can be a 
disaster.  It makes disk partitioning a real headache since the process 
can end up destroying disk boot code!


>If we find an "Apple_Free" partition, we found freespace. If it is big
>enough to hold the boot blocks and either we haven't found a free space
>partition yet, or this one is smaller than the one we already found, we
>use it.
>
Other partition types that might also qualify are "Apple_Scratch" and 
"Apple_Unused".  Both are present in some disk formatters.

>If we get to this point in the logic, we have to add a new boot partition.
>First we check to see if we have a free partition entry. If not, we bail.
>
>Then we get the freespace partition we're using. We strip space out of it,
>and save it. We then itterate over all partitions increasing the count of
>active partitions.
>
I haven't looked real close at the code yet, but I assume by "strip 
space" you mean allocating a part of the free space.  Do you create a new 
partition map entry to place the rest of the space in, i.e. do you 
"split" the original partition into two entries?

hope this helps,
-bob