Subject: kern/22774: there is no way to swapctl -a to a wrongly typed partition
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tv@pobox.com>
List: netbsd-bugs
Date: 09/13/2003 11:27:07
>Number:         22774
>Category:       kern
>Synopsis:       there is no way to swapctl -a to a wrongly typed partition
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 13 15:30:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Todd Vierling
>Release:        NetBSD 1.6.1_STABLE
>Organization:
	DUH.ORG:  Pointing out the obvious since 1994.
>Environment:
System: NetBSD server.duh.org 1.6.1_STABLE NetBSD 1.6.1_STABLE (SERVER) #1: Fri Sep 12 11:28:14 EDT 2003 tv@server.duh.org:/export/SRC/duh/netbsd-kernels/SERVER i386
Architecture: i386
Machine: i386
>Description:

Devices such as vnd, ccd, cgd provide fake disklabels with the raw
partition typed as "4.2BSD" to make it possible to newfs and mount the
devices without creating a real disklabel.  However, mount(2) isn't the
only thing that checks the partition type; swapctl(2) appears to do so as
well.

This makes it impossible to use cgd, ccd, etc. for encrypted or
interleave-striped swap purposes without somehow munging the faked
disklabel.  Problem is, the faked disklabel cannot be written to the disk,
since swap does not typically leave the disklabel space alone at the start
of the disk (unlike ffs).

>How-To-Repeat:

# cgdconfig -s cgd0 /dev/wd1e aes-cbc 192 </dev/urandom
# swapctl -a /dev/cgd0d
swapctl: /dev/cgd0d: Device not configured

...or...

# ccdconfig ccd0 /dev/wd1e
# swapctl -a /dev/ccd0d
swapctl: /dev/ccd0d: Device not configured

>Fix:

Two possibilities:

* Change cgd, ccd, and vnd to create a "b" fake partition that is also the
  whole disk but of type swap.  (vnd already creates a b partition, but of
  type 4.2BSD.)

* Add a "force" flag to swapctl(2) and matching command line option and
  fstab flag to allow swapctl to turn on swap to a wrongly typed partition.

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