From nobody@FreeBSD.org  Mon Apr  8 23:47:53 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 EF1C037B400
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Apr 2002 23:47:52 -0700 (PDT)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g396lqa03072;
	Mon, 8 Apr 2002 23:47:52 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200204090647.g396lqa03072@freefall.freebsd.org>
Date: Mon, 8 Apr 2002 23:47:52 -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:         36916
>Category:       kern
>Synopsis:       [libdisk] [patch] DOS active partition flag lost in libdisk and sysinstall
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-sysinstall
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 08 23:50:01 PDT 2002
>Closed-Date:    
>Last-Modified:  Sat Jun 29 05:53:22 UTC 2013
>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:
Responsible-Changed-From-To: freebsd-bugs->qa 
Responsible-Changed-By: kris 
Responsible-Changed-When: Fri Jul 18 15:54:51 PDT 2003 
Responsible-Changed-Why:  
Assign to qa team 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36916 
Responsible-Changed-From-To: freebsd-bugs->randi 
Responsible-Changed-By: randi 
Responsible-Changed-When: Sat Jun 6 19:43:33 UTC 2009 
Responsible-Changed-Why:  
Quite a few duplicates for this issue, but this is the first one to provide a patch. :) I'll look into this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36916 
Responsible-Changed-From-To: randi->freebsd-sysinstall 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Jun 29 05:52:04 UTC 2013 
Responsible-Changed-Why:  
back to mailing list. 

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