Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
/*	$NetBSD: md.c,v 1.12 2022/04/07 19:33:38 andvar Exp $ */

/*
 * Copyright 1997 Piermont Information Systems Inc.
 * All rights reserved.
 *
 * Based on code written by Philip A. Nelson for Piermont Information
 * Systems Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

/* md.c -- mac68k machine specific routines */

#include <stdio.h>
#include <util.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <machine/int_fmtio.h>

#include "defs.h"
#include "md.h"
#include "msg_defs.h"
#include "menu_defs.h"

static int	stricmp(const char *c1, const char *c2);
static void	setpartition(struct apple_part_map_entry *, char *, int);
static int	getFreeLabelEntry(char *);
static char	*getFstype(struct apple_part_map_entry *, int, char *);
static char	*getUse(struct apple_part_map_entry *, int, char *);
static char	*getName(struct apple_part_map_entry *, int, char *);
static int	findStdType(int, char *, int, int *, int);
static int	check_for_errors(void);
static int	edit_diskmap(void);
#ifdef MD_DEBUG_SORT_MERGE
static int	md_debug_dump(char *);
#endif

int blk_size;

MAP_TYPE map_types[] = {
	{MAP_RESERVED, APPLE_PART_TYPE_DRIVER},
	{MAP_RESERVED, APPLE_PART_TYPE_DRIVER43},
	{MAP_RESERVED, APPLE_PART_TYPE_DRIVERATA},
	{MAP_RESERVED, APPLE_PART_TYPE_FWB_COMPONENT},
	{MAP_MACOS,    APPLE_PART_TYPE_MAC},
	{MAP_NETBSD,   APPLE_PART_TYPE_NETBSD},
	{MAP_RESERVED, APPLE_PART_TYPE_PARTMAP},
	{MAP_OTHER,    APPLE_PART_TYPE_SCRATCH},
	{MAP_NETBSD,   APPLE_PART_TYPE_UNIX},
	{MAP_EOL,      NULL}
};

MAP map = {0, 0, 0, 0, 0, 0, 0, 0, {0}, NULL};

struct apple_part_map_entry new_map[] =
{
	{ APPLE_PART_MAP_ENTRY_MAGIC, 0xa5a5, 6, 1, NEW_MAP_SIZE & 0x7e,
	  "Apple", "Apple_Partition_Map", 0, NEW_MAP_SIZE, 0x37,
	  0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
	{ APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 64, 32,
	  "Macintosh", "Apple_Driver", 0, 0, 0x37,
	  0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
	{ APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 96, 64,
	  "Macintosh", "Apple_Driver43", 0, 0, 0x37,
	  0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
	{ APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 160, 64,
	  "Macintosh", "Apple_Driver_ATA", 0, 0, 0x37,
	  0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
	{ APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 224, 4096,
	  "untitled", "Apple_HFS", 0, 0, 0x37,
	  0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
	{ APPLE_PART_MAP_ENTRY_MAGIC, 0, 6,4320, 0,
	  "untitled", "Apple_Free", 0, 0, 0x37,
	  0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}}
};

void
md_init(void)
{
}

void
md_init_set_status(int flags)
{
       struct utsname instsys;

	(void)flags;

	/*
	 * Get the name of the Install Kernel we are running under and
	 * enable the installation of the corresponding GENERIC kernel.
	 *
	 * Note:  In md.h the two kernels are disabled.  If they are
	 *        enabled there the logic here needs to be switched.
	 */
        uname(&instsys);
        if (strstr(instsys.version, "(INSTALLSBC)"))
		/*
		 * Running the SBC Installation Kernel, so enable GENERICSBC
		 */
		set_kernel_set(SET_KERNEL_2);
        else
		/*
		 * Running the GENERIC Installation Kernel, so enable GENERIC
		 */
		set_kernel_set(SET_KERNEL_1);
}

bool
md_get_info(struct install_partition_desc *install)
{
	struct disklabel disklabel;
	int fd, i;
	char dev_name[100];
	struct apple_part_map_entry block;

	snprintf(dev_name, sizeof(dev_name), "/dev/r%s%c",
		pm->diskdev, 'a' + getrawpartition());

	/*
	 * Open the disk as a raw device
	 */
	fd = open(dev_name, O_RDONLY, 0);
	if (fd < 0) {
		endwin();
		fprintf (stderr, "Can't open %s\n", dev_name);
		exit(1);
	}
	/*
	 * Try to get the default disklabel info for the device
	 */
	if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
		endwin();
		fprintf (stderr, "Can't read disklabel on %s\n", dev_name);
		close(fd);
		exit(1);
	}
	/*
	 * Get the disk parameters from the disk driver.  It should have
	 *  obained them by querying the disk itself.
	 */
	blk_size = disklabel.d_secsize;
	pm->dlcyl = disklabel.d_ncylinders;
	pm->dlhead = disklabel.d_ntracks;
	pm->dlsec = disklabel.d_nsectors;
	/*
	 * Just in case, initialize the structures we'll need if we
	 *  need to completely initialize the disk.
	 */
	pm->dlsize = disklabel.d_secperunit;
/*
 * XXX this code is broken: it accesses off the end of new_map[],
 * because NEW_MAP_SIZE is substantially larger than the number of
 * entries in new_map[]. Based on the description of struct
 * apple_part_map_entry in sys/bootblock.h, and the usage of it in
 * new_map[], NEW_MAP_SIZE is expected to be a block count, not an
 * entry count. As far I can tell the logic here is just wrong; it
 * needs someone with platform knowledge to sort it out.
 *
 * Note that nothing uses the data this writes into new_map[] so
 * disabling it should have no adverse consequences.
 *
 *   - dholland 20160530
 */
#if 0 /* XXX broken */
	for (i=0;i<NEW_MAP_SIZE;i++) {
	   if (i > 0)
		new_map[i].pmPyPartStart = new_map[i-1].pmPyPartStart +
			new_map[i-1].pmPartBlkCnt;
	   new_map[i].pmDataCnt = new_map[i].pmPartBlkCnt;
	   if (new_map[i].pmPartBlkCnt == 0) {
		new_map[i].pmPartBlkCnt = pm->dlsize;
		new_map[i].pmDataCnt = pm->dlsize;
		break;
	   }
	   pm->dlsize -= new_map[i].pmPartBlkCnt;
	}
#endif /* 0 - broken */
	pm->dlsize = disklabel.d_secperunit;
#if 0
	msg_fmt_display(MSG_dldebug, "%d%d%d%d%d",
	    blk_size, pm->dlcyl, pm->dlhead, pm->dlsec, pm->dlsize);
	process_menu(MENU_ok, NULL);
#endif
	map.size = 0;
	/*
	 * Verify the disk has been initialized for MacOS use by checking
	 *  to see if the disk have a Boot Block
	 */
	if (lseek(fd, (off_t)0 * blk_size, SEEK_SET) < 0 ||
	    read(fd,  &block, sizeof(block)) - sizeof(block) != 0 ||
	    block.pmSig != 0x4552) {
             process_menu(MENU_nodiskmap, NULL);
        }
	else {
	   /*
	    * Scan for the Partition Map entry that describes the Partition
	    *  Map itself.  We need to know the number of blocks allocated
	    *  to it and the number currently in use.
	    */
	   for (i=0;i<MAXMAXPARTITIONS;i++) {
		lseek(fd, (off_t)(i+1) * blk_size, SEEK_SET);
		read(fd, &block, sizeof(block));
		if (stricmp("Apple_partition_map", (char *)block.pmPartType) == 0) {
		    map.size = block.pmPartBlkCnt;
		    map.in_use_cnt = block.pmMapBlkCnt;
		    map.blk = (struct apple_part_map_entry *)malloc(map.size * blk_size);
		    break;
	        }
            }
	    lseek(fd, (off_t)1 * blk_size, SEEK_SET);
	    read(fd, map.blk, map.size * blk_size);
	}
	close(fd);

	return edit_diskmap();
}

/*
 * md back-end code for menu-driven BSD disklabel editor.
 */
int
md_make_bsd_partitions(struct install_partition_desc *install)
{
	int i, j, rv;
	EBZB *bzb;
	struct disk_part_info info;
	uint fs_type;
	const char *mountpoint;
	part_id pid;
	size_t ndx;

	/*
	 * Scan for any problems and report them before continuing.
	 *  The user can abort installation and we'll take them back
	 *  to the main menu; continue ignoring the warnings, or
	 *  ask to reedit the Disk Partition Map.
	 */
	while (1) {
	    if (check_for_errors()) {
	        process_menu (MENU_sanity, &rv);
	        if (rv < 0)
		    return 0;
	        else if (rv)
		    break;
	        edit_diskmap();
	    } else
		break;
	}

	/* Start with empty fake disklabel partitions */
	pm->parts->pscheme->delete_all_partitions(pm->parts);

	/*
	 * Now, scan through the Disk Partition Map and transfer the
	 *  information into the incore disklabel.
	 */
	for (i=0;i<map.usable_cnt;i++) {
	    j = map.mblk[i];
	    bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
	    if (bzb->flags.part) {
		mountpoint = NULL;
		fs_type = FS_UNUSED;
		switch (whichType(&map.blk[j])) {
		    case HFS_PART:
			fs_type = FS_HFS;
			mountpoint = (const char*)bzb->mount_point;
			break;
		    case ROOT_PART:
		    case UFS_PART:
			fs_type = FS_BSDFFS;
			mountpoint = (const char*)bzb->mount_point;
			break;
		    case SWAP_PART:
			fs_type = FS_SWAP;
			break;
		    case SCRATCH_PART:
			fs_type = FS_OTHER;
			mountpoint = (const char*)bzb->mount_point;
			break;
		    default:
			continue;
		}
		if (fs_type != FS_UNUSED) {
			memset(&info, 0, sizeof info);
			info.start = map.blk[j].pmPyPartStart;
			info.size = map.blk[j].pmPartBlkCnt;
			info.fs_type = fs_type;
			info.last_mounted = mountpoint;
			info.nat_type = pm->parts->pscheme->get_fs_part_type(
			    PT_root, fs_type, 0);
			pid = pm->parts->pscheme->add_outer_partition(pm->parts,
			    &info, NULL);
			if (pid == NO_PART)
				return 0;
		}
	    }
	}

	/* Disk name  - don't bother asking, just use the physical name*/
	pm->parts->pscheme->set_disk_pack_name(pm->parts, pm->diskdev);

	/* Write the converted partitions */
	if (!pm->parts->pscheme->write_to_disk(pm->parts))
		return 0;

	/* now convert to install info */
	if (!install_desc_from_parts(install, pm->parts))
		return 0;

	/* set newfs flag for all FFS partitions */
	for (ndx = 0; ndx < install->num; ndx++) {
		if (install->infos[ndx].fs_type == FS_BSDFFS &&
		    install->infos[ndx].size > 0 &&
		    (install->infos[ndx].instflags & PUIINST_MOUNT))
			install->infos[ndx].instflags |= PUIINST_NEWFS;
	}

	return 1;
}

/*
 * any additional partition validation
 */
bool
md_check_partitions(struct install_partition_desc *install)
{
	return true;
}

/*
 * hook called before writing new disklabel.
 */
bool
md_pre_disklabel(struct install_partition_desc *install,
    struct disk_partitions *parts)
{
    int fd;
    char dev_name[100];
    struct disklabel lp;
    Block0 new_block0 = {APPLE_DRVR_MAP_MAGIC, 512,
	 		 0, 0, 0, 0, 0, 0, 0, 0, {0}};

    /*
     * Danger Will Robinson!  We're about to turn that nice MacOS disk
     *  into an expensive doorstop...
     */
    printf ("%s", msg_string (MSG_dodiskmap));

    snprintf (dev_name, sizeof(dev_name), "/dev/r%sc", pm->diskdev);
    /*
     * Open the disk as a raw device
     */
    if ((fd = open(dev_name, O_WRONLY, 0)) < 0) {
	endwin();
	fprintf(stderr, "Can't open %s to rewrite the Disk Map\n", dev_name);
	exit (1);
    }
    /*
     *  First check the pmSigPad field of the first block in the incore
     *  Partition Map.  It should be zero, but if it's 0xa5a5 that means
     *  we need to write out Block0 too.
     */
    if (map.blk[0].pmSigPad == 0xa5a5) {
	if (lseek (fd, (off_t)0 * blk_size, SEEK_SET) < 0) {
	    endwin();
	    fprintf (stderr, "Can't position to write Block0\n");
	    close (fd);
	    exit (1);
	}
	new_block0.sbBlkCount = pm->dlsize;		/* Set disk size */
	if (write (fd, &new_block0, blk_size) != blk_size) {
	    endwin();
	    fprintf (stderr, "I/O error writing Block0\n");
	    close (fd);
	    exit (1);
	}
	map.blk[0].pmSigPad = 0;
    }
    if (lseek (fd, (off_t)1 * blk_size, SEEK_SET) < 0) {
	endwin();
	fprintf (stderr, "Can't position disk to rewrite Disk Map\n");
	close (fd);
	exit (1);
    }
    if (write (fd, map.blk, map.size * blk_size) != (map.size * blk_size)) {
	endwin();
	fprintf(stderr, "I/O error writing Disk Map\n");
	close (fd);
	exit (1);
    }
    fsync(fd);
    /*
     * Well, if we get here the dirty deed has been done.
     *
     * Now we need to force the incore disk table to get updated. This
     * should be done by disklabel -- which is normally called right after
     * we return -- but may be commented out for the mac68k port. We'll
     * instead update the incore table by forcing a dummy write here. This
     * relies on a change in the mac68k-specific write_disklabel() routine.
     * If that change doesn't exist nothing bad happens here. If disklabel
     * properly updates the ondisk and incore labels everything still
     * works. Only if we fail here and if disklabel fails are we in
     * in a state where we've updated the disk but not the incore and
     * a reboot is necessary.
     *
     * First, we grab a copy of the incore label as it existed before
     * we did anything to it. Then we invoke the "write label" ioctl to
     * rewrite it to disk. As a result, the ondisk partition map is
     * re-read and the incore label is reconstructed from it. If
     * disklabel() is then called to update again, either that fails
     * because the mac68k port doesn't support native disklabels, or it
     * succeeds and writes out a new ondisk copy.
     */
    ioctl(fd, DIOCGDINFO, &lp);    /* Get the current disk label */
    ioctl(fd, DIOCWDINFO, &lp);    /* Write it out again */

    close (fd);
    return true;
}

/*
 * hook called after writing disklabel to new target disk.
 */
bool
md_post_disklabel(struct install_partition_desc *install,
    struct disk_partitions *parts)
{
#if 0	// XXX
    struct disklabel updated_label;
    int fd, i, no_match;
    char dev_name[100], buf[80];
    const char *fst[] = {"free", "swap", " v6 ", " v7 ", "sysv", "v71k",
			" v8 ", "ffs ", "dos ", "lfs ", "othr", "hpfs",
			"9660", "boot", "ados", "hfs ", "fcor", "ex2f",
			"ntfs", "raid", "ccd "};

    snprintf(dev_name, sizeof(dev_name), "/dev/r%sc", pm->diskdev);
    /*
     * Open the disk as a raw device
     */
    if ((fd = open(dev_name, O_RDONLY, 0)) < 0)
       return false;
    /*
     * Get the "new" label to see if we were successful.  If we aren't
     *  we'll return an error to keep from destroying the user's disk.
     */
    ioctl(fd, DIOCGDINFO, &updated_label);
    close(fd);
    /*
     * Make sure the in-core label matches the on-disk one
     */
    no_match = 0;
    for (i=0;i<MAXPARTITIONS;i++) {
        if (i > updated_label.d_npartitions)
           break;
        if (pm->bsdlabel[i].pi_size != updated_label.d_partitions[i].p_size)
           no_match = 1;
        if (pm->bsdlabel[i].pi_size) {
           if (pm->bsdlabel[i].pi_offset != updated_label.d_partitions[i].p_offset)
               no_match = 1;
           if (pm->bsdlabel[i].pi_fstype != updated_label.d_partitions[i].p_fstype)
               no_match = 1;
        }
        if (no_match)
           break;
    }
    /*
     * If the labels don't match, tell the user why
     */
    if (no_match) {
       msg_clear();
       msg_display(MSG_label_error);
       msg_fmt_table_add(MSG_dump_line, "%s",
           " in-core: offset      size type on-disk: offset      size type");
       for (i=0;i<MAXPARTITIONS;i++) {
           snprintf(buf, sizeof(buf),
	      " %c:%13.8x%10.8x%5s%16.8x%10.8x%5s", i+'a',
              pm->bsdlabel[i].pi_offset, pm->bsdlabel[i].pi_size,
              fst[pm->bsdlabel[i].pi_fstype],
              updated_label.d_partitions[i].p_offset,
              updated_label.d_partitions[i].p_size,
              fst[updated_label.d_partitions[i].p_fstype]);
           msg_fmt_table_add(MSG_dump_line, "%s", buf);
       }
       process_menu(MENU_ok2, NULL);
    }
    return no_match == 0;
#else
	return true;
#endif
}

/*
 * hook called after upgrade() or install() has finished setting
 * up the target disk but immediately before the user is given the
 * ``disks are now set up'' message.
 */
int
md_post_newfs(struct install_partition_desc *install)
{
	return 0;
}

int
md_post_extract(struct install_partition_desc *install, bool upgrade)
{
	return 0;
}

void
md_cleanup_install(struct install_partition_desc *install)
{
#ifndef DEBUG
	enable_rc_conf();
#endif
}

int
md_pre_update(struct install_partition_desc *install)
{
	return 1;
}

/* Upgrade support */
int
md_update(struct install_partition_desc *install)
{
	md_post_newfs(install);
	return 1;
}

/*
 * Compare lexigraphically two strings
 */
static int
stricmp(s1, s2)
	const char *s1;
	const char *s2;
{
	char c1, c2;

	while (1) {
	    c1 = tolower((unsigned char)*s1++);
	    c2 = tolower((unsigned char)*s2++);
	    if (c1 < c2) return -1;
	    if (c1 > c2) return 1;
	    if (c1 == 0) return 0;
	}
}

static void
setpartition(part, in_use, slot)
	struct apple_part_map_entry *part;
	char in_use[];
	int slot;
{
	EBZB *bzb;

	bzb = (EBZB *)&part->pmBootArgs[0];
	in_use[slot] = 1;
	bzb->flags.used = 1;
	bzb->flags.part = 'a' + slot;
}

/*
 * Find an entry in a use array that is unused and return it or
 *  -1 if no entry is available
 */
static int
getFreeLabelEntry(slots)
	char *slots;
{
	int i;

	for ( i = 0; i < MAXPARTITIONS; i++) {
		if (i != RAW_PART && slots[i] == 0)
			return i;
	}
	return -1;
}

/*
 * Figure out what type type of the given partition is and return it.
 */
int
whichType(part)
	struct apple_part_map_entry *part;
{
	MAP_TYPE *map_entry = (MAP_TYPE *)&map_types;
	EBZB *bzb;
	char partyp[32];
	int type, maxsiz, entry_type = MAP_OTHER;

	bzb = (EBZB *)&part->pmBootArgs[0];
	if (part->pmSig != APPLE_PART_MAP_ENTRY_MAGIC)
	    return 0;
	maxsiz = sizeof(part->pmPartType);
	if (maxsiz > (int)sizeof(partyp))
	    maxsiz = sizeof(partyp);
	strncpy(partyp, (char *)part->pmPartType, maxsiz);
	partyp[maxsiz-1] = '\0';

	/*
	 * Find out how to treat the partition type under NetBSD
	 */
	while (map_entry->type != MAP_EOL) {
	    if (stricmp(map_entry->name, partyp) == 0) {
		entry_type = map_entry->type;
		break;
	    }
	    map_entry++;
	}

	/*
	 * Now classify the use for NetBSD
	 */
	if (entry_type == MAP_RESERVED)
		type = 0;
	else if (entry_type == MAP_NETBSD) {
	    if (bzb->magic != APPLE_BZB_MAGIC)
		type = 0;
	    else if (bzb->type == APPLE_BZB_TYPEFS) {
		if (bzb->flags.root)
		    type = ROOT_PART;
		else if (bzb->flags.usr)
		    type = UFS_PART;
		else
		    type = SCRATCH_PART;
	    } else if (bzb->type == APPLE_BZB_TYPESWAP)
		type = SWAP_PART;
	    else
		type = SCRATCH_PART;
	} else if (entry_type == MAP_MACOS)
	    type = HFS_PART;
	else
	    type = SCRATCH_PART;
	return type;
}

static char *
getFstype(part, len_type, type)
	struct apple_part_map_entry *part;
	int len_type;
	char *type;
{
	*type = '\0';
	switch(whichType(part)) {
	    case ROOT_PART:
	    case UFS_PART:
		strncpy(type, "4.2BSD", len_type);
		break;
	    case SWAP_PART:
		strncpy(type, "swap", len_type);
		break;
	    case HFS_PART:
		strncpy(type, "HFS", len_type);
		break;
	    case SCRATCH_PART:
	    default:
		break;
	}
	return (type);
}

static char *
getUse(part, len_use, use)
	struct apple_part_map_entry *part;
	int len_use;
	char *use;
{
	EBZB *bzb;
	char partyp[32];

	*use = '\0';
	bzb = (EBZB *)&part->pmBootArgs[0];
	switch(whichType(part)) {
	    case ROOT_PART:
		if (bzb->flags.usr)
		    strncpy(use, "Root&Usr", len_use);
		else
		    strncpy(use, "Root", len_use);
		break;
	    case UFS_PART:
		strncpy(use, "Usr", len_use);
		break;
	    case SWAP_PART:
		break;
	    case HFS_PART:
		strncpy(use, "MacOS", len_use);
		break;
	    case SCRATCH_PART:
		strncpy(partyp, (char *)part->pmPartType, sizeof(partyp));
		partyp[sizeof(partyp)-1] = '\0';
		if (stricmp("Apple_Free", partyp) == 0)
		    strncpy(use, "Free", len_use);
		else if (stricmp("Apple_Scratch", partyp) == 0)
		    strncpy(use, "Scratch", len_use);
		else if (stricmp("Apple_MFS", partyp) == 0)
		    strncpy(use, "MFS", len_use);
		else if (stricmp("Apple_PRODOS", partyp) == 0)
		    strncpy(use, "PRODOS", len_use);
		else
		    strncpy(use, "unknown", len_use);
	    default:
		break;
	}
	return(use);
}

static char *
getName(part, len_name, name)
	struct apple_part_map_entry *part;
	int len_name;
	char *name;
{
	EBZB *bzb;
	int fd;
	off_t seek;
	char dev_name[100], macosblk[512];

	*name = '\0';
	bzb = (EBZB *)&part->pmBootArgs[0];
	switch(whichType(part)) {
	    case SCRATCH_PART:
	    case ROOT_PART:
	    case UFS_PART:
		strncpy(name, (char *)bzb->mount_point, len_name);
		break;
	    case SWAP_PART:
		break;
	    case HFS_PART:
		/*
		 * OK, this is stupid but it's damn nice to know!
		 */
		snprintf (dev_name, sizeof(dev_name), "/dev/r%sc", pm->diskdev);
		/*
		 * Open the disk as a raw device
		 */
		if ((fd = open(dev_name, O_RDONLY, 0)) >= 0) {
		    seek = (off_t)part->pmPyPartStart + (off_t)2;
		    seek *= (off_t)blk_size;
		    lseek(fd, seek, SEEK_SET);
		    read(fd, &macosblk, sizeof(macosblk));
		    macosblk[37+32] = '\0';
		    strncpy(name, (char *)bzb->mount_point, len_name);
		    strncat(name, " (", len_name-strlen(name));
		    strncat(name, &macosblk[37], len_name-strlen(name));
		    strncat(name, ")", len_name-strlen(name));
		    close(fd);
		}
		break;
	    default:
		break;
	}
	return(name);
}

/*
 * Find the first occurrence of a Standard Type partition and
 *  mark it for use along with the default mount slot.
 */
static int
findStdType(num_parts, in_use, type, count, alt)
	int num_parts;
	char in_use[];
	int type;
	int *count;
	int alt;
{
	EBZB *bzb;
	int i;

	for (i = 0; i < num_parts; i++) {
		bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
		if (whichType(&map.blk[i]) != type || bzb->flags.used)
			continue;
		if (type == ROOT_PART) {
			if (alt >= 0 && alt != bzb->cluster)
				continue;
			setpartition(&map.blk[i], in_use, 0);
			strcpy ((char *)bzb->mount_point, "/");
			*count += 1;
		} else if (type == UFS_PART) {
			if (alt >= 0 && alt != bzb->cluster)
				continue;
			setpartition(&map.blk[i], in_use, 6);
			if (bzb->mount_point[0] == '\0')
				strcpy ((char *)bzb->mount_point, "/usr");
			*count += 1;
		} else if (type == SWAP_PART) {
			setpartition(&map.blk[i], in_use, 1);
			*count += 1;
		}
		return 0;
	}
	return -1;
}

/*
 * Reset the flags and reserved fields in the selected partition.
 * This functions isn't called to process any of the reserved partitions
 * where the boot code for MacOS is stored, so (hopefully) we won't
 * do more damage that we're trying to avoid.  Eventually the NetBSD
 * Boot Code will need to go into a partition too, but that should go
 * into a reserved partition as well.  I'd suggest using a partition
 * named something like "NetBSD_Boot" with a pmPartName of "Macintosh".
 * The Apple Start Manager (in ROM) will then recognize the partition
 * as the one containing the system bootstrip for the volume.
 */
void
reset_part_flags(part)
	struct apple_part_map_entry *part;
{
	EBZB *bzb;

	/*
	 * Clear out the MacOS fields that might be used for booting just
	 *  in case we've clobbered the boot code.
	 */
	part->pmLgDataStart = 0;
	part->pmPartStatus = 0x77;  /* make sure the partition shows up */
	part->pmLgBootStart = 0;
	part->pmBootSize = 0;
	part->pmBootLoad = 0;
	part->pmBootLoad2 = 0;
	part->pmBootEntry = 0;
	part->pmBootEntry2 = 0;
	part->pmBootCksum = 0;

	/*
	 * Clear out all the NetBSD fields too.  We only clear out the ones
	 *  that should get reset during our processing.
	 */
	bzb = (EBZB *)&part->pmBootArgs[0];
	bzb->magic = 0;
	bzb->cluster = 0;
	bzb->inode = 0;
	bzb->type = 0;
	bzb->flags.root = 0;
	bzb->flags.usr = 0;
	bzb->flags.crit = 0;
	bzb->flags.slice = 0;
	bzb->flags.used = 0;
	return;
}

/*
 * sortmerge:
 *  1) Moves all the Partition Map entries to the front of the Map.
 *     This is required because some disk formatters leave holes.
 *  2) Sorts all entries by ascending start block number.
 *     Needed so the NetBSD algorithm for finding partitions works
 *     consistently from a user perspective.
 *  3) Collapse multiple adjected "free" entries into a single entry.
 *  4) Identify the NetBSD mount_points.
 */
void
sortmerge(void)
{
    struct apple_part_map_entry tmp_blk;
    char in_use[MAXPARTITIONS];
    int i, j;
    EBZB *bzb;

    /*
     * Step 1, squeeze out the holes that some disk formatters leave in
     *  the Map.  Also convert any "old" Map entries to the new entry
     *  type. Also clear out our used flag which is used to indicte
     *  we've mapped the partition.
     */
    map.in_use_cnt = 0;
    for (i=0;i<map.size-1;i++) {
	if (map.blk[i].pmSig == 0x5453)
	    map.blk[i].pmSig = APPLE_PART_MAP_ENTRY_MAGIC;
	if (map.blk[i].pmSig != APPLE_PART_MAP_ENTRY_MAGIC) {
	    for (j=i+1;j<map.size;j++) {
		if (map.blk[j].pmSig == 0x5453)
		    map.blk[j].pmSig = APPLE_PART_MAP_ENTRY_MAGIC;
		if (map.blk[j].pmSig == APPLE_PART_MAP_ENTRY_MAGIC) {
		    memcpy (&map.blk[i], &map.blk[j], sizeof(map.blk[i]));
		    map.blk[j].pmSig = 0;
		    break;
		}
	    }
	} else {
	    map.in_use_cnt += 1;
	    bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
	    bzb->flags.used = 0;
	    bzb->flags.part = 0;
	}
    }

    /*
     * Step 2, sort by ascending starting block number.  Since
     *         we've already removed the holes we only need to
     *         deal with the in_use count of blocks.
     */
    for (i=0;i<map.in_use_cnt-1;i++) {
	for (j=i+1;j<map.in_use_cnt;j++) {
	    if (map.blk[i].pmPyPartStart > map.blk[j].pmPyPartStart) {
		memcpy (&tmp_blk, &map.blk[i], sizeof(tmp_blk));
		memcpy (&map.blk[i], &map.blk[j], sizeof(map.blk[i]));
		memcpy (&map.blk[j], &tmp_blk, sizeof(map.blk[j]));
	    }
	}
    }

    /*
     * Step 3, merge adjacent free space
     */
    for (i=0;i<map.in_use_cnt-1;i++) {
        if (stricmp("Apple_Free", (char *)map.blk[i].pmPartType) == 0 &&
	    stricmp("Apple_Free", (char *)map.blk[i+1].pmPartType) == 0) {
	    map.blk[i].pmPartBlkCnt += map.blk[i+1].pmPartBlkCnt;
	    map.blk[i].pmDataCnt += map.blk[i+1].pmDataCnt;
	    map.blk[i+1].pmSig = 0;
	    for (j=i+1;j<map.in_use_cnt-1;j++) {
		memcpy (&map.blk[j], &map.blk[j+1], sizeof(map.blk[j]));
		map.blk[j+1].pmSig = 0;
	    }
	    map.in_use_cnt -= 1;
	}
    }

    /*
     * Step 4, try to identify the mount points for the partitions
     *         and adjust the pmMapBlkCnt in each Map entry.  Set
     *         up the display array for the non-reserved partitions,
     *         and count the number of NetBSD usable partitions
     */
    map.hfs_cnt = 0;
    map.root_cnt = 0;
    map.swap_cnt = 0;
    map.usr_cnt = 0;
    map.usable_cnt = 0;
    /*
     * Clear out record of partition slots already in use
     */
    memset(&in_use, 0, sizeof(in_use));
    for (i=0,j=0;i<map.in_use_cnt;i++) {
        map.blk[i].pmSig = APPLE_PART_MAP_ENTRY_MAGIC;
        map.blk[i].pmMapBlkCnt = map.in_use_cnt;
	/*
	 * Since MAXPARTITIONS == 8 for mac68k, and we do not display
	 * the c partition, we only need 7 partition slots on the screen.
	 * If/when MAXPARTITIONS is changed, the "Edit Disk Partition Map"
	 * needs to be a scrollable view of the partition table.
	 */
        if (whichType(&map.blk[i]) && (j < MAXPARTITIONS - 1)) {
		map.mblk[j++] = i;
		map.usable_cnt += 1;
	}
    }
    /*
     * Fill in standard partitions.  Look for a Cluster "0" first and use
     *  it, otherwise take any Cluster value.
     */
    if (findStdType(map.in_use_cnt, in_use, ROOT_PART, &map.root_cnt, 0))
	findStdType(map.in_use_cnt, in_use, ROOT_PART, &map.root_cnt, -1);
    if (findStdType(map.in_use_cnt, in_use, UFS_PART, &map.usr_cnt, 0))
	findStdType(map.in_use_cnt, in_use, UFS_PART, &map.usr_cnt, -1);
    if (findStdType(map.in_use_cnt, in_use, SWAP_PART, &map.swap_cnt, 0))
	findStdType(map.in_use_cnt, in_use, SWAP_PART, &map.swap_cnt, -1);

#ifdef MD_DEBUG_SORT_MERGE
	md_debug_dump("After marking Standard Types");
#endif
    /*
     * Now fill in the remaining partitions counting them by type and
     *  assigning them the slot the where the kernel should map them.
     * This will be where they are displayed in the Edit Map.
     */
    for (i=0; i < map.in_use_cnt; i++) {
	bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
	if (bzb->flags.used == 0) {
	    if ((j = getFreeLabelEntry(in_use)) < 0)
		break;
	    switch (whichType(&map.blk[i])) {
		case ROOT_PART:
		    map.root_cnt += 1;
		    setpartition(&map.blk[i], in_use, j);
		    break;
		case UFS_PART:
		    map.usr_cnt += 1;
		    setpartition(&map.blk[i], in_use, j);
		    break;
		case SWAP_PART:
		    map.swap_cnt += 1;
		    setpartition(&map.blk[i], in_use, j);
		    break;
		case HFS_PART:
		    map.hfs_cnt += 1;
		    setpartition(&map.blk[i], in_use, j);
		    break;
		case SCRATCH_PART:
		    setpartition(&map.blk[i], in_use, j);
		default:
		    break;
	    }
	}
    }
#ifdef MD_DEBUG_SORT_MERGE
	md_debug_dump("After sort merge");
#endif
    return;
}

void
disp_selected_part(sel)
	int sel;
{
	int i,j;
	char fstyp[16], use[16], name[32];
	EBZB *bzb;

	msg_table_add(MSG_mac68k_part_header);
	for (i=0;i<map.usable_cnt;i++) {
	    if (i == sel) msg_standout();
	    j = map.mblk[i];
	    getFstype(&map.blk[j], sizeof(fstyp), fstyp);
	    getUse(&map.blk[j], sizeof(use), use);
	    getName(&map.blk[j], sizeof(name), name);
	    bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
	    msg_fmt_table_add(MSG_part_row, "%s%c%d%d%s%s%s",
		pm->diskdev,
		bzb->flags.part, map.blk[j].pmPyPartStart,
                 map.blk[j].pmPartBlkCnt, fstyp, use, name);
	    if (i == sel) msg_standend();
	}
	return;
}

/*
 * check for any anomalies on the requested setup
 */
static int
check_for_errors()
{
    int i, j;
    int errs = 0;

    errs = (!map.root_cnt) || (map.root_cnt > 1) || (!map.swap_cnt) ||
	   (map.swap_cnt > 1);

    for (i=0;i<map.usable_cnt;i++) {
	j = map.mblk[i];
	if (map.blk[j].pmPyPartStart > pm->dlsize)
		errs++;
	if ((map.blk[j].pmPyPartStart + map.blk[j].pmPartBlkCnt) > pm->dlsize + 1)
		errs++;
    }
    return(errs);
}

/*
 * check for and report anomalies on the requested setup
 */
void
report_errors()
{
    int i, j;
    int errs = 0;
    EBZB *bzb;

    if (!map.root_cnt) {
	msg_display_add(MSG_disksetup_no_root);
	errs++;
    }
    if (map.root_cnt > 1) {
	msg_display_add(MSG_disksetup_multiple_roots);
	errs++;
    }
    if (!map.swap_cnt) {
	msg_display_add(MSG_disksetup_no_swap);
	errs++;
    }
    if (map.swap_cnt > 1) {
	msg_display_add(MSG_disksetup_multiple_swaps);
	errs++;
    }
    for (i=0;i<map.usable_cnt;i++) {
	j = map.mblk[i];
	if (map.blk[j].pmPyPartStart > pm->dlsize) {
	    bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
	    msg_fmt_display_add(MSG_disksetup_part_beginning, "%s%c",
		pm->diskdev, bzb->flags.part);
	    errs++;
	}
	if ((map.blk[j].pmPyPartStart + map.blk[j].pmPartBlkCnt) > pm->dlsize) {
	    bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
	    msg_fmt_display_add(MSG_disksetup_part_size, "%s%c",
		pm->diskdev, bzb->flags.part);
	    errs++;
	}
    }
    if (!errs)
	msg_display_add(MSG_disksetup_noerrors);
    return;
}

static int
edit_diskmap(void)
{
    int i;

	/* Ask full/part */
	msg_fmt_display (MSG_mac68k_fullpart, "%s", pm->diskdev);
	process_menu (MENU_fullpart, NULL);

	map.selected = 0;
	sortmerge();

	/* If blowing away the whole disk, let user know if there
	 *  are any active disk partitions */
	if (usefull) {
	    if (map.usable_cnt > (map.root_cnt+map.swap_cnt+map.usr_cnt)) {
		msg_display (MSG_mac68k_ovrwrite);
		if (!ask_noyes(NULL)) {
			endwin();
			return 0;
		}
	    }
	    /*
	     * mark all non-reserved partitions as "free"
	     *  then sort and merge the map into something sensible
	     */
	    for (i=0;i<map.size;i++)
		if (whichType(&map.blk[i]))
		    strcpy ((char *)map.blk[i].pmPartType, "Apple_Free");
	    sortmerge();
	}
	process_menu (MENU_editparttable, NULL);
	return 1;
}

#ifdef MD_DEBUG_SORT_MERGE
static int
md_debug_dump(title)
	char *title;
{
	char buf[96], type;
	char fstyp[16], use[16], name[64];
	int i, j, rv;
	EBZB *bzb;

	msg_clear();
	sprintf(buf, "Apple Disk Partition Map: %s", title);
	msg_fmt_table_add(MSG_dump_line, "%s", buf);
	msg_fmt_table_add(MSG_dump_line, "%s",
           "slot      base   fstype        use name");
	for (i=0;i<map.in_use_cnt;i++) {
	   j = whichType(&map.blk[i]);
	   getFstype(&map.blk[i], sizeof(fstyp), fstyp);
	   getUse(&map.blk[i], sizeof(use), use);
	   getName(&map.blk[i], sizeof(name), name);
	   bzb = (EBZB *) &map.blk[i].pmBootArgs[0];
	   type = bzb->flags.part;
	   if (type < 'a' || type > 'h') type = '?';
	   if (j == 0) strcpy (name, "reserved for Apple");
           sprintf(buf, " %02d:%c %08x %8s %10s %s", i+1,  type,
		map.blk[i].pmPyPartStart, fstyp, use, name);
           msg_fmt_table_add(MSG_dump_line, "%s", buf);
	}
	process_menu(MENU_okabort, &rv);
	msg_clear();
	return rv;
}
#endif /* MD_DEBUG_SORT_MERGE */

int
md_pre_mount(struct install_partition_desc *install, size_t ndx)
{
	return 0;
}

bool
md_parts_use_wholedisk(struct disk_partitions *parts)
{
	return parts_use_wholedisk(parts, 0, NULL);
}

#ifdef HAVE_GPT
bool
md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
    bool root_is_new, part_id efi_id, bool efi_is_new)
{
	/* no GPT boot support, nothing needs to be done here */
	return true;
}
#endif