Subject: sysinst fix
To: port-mac68k <port-mac68k@NetBSD.ORG>
From: Bob Nestor <rnestor@augustmail.com>
List: port-mac68k
Date: 06/15/2002 06:52:07
--Apple-Mail-2-737570966
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

I tried to send this out yesterday but it doesn't appear to have made it 
so I'll try again today.  My apologies if this is a duplicate message.

---------------
Some users have reported problems with sysinst/mac68k when the disk 
partitioning feature is used.  Disk corruption can occur on HFS 
partitions or NetBSD partitions can be incorrectly identified and 
mounted during the installation.  I've been able to reproduce these 
problems and have a fix that appears to work on my system.  I'd 
appreciate it if these changes can be tested by others since I'm sure I 
haven't found all the ways people use sysinst during partitioning.

To test these you'll have to build a new Installation kernel with 
sysinst.  If you have multiple disks on your system you can just build 
and install a new Kernel with the updated disksubr and then build and 
run sysinst as an application.  Please let me know if you find problems.

BTW, these changes were made on -current source and tested on a 
1.6_Beta1 system.

-bob


--Apple-Mail-2-737570966
Content-Disposition: attachment;
	filename=sysinst-patches
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="sysinst-patches"

>>>> src/sys/arch/mac68k/mac68k/disksubr.c

*** disksubr.c	Fri Jun 14 18:41:32 2002
--- disksubr.c_orig	Fri Jun 14 18:09:48 2002
*************** writedisklabel(dev, strat, lp, osdep)
*** 554,560 ****
  	struct disklabel *lp;
  	struct cpu_disklabel *osdep;
  {
- 	int i;
  #if 0
  	struct buf *bp;
  	struct disklabel *dlp;
--- 554,559 ----
*************** done:
*** 602,616 ****
  	 * causes the DIOCWDINFO ioctl invoked by sysinst to update the
  	 * in-core disk label when it is "written" to disk.
  	 * This code was originally developed by Bob Nestor on 9/13/99.
- 	 * Make sure the entries are unused and have zero size so they
- 	 * will be reused on the rescan.
  	 */
- 	lp->d_npartitions = 0;
- 	for (i=0; i < MAXPARTITIONS; i++) {
- 	    lp->d_partitions[i].p_fstype = FS_UNUSED;
- 	    lp->d_partitions[i].p_offset = 0;
- 	    lp->d_partitions[i].p_size = 0;
- 	}
  	return (readdisklabel(dev, strat, lp, osdep) ? EINVAL : 0);
  #endif
  }
--- 601,607 ----

>>>> src/distrib/utils/sysinst/arch/mac68k/md.c

*** md.c	Fri Jun 14 18:58:19 2002
--- md.c_orig	Fri Jun 14 18:14:40 2002
*************** PTYPES ptypes[] = {
*** 85,108 ****
  
  /*
   * Order of the BSD disk parts as they are assigned in the mac68k port
-  *   'a' is reserved for Root
-  *   'b' is reserved for SWAP
-  *   'c' is reserved for raw disk
-  *   'd' is unused in mac68k port, reserved for raw disk in other ports
-  *   'g' is available for Usr
-  *   'e', 'f', and 'h' are available for additional Usr type parts
-  *
-  * XXX this must agree with the algorithm in mac68k/disksubr.c
-  */
- char bsd_order[] = {'g', 'e', 'f', 'h'};
- /*
-  * Order of the MacOS disk parts as they are assigned in the mac68k port
-  *   'b' is assumed used by NetBSD to map SWAP
-  *   'c' is assumed used by NetBSD to map raw disk
-  *   Remaining unassigned slots are used for HFS/HFS+ partitions
-  *
-  * XXX this must agree with the algorithm in mac68k/disksubr.c
   */
  char macos_order[] = {'a', 'd', 'e', 'f', 'g', 'h'};
  
  /*
--- 85,92 ----
  
  /*
   * Order of the BSD disk parts as they are assigned in the mac68k port
   */
+ char bsd_order[] = {'g', 'd', 'e', 'f', 'h'};
  char macos_order[] = {'a', 'd', 'e', 'f', 'g', 'h'};
  
  /*
*************** sortmerge(void)
*** 279,289 ****
  			    bzb->flags.part = 'a';
                              strcpy (bzb->mount_point, "/");
  			}
! 			else if (bzb->flags.root || bzb->flags.usr) {
  			    bzb->flags.part = bsd_order[map.usr_cnt++];
- 			    if (map.usr_cnt > sizeof(bsd_order))
- 				map.usr_cnt = sizeof(bsd_order);
- 			}
  			break;
  		    case BZB_TYPESWAP:
  			if (!map.swap_cnt)
--- 263,270 ----
  			    bzb->flags.part = 'a';
                              strcpy (bzb->mount_point, "/");
  			}
! 			else if (bzb->flags.root || bzb->flags.usr)
  			    bzb->flags.part = bsd_order[map.usr_cnt++];
  			break;
  		    case BZB_TYPESWAP:
  			if (!map.swap_cnt)
*************** sortmerge(void)
*** 307,314 ****
  	    if (j == TYP_AVAIL || j == TYP_HFS) {
  		bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
  		bzb->flags.part = macos_order[k++];
- 		if (k > sizeof(macos_order))
- 		    k = sizeof(macos_order);
                  if (j == TYP_HFS)
                     map.hfs_cnt += 1;
  	    }
--- 288,293 ----
*************** md_get_info()
*** 572,578 ****
  	}
  	/*
  	 * Get the disk parameters from the disk driver.  It should have
! 	 *  obtained them by querying the disk itself.
  	 */
  	bsize = disklabel.d_secsize;
  	dlcyl = disklabel.d_ncylinders;
--- 551,557 ----
  	}
  	/*
  	 * Get the disk parameters from the disk driver.  It should have
! 	 *  obained them by querying the disk itself.
  	 */
  	bsize = disklabel.d_secsize;
  	dlcyl = disklabel.d_ncylinders;
*************** md_get_info()
*** 582,588 ****
  	 * Just in case, initialize the structures we'll need if we
  	 *  need to completely initialize the disk.
  	 */
! 	dlsize = disklabel.d_secperunit;  /* dlsec*dlhead*dlcyl; */
  	new_block0.sbBlkCount = dlsize;
  	for (i=0;i<NEW_MAP_SIZE;i++) {
  	   if (i > 0)
--- 561,567 ----
  	 * Just in case, initialize the structures we'll need if we
  	 *  need to completely initialize the disk.
  	 */
! 	dlsize = dlsec*dlhead*dlcyl;
  	new_block0.sbBlkCount = dlsize;
  	for (i=0;i<NEW_MAP_SIZE;i++) {
  	   if (i > 0)
*************** md_get_info()
*** 596,602 ****
  	   }
  	   dlsize -= new_map[i].pmPartBlkCnt;
  	}
! 	dlsize = disklabel.d_secperunit;  /* dlsec*dlhead*dlcyl; */
  #if 0
  	msg_display(MSG_dldebug, bsize, dlcyl, dlhead, dlsec, dlsize);
  	process_menu(MENU_ok);
--- 575,581 ----
  	   }
  	   dlsize -= new_map[i].pmPartBlkCnt;
  	}
! 	dlsize = dlsec*dlhead*dlcyl;
  #if 0
  	msg_display(MSG_dldebug, bsize, dlcyl, dlhead, dlsec, dlsize);
  	process_menu(MENU_ok);
*************** md_pre_disklabel()
*** 703,709 ****
  	close (fd);
  	exit (1);
      }
-     fsync(fd);
      /*
       * Well, if we get here the dirty deed has been done.
       *
--- 682,687 ----
*************** md_pre_disklabel()
*** 736,799 ****
  int
  md_post_disklabel(void)
  {
!     struct disklabel updated_label;
!     int fd, i, no_match;
!     char devname[100], buf[80];
!     char *fst[] = {"free", "swap", " v6 ", " v7 ", "sysv", "v71k",
! 		   " v8 ", "ffs ", "dos ", "lfs ", "othr", "hpfs",
! 		   "9660", "boot", "ados", "hfs ", "fcor", "ex2f",
! 		   "ntfs", "raid", "ccd "};
!    
!     snprintf(devname, sizeof(devname), "/dev/r%sc", diskdev);
!     /*
!      * Open the disk as a raw device
!      */
!     if ((fd = open(devname, O_RDONLY, 0)) < 0)
!        return 0;
!     /*
!      * Get the "new" label to see if we were successful.  If we we're
!      *  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 (bsdlabel[i].pi_size != updated_label.d_partitions[i].p_size)
!            no_match = 1;
!         if (bsdlabel[i].pi_size) {
!            if (bsdlabel[i].pi_offset != updated_label.d_partitions[i].p_offset)
!                no_match = 1;
!            if (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_table_add(MSG_dump_line,
!            " in-core: offset      size type on-disk: offset      size type");
!        for (i=0;i<MAXPARTITIONS;i++) {
!            sprintf(buf, " %c:%13.8x%10.8x%5s%16.8x%10.8x%5s", i+'a',
!               bsdlabel[i].pi_offset, bsdlabel[i].pi_size,
!               fst[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_table_add(MSG_dump_line, buf);
!        }
!        process_menu(MENU_ok2);
!     }
!     return no_match;
  }
  
  int
--- 714,720 ----
  int
  md_post_disklabel(void)
  {
! 	return 0;
  }
  
  int
*************** md_make_bsd_partitions(void)
*** 852,859 ****
  	emptylabel(bsdlabel);
  
  	/*
! 	 * The mac68k port has a predefined partition for "c" which
! 	 *  is the size of the disk, everything else is unused.
  	 */
  	for (i=0;i<MAXPARTITIONS;i++) {
  	    bsdlabel[i].pi_size = 0;
--- 773,780 ----
  	emptylabel(bsdlabel);
  
  	/*
! 	 * The mac68k port has no predefined partitions, so we'll
! 	 *  start by setting everything to unused.
  	 */
  	for (i=0;i<MAXPARTITIONS;i++) {
  	    bsdlabel[i].pi_size = 0;
*************** md_make_bsd_partitions(void)
*** 863,869 ****
  	    bsdlabel[i].pi_fsize = 0;
  	    fsmount[i][0] = '\0';
  	}
- 	bsdlabel[2].pi_size = new_block0.sbBlkCount;
  	/*
  	 * Now, scan through the Disk Partition Map and transfer the
  	 *  information into the incore disklabel.
--- 784,789 ----

>>>> src/distrib/utils/sysinst/arch/mac68k/menus.md.en

*** menus.md.en	Fri Jun 14 18:18:24 2002
--- menus.md.en_orig	Fri Jun 14 18:14:39 2002
*************** menu editparttable, title  "Choose your 
*** 143,151 ****
                  };
  
  
- menu ok2, title "Abort?", y=17;
-        option "OK", exit, action { };
- 
  menu okabort, title "What do you want to do?";
  	option "OK", exit, action { yesno = 1; };
  	option "Abort install", exit, action { yesno = 0; };
--- 143,148 ----

>>>> src/distrib/utils/sysinst/arch/mac68k/menus.md.pl

*** menus.md.pl	Fri Jun 14 18:18:28 2002
--- menus.md.pl_orig	Fri Jun 14 18:14:39 2002
*************** menu editparttable, title  "Wybierz swoj
*** 144,151 ****
                  process_menu(MENU_ok);
                  };
  
! menu ok2, title "Przerwac?", y=17;
! 	option "OK", exit, action { };
  
  menu okabort, title "Co chcesz zrobic?";
         option "OK", exit, action { yesno = 1; };
--- 144,151 ----
                  process_menu(MENU_ok);
                  };
  
! 
! 
  
  menu okabort, title "Co chcesz zrobic?";
         option "OK", exit, action { yesno = 1; };

>>>> src/distrib/utils/sysinst/arch/mac68k/msg.md.en

*** msg.md.en	Wed Jun 12 16:01:45 2002
--- msg.md.en_orig	Fri Jun 14 18:14:39 2002
*************** message dodiskmap
*** 157,170 ****
  {Setting up the Disk Partition Map ...
  }
  
- message label_error
- {The new on-disk partition label does not match the one currently in-core.
- Any attempt to proceed will most likely result in damage to any pre-existing
- disk partitions, although your new Disk Partition Map has been written to
- the disk and will be available as soon as this program terminates. If you 
- wish to continue with the installation at this time, then completely exit  
- sysinst via the menus, and re-invoke it via "./sysinst".\n}
-  
  message mapdebug
  {Partition Map:
  HFS count: %d
--- 157,162 ----
*************** message parttable_fix_fixing
*** 227,232 ****
  
  message parttable_fix_fine
  {Partition %s%c is just fine!\n}
-  
- message dump_line
- {%s\n}
--- 219,221 ----

>>>> src/distrib/utils/sysinst/arch/mac68k/msg.md.pl

*** msg.md.pl	Fri Jun 14 18:20:35 2002
--- msg.md.pl_orig	Fri Jun 14 18:14:40 2002
*************** message dodiskmap
*** 157,170 ****
  {Konfigurowanie Mapy Partycji Dysku ...
  }
  
- message label_error
- {The new on-disk partition label does not match the one currently in-core.
- Any attempt to proceed will most likely result in damage to any pre-existing
- disk partitions, although your new Disk Partition Map has been written to
- the disk and will be available as soon as this program terminates. If you 
- wish to continue with the installation at this time, then completely exit  
- sysinst via the menus, and re-invoke it via "./sysinst".\n}
- 
  message mapdebug
  {Mapa partycji:
  HFS count: %d
--- 157,162 ----
*************** message parttable_fix_fixing
*** 227,232 ****
  
  message parttable_fix_fine
  {Partycja %s%c jest w porzadku!\n}
- 
- message dump_line
- {%s\n}
--- 219,221 ----

--Apple-Mail-2-737570966--