From nobody@FreeBSD.org  Mon Apr  8 23:54:43 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id D522E37B416
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Apr 2002 23:54:42 -0700 (PDT)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g396sgl04219;
	Mon, 8 Apr 2002 23:54:42 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200204090654.g396sgl04219@freefall.freebsd.org>
Date: Mon, 8 Apr 2002 23:54:42 -0700 (PDT)
From: David Xu <davidx@viasoft.com.cn>
To: freebsd-gnats-submit@FreeBSD.org
Subject: DOS active partition flag lost in libdisk and sysinstall
X-Send-Pr-Version: www-1.0

>Number:         36917
>Category:       misc
>Synopsis:       DOS active partition flag lost in libdisk and sysinstall
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 09 00:00:04 PDT 2002
>Closed-Date:    Tue Apr 09 02:58:33 PDT 2002
>Last-Modified:  Tue Apr 09 02:58:33 PDT 2002
>Originator:     David Xu
>Release:        FreeBSD 5.0-CURRENT
>Organization:
Viatech
>Environment:
FreeBSD davidbsd.viasoft.com.cn 5.0-CURRENT FreeBSD 5.0-CURRENT #9: Mon Apr  8 13:45:15 CST 2002     root@davidbsd.viasoft.com.cn:/usr/src/sys/i386/compile/xu  i386      
>Description:
When libdisk read DOS partition information from MBR, active partition
flag is lost. when sysinstall uses libdisk to read MBR partition information, it can not display active partition flag, if user is 
installing FreeBSD in multiple boot system, for example installing 
FreeBSD on a machine which already have Windows/NT installed, and if 
he don't install FreeBSD boot0 into MBR and keep using Windows/NT boot loader, sysinstall will write partition table without DOS active 
partition flag set, when Windows/NT boot loader runs, it will die
at "Invalid Partition". the problem occurs when newbie wants to 
install FreeBSD on there Windows/NT machine and forget to set active 
partition flag.


>How-To-Repeat:
      
>Fix:
--- /usr/src/lib/libdisk/disk.c.orig	Tue Apr  9 12:46:22 2002
+++ /usr/src/lib/libdisk/disk.c	Tue Apr  9 14:05:56 2002
@@ -132,7 +132,7 @@
 #else
 	p = read_block(fd, 0, sector_size);
 	dp = (struct dos_partition*)(p + DOSPARTOFF);
-	for (i = 0; i < NDOSPART; i++) {
+	for (i = 0; i < NDOSPART; i++, dp++) {
 		if (Read_Int32(&dp->dp_start) >= size)
 		    continue;
 		if (Read_Int32(&dp->dp_start) + Read_Int32(&dp->dp_size) >= size)
@@ -144,9 +144,7 @@
 			d->flags |= DISK_ON_TRACK;
 			offset = 63;
 		}
-
 	}
-	free(p);
 #endif
 
 	d->bios_sect = dl.d_nsectors;
@@ -178,11 +176,10 @@
 	    (*(p+1) == 0xff) &&
 	    (*(p+2) == 0xff)) {
 		Add_Chunk(d, 0, size, name, fat, 0xa0a0, 0, name);
-	    free(p);
 	    goto pc98_mo_done;
 	}
-	free(p);
 #endif /* PC98 */
+	dp = (struct dos_partition*)(p + DOSPARTOFF);
 	for(i=BASE_SLICE;i<ds.dss_nslices;i++) {
 		char sname[20];
 		chunk_e ce;
@@ -230,6 +227,9 @@
 				ce = unknown;
 				break;
 		}
+		if (i-BASE_SLICE < NDOSPART && 
+			dp[i-BASE_SLICE].dp_flag == 0x80)
+			flags |= CHUNK_ACTIVE; 
 #ifdef PC98
 		if (Add_Chunk(d, ds.dss_slices[i].ds_offset,
 			ds.dss_slices[i].ds_size, sname, ce, subtype, flags,
@@ -377,6 +377,7 @@
 #ifdef PC98
 pc98_mo_done:
 #endif
+	free(p);
 	close(fd);
 	Fixup_Names(d);
 	return d;


--- /usr/src/usr.sbin/sysinstall/disks.c.orig	Tue Apr  9 12:21:26 2002
+++ /usr/src/usr.sbin/sysinstall/disks.c	Tue Apr  9 14:08:02 2002
@@ -528,7 +528,10 @@
 	
 	case 'S':
 	    /* Set Bootable */
-	    chunk_info[current_chunk]->flags |= CHUNK_ACTIVE;
+	    if (chunk_info[current_chunk]->flags & CHUNK_ACTIVE)
+		chunk_info[current_chunk]->flags &= ~CHUNK_ACTIVE;
+	    else
+		chunk_info[current_chunk]->flags |= CHUNK_ACTIVE;
 	    break;
 	
 	case 'U':


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ceri 
State-Changed-When: Tue Apr 9 02:58:08 PDT 2002 
State-Changed-Why:  


Duplicate of misc/36916 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36917 
>Unformatted:
