Subject: kern/21723: dk_size() fails with no disklabel - should special-case RAW_PART
To: None <>
From: Alan Barrett <>
List: netbsd-bugs
Date: 05/30/2003 23:14:14
>Number:         21723
>Category:       kern
>Synopsis:       dk_size() fails with no disklabel - should special-case RAW_PART
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 30 21:15:00 UTC 2003
>Originator:     Alan Barrett
>Release:        NetBSD 1.6T
Not much
/* $NetBSD: dksubr.c,v 1.7 2003/05/12 00:19:00 atatat Exp $ */
The dk_size() function in sys/dev/dksubr.c is apparently intended to
return the size of a disk partition.  It seems reasonable to expect it
to work when passed the raw partition of a disk without a label, but it

This failure makes it impossible to swap to the raw partition on a "cgd"
device that does not have a disklabel.  I assume that it will also
prevent similar operations on other kinds of devices.

0. Decide to use /dev/wd0e as an encrypted swap partition
   via a cgd layer.

1. Create a cgd paramsfile as follows:

	# cgdconfig -g -k random -o /etc/cgd/wd0e aes-cbc 192

2. Configure a cgd layer (cgd0) on top of wd0e using the paramsfile:

	# cgdconfig /dev/cgd0 /dev/wd0e /etc/cgd/wd0e

3. Try to enable /dev/cgd0d as a swap partition.  
   (Note that "d" is teh raw partition in NetBSD/i386.)

	# swapctl -a /dev/cgd0d
	swapctl: /dev/cgd0d: Device not configured

Apply this patch:

--- sys/dev/dksubr.c	12 May 2003 00:19:00 -0000	1.7
+++ sys/dev/dksubr.c	27 May 2003 15:29:41 -0000
@@ -221,6 +221,9 @@
 		return -1;
 	part = DISKPART(dev);
+	if (part == RAW_PART)
+		return dksc->sc_size;
 	is_open = dksc->sc_dkdev.dk_openmask & (1 << part);
 	if (!is_open && di->di_open(dev, 0, S_IFBLK, curproc))