misc/127759: Nanobsd.sh incorrectly calculates partition sizes

Cyrus Rahman crahman at gmail.com
Wed Oct 1 02:50:02 UTC 2008


>Number:         127759
>Category:       misc
>Synopsis:       Nanobsd.sh incorrectly calculates partition sizes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 01 02:50:02 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Cyrus Rahman
>Release:        7.1-PRERELEASE
>Organization:
>Environment:
FreeBSD silva.signetica.com 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #0: Thu Sep 25 23:49:02 MDT 2008     cr at silva.signetica.com:/usr/src/sys/amd64/compile/SIGNETICA  amd64

>Description:
It is possible to ask nanobsd.sh to create a 'data' partition, separate from the system or configuration partitions, and furthermore, by specifying a negative value for its size to request that it use all space unused by those partitions for its own size.

Because the two lines of code that calculate how much space is available for this data partition are written in perl-like syntax, the awk code that does the processing performs the calculation incorrectly.

Furthermore, a comparison later down fails to newfs the partition when the size is negative.

>How-To-Repeat:
Run nanobsd.sh with NANO_DATASIZE set to a negative value.
>Fix:
Apply the attached patch, also listed herein:

--- /u/cr/sys/freebsd/nanobsd/nanobsd.sh        2008-09-29 20:59:44.000000000 -0600
+++ nanobsd.sh  2008-09-30 06:12:29.000000000 -0600
@@ -376,8 +376,8 @@
                # Data partition (if any) starts at cylinder boundary.
                if ($7 > 0) {
                        print "p 4 165 " c, dsl * cs
-               } else if ($7 < 0 && $1 > $c) {
-                       print "p 4 165 " c, $1 - $c
+               } else if ($7 < 0 && $1 > c) {
+                       print "p 4 165 " c, $1 - c
                } else if ($1 < c) {
                        print "Disk space overcommitted by", \
                            c - $1, "sectors" > "/dev/stderr"
@@ -432,7 +432,7 @@
        # XXX: fill from where ?
 
        # Create Data slice, if any.
-       if [ $NANO_DATASIZE -gt 0 ] ; then
+       if [ $NANO_DATASIZE -ne 0 ] ; then
                newfs ${NANO_NEWFS} /dev/${MD}s4
                # XXX: fill from where ?
        fi


Patch attached with submission follows:

--- /u/cr/sys/freebsd/nanobsd/nanobsd.sh	2008-09-29 20:59:44.000000000 -0600
+++ nanobsd.sh	2008-09-30 06:12:29.000000000 -0600
@@ -376,8 +376,8 @@
 		# Data partition (if any) starts at cylinder boundary.
 		if ($7 > 0) {
 			print "p 4 165 " c, dsl * cs
-		} else if ($7 < 0 && $1 > $c) {
-			print "p 4 165 " c, $1 - $c
+		} else if ($7 < 0 && $1 > c) {
+			print "p 4 165 " c, $1 - c
 		} else if ($1 < c) {
 			print "Disk space overcommitted by", \
 			    c - $1, "sectors" > "/dev/stderr"
@@ -432,7 +432,7 @@
 	# XXX: fill from where ?
 
 	# Create Data slice, if any.
-	if [ $NANO_DATASIZE -gt 0 ] ; then
+	if [ $NANO_DATASIZE -ne 0 ] ; then
 		newfs ${NANO_NEWFS} /dev/${MD}s4
 		# XXX: fill from where ?
 	fi


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list