From ba0cc1abb302756c40039a3d98f8df159cc05766 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 17 Jun 2007 23:50:16 +0000 Subject: [PATCH] Disklabel separation work - Generally shift all disklabel-specific procedures for the kernel proper to a new source file, subr_disklabel32.c. Move the DTYPE_ and FS_ defines out of sys/disklabel.h and into a new header files sys/dtype.h Make adjustments to the uuids file, renaming "DragonFly Label" to "DragonFly Label32" and creating a "DragonFly Label64" uuid. --- etc/defaults/uuids | 6 +- lib/libc/gen/disklabel.c | 3 +- lib/libc/gen/disktab.c | 3 +- sbin/diskinfo/diskinfo.c | 4 +- sbin/disklabel/disklabel.c | 3 +- sbin/gpt/add.c | 6 +- sbin/gpt/gpt.c | 4 +- sbin/gpt/migrate.c | 3 +- sbin/vinum/list.c | 3 +- sys/boot/efi/libefi/devicename.c | 3 +- sys/boot/pc32/boot2/boot2.c | 3 +- sys/boot/pc32/libi386/biosdisk.c | 3 +- sys/dev/disk/ccd/ccd.c | 5 +- sys/dev/disk/fd/fd.c | 3 +- sys/dev/raid/aac/aac_disk.c | 3 +- sys/dev/raid/amr/amr_disk.c | 3 +- sys/dev/raid/ida/ida_disk.c | 3 +- sys/dev/raid/ips/ips_disk.c | 3 +- sys/dev/raid/mlx/mlx_disk.c | 3 +- sys/dev/raid/twe/twe_freebsd.c | 3 +- sys/dev/raid/vinum/vinumhdr.h | 4 +- sys/kern/subr_disk.c | 161 +------- sys/kern/subr_disklabel32.c | 589 +++++++++++++++++++++++++++ sys/kern/subr_disklabel64.c | 45 ++ sys/kern/subr_diskslice.c | 390 ++---------------- sys/kern/vfs_conf.c | 3 +- sys/platform/pc32/i386/autoconf.c | 17 +- sys/platform/vkernel/i386/autoconf.c | 3 +- sys/sys/disk.h | 5 +- sys/sys/disklabel.h | 110 +---- sys/sys/disklabel32.h | 110 +---- sys/sys/dtype.h | 137 +++++++ 32 files changed, 890 insertions(+), 754 deletions(-) create mode 100644 sys/kern/subr_disklabel32.c create mode 100644 sys/kern/subr_disklabel64.c create mode 100644 sys/sys/dtype.h diff --git a/etc/defaults/uuids b/etc/defaults/uuids index 965cfcc5d5..a2e6d83465 100644 --- a/etc/defaults/uuids +++ b/etc/defaults/uuids @@ -1,4 +1,4 @@ -# $DragonFly: src/etc/defaults/uuids,v 1.1 2007/06/17 08:17:11 dillon Exp $ +# $DragonFly: src/etc/defaults/uuids,v 1.2 2007/06/17 23:50:11 dillon Exp $ # # # EFI @@ -9,11 +9,13 @@ c12a7328-f81f-11d2-ba4b-00a0c93ec93b "EFI System" # # DragonFly # -9d087404-1ca5-11dc-8817-01301bb8a9f5 "DragonFly Label" +9d087404-1ca5-11dc-8817-01301bb8a9f5 "DragonFly Label32" 9d58fdbd-1ca5-11dc-8817-01301bb8a9f5 "DragonFly Swap" 9d94ce7c-1ca5-11dc-8817-01301bb8a9f5 "DragonFly UFS1" 9dd4478f-1ca5-11dc-8817-01301bb8a9f5 "DragonFly Vinum" dbd5211b-1ca5-11dc-8817-01301bb8a9f5 "DragonFly CCD" +3d48ce54-1d16-11dc-8696-01301bb8a9f5 "DragonFly Label64" +bd215ab2-1d16-11dc-8696-01301bb8a9f5 "DragonFly Legacy" # # FreeBSD # diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c index 077732c41e..391e83595b 100644 --- a/lib/libc/gen/disklabel.c +++ b/lib/libc/gen/disklabel.c @@ -32,12 +32,13 @@ * * @(#)disklabel.c 8.2 (Berkeley) 5/3/95 * $FreeBSD: src/lib/libc/gen/disklabel.c,v 1.9.2.1 2001/03/05 08:40:47 obrien Exp $ - * $DragonFly: src/lib/libc/gen/disklabel.c,v 1.11 2007/05/19 00:51:56 dillon Exp $ + * $DragonFly: src/lib/libc/gen/disklabel.c,v 1.12 2007/06/17 23:50:13 dillon Exp $ */ #include #define DKTYPENAMES #include +#include #include #include diff --git a/lib/libc/gen/disktab.c b/lib/libc/gen/disktab.c index 5fefa0982b..00c4087e19 100644 --- a/lib/libc/gen/disktab.c +++ b/lib/libc/gen/disktab.c @@ -64,7 +64,7 @@ * SUCH DAMAGE. */ /* - * $DragonFly: src/lib/libc/gen/disktab.c,v 1.10 2007/05/17 23:50:00 dillon Exp $ + * $DragonFly: src/lib/libc/gen/disktab.c,v 1.11 2007/06/17 23:50:13 dillon Exp $ * @(#)disklabel.c 8.2 (Berkeley) 5/3/95 * $FreeBSD: src/lib/libc/gen/disklabel.c,v 1.9.2.1 2001/03/05 08:40:47 obrien */ @@ -72,6 +72,7 @@ #include #define DKTYPENAMES #include +#include #include #include diff --git a/sbin/diskinfo/diskinfo.c b/sbin/diskinfo/diskinfo.c index bd11c24c94..920f7e76e2 100644 --- a/sbin/diskinfo/diskinfo.c +++ b/sbin/diskinfo/diskinfo.c @@ -31,13 +31,13 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/diskinfo/diskinfo.c,v 1.3 2007/06/17 03:51:12 dillon Exp $ + * $DragonFly: src/sbin/diskinfo/diskinfo.c,v 1.4 2007/06/17 23:50:15 dillon Exp $ */ #define DKTYPENAMES #include #include -#include +#include #include #include #include diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 1c65911994..e56a67c0a8 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -37,7 +37,7 @@ * @(#)disklabel.c 1.2 (Symmetric) 11/28/85 * @(#)disklabel.c 8.2 (Berkeley) 1/7/94 * $FreeBSD: src/sbin/disklabel/disklabel.c,v 1.28.2.15 2003/01/24 16:18:16 des Exp $ - * $DragonFly: src/sbin/disklabel/disklabel.c,v 1.19 2007/06/17 03:51:13 dillon Exp $ + * $DragonFly: src/sbin/disklabel/disklabel.c,v 1.20 2007/06/17 23:50:15 dillon Exp $ */ #include @@ -48,6 +48,7 @@ #include #include #include +#include #include #include diff --git a/sbin/gpt/add.c b/sbin/gpt/add.c index 8aaa4d98f7..cc01ef2a3a 100644 --- a/sbin/gpt/add.c +++ b/sbin/gpt/add.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sbin/gpt/add.c,v 1.15 2006/10/04 18:20:25 marcel Exp $ - * $DragonFly: src/sbin/gpt/add.c,v 1.3 2007/06/17 08:34:59 dillon Exp $ + * $DragonFly: src/sbin/gpt/add.c,v 1.4 2007/06/17 23:50:15 dillon Exp $ */ #include @@ -196,11 +196,11 @@ cmd_add(int argc, char *argv[]) if (argc == optind) usage_add(); - /* Create UFS partitions by default. */ + /* Create DragonFly 64 bit label partitions by default. */ if (uuid_is_nil(&type, NULL)) { uint32_t status; - uuid_name_lookup(&type, "DragonFly Label", &status); + uuid_name_lookup(&type, "DragonFly Label64", &status); if (status != uuid_s_ok) usage_add(); } diff --git a/sbin/gpt/gpt.c b/sbin/gpt/gpt.c index b2f5bc8afb..26fb20ddff 100644 --- a/sbin/gpt/gpt.c +++ b/sbin/gpt/gpt.c @@ -26,7 +26,7 @@ * CRC32 code derived from work by Gary S. Brown. * * $FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $ - * $DragonFly: src/sbin/gpt/gpt.c,v 1.3 2007/06/17 08:34:59 dillon Exp $ + * $DragonFly: src/sbin/gpt/gpt.c,v 1.4 2007/06/17 23:50:15 dillon Exp $ */ #include @@ -272,7 +272,7 @@ parse_uuid(const char *s, uuid_t *uuid) switch (*s) { case 'd': if (strcmp(s, "dfly") == 0 || strcmp(s, "dragonfly") == 0) { - s = "DragonFly Label"; + s = "DragonFly Label64"; /* fall through to lookup at end */ } break; diff --git a/sbin/gpt/migrate.c b/sbin/gpt/migrate.c index 456ca329e4..772ba7162c 100644 --- a/sbin/gpt/migrate.c +++ b/sbin/gpt/migrate.c @@ -24,11 +24,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sbin/gpt/migrate.c,v 1.16 2005/09/01 02:42:52 marcel Exp $ - * $DragonFly: src/sbin/gpt/migrate.c,v 1.1 2007/06/16 22:29:27 dillon Exp $ + * $DragonFly: src/sbin/gpt/migrate.c,v 1.2 2007/06/17 23:50:15 dillon Exp $ */ #include #include +#include #include #include diff --git a/sbin/vinum/list.c b/sbin/vinum/list.c index 2cd8820747..1a12e0785a 100644 --- a/sbin/vinum/list.c +++ b/sbin/vinum/list.c @@ -37,7 +37,7 @@ * * $Id: list.c,v 1.25 2000/12/20 03:38:43 grog Exp grog $ * $FreeBSD: src/sbin/vinum/list.c,v 1.25.2.4 2001/05/28 05:58:04 grog Exp $ - * $DragonFly: src/sbin/vinum/list.c,v 1.8 2007/06/07 22:57:49 corecode Exp $ + * $DragonFly: src/sbin/vinum/list.c,v 1.9 2007/06/17 23:50:15 dillon Exp $ */ #define _KERNEL_STRUCTURES @@ -55,6 +55,7 @@ #include #include #include +#include #include #include "vext.h" #include diff --git a/sys/boot/efi/libefi/devicename.c b/sys/boot/efi/libefi/devicename.c index 7833282185..504d41d1e5 100644 --- a/sys/boot/efi/libefi/devicename.c +++ b/sys/boot/efi/libefi/devicename.c @@ -24,12 +24,11 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/boot/efi/libefi/devicename.c,v 1.2 2001/09/07 08:49:47 dfr Exp $ - * $DragonFly: src/sys/boot/efi/libefi/devicename.c,v 1.1 2003/11/10 06:08:33 dillon Exp $ + * $DragonFly: src/sys/boot/efi/libefi/devicename.c,v 1.2 2007/06/17 23:50:15 dillon Exp $ */ #include #include -#include #include "bootstrap.h" #include diff --git a/sys/boot/pc32/boot2/boot2.c b/sys/boot/pc32/boot2/boot2.c index 9cd56fd5ee..d727c171d1 100644 --- a/sys/boot/pc32/boot2/boot2.c +++ b/sys/boot/pc32/boot2/boot2.c @@ -45,12 +45,13 @@ * purpose. * * $FreeBSD: src/sys/boot/i386/boot2/boot2.c,v 1.64 2003/08/25 23:28:31 obrien Exp $ - * $DragonFly: src/sys/boot/pc32/boot2/boot2.c,v 1.14 2005/05/25 06:22:22 y0netan1 Exp $ + * $DragonFly: src/sys/boot/pc32/boot2/boot2.c,v 1.15 2007/06/17 23:50:15 dillon Exp $ */ #include #include #include #include +#include #include #include #include diff --git a/sys/boot/pc32/libi386/biosdisk.c b/sys/boot/pc32/libi386/biosdisk.c index 229e8118e7..ff114fb2d9 100644 --- a/sys/boot/pc32/libi386/biosdisk.c +++ b/sys/boot/pc32/libi386/biosdisk.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/boot/i386/libi386/biosdisk.c,v 1.45 2004/09/21 06:46:44 wes Exp $ - * $DragonFly: src/sys/boot/pc32/libi386/biosdisk.c,v 1.10 2006/09/10 01:26:31 dillon Exp $ + * $DragonFly: src/sys/boot/pc32/libi386/biosdisk.c,v 1.11 2007/06/17 23:50:15 dillon Exp $ */ /* @@ -41,6 +41,7 @@ #include #include +#include #include #include diff --git a/sys/dev/disk/ccd/ccd.c b/sys/dev/disk/ccd/ccd.c index ce18d990d3..143fe63c0b 100644 --- a/sys/dev/disk/ccd/ccd.c +++ b/sys/dev/disk/ccd/ccd.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.45 2007/06/17 03:51:14 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.46 2007/06/17 23:50:15 dillon Exp $ */ /* * Copyright (c) 1995 Jason R. Thorpe. @@ -108,7 +108,7 @@ * @(#)cd.c 8.2 (Berkeley) 11/16/93 * $FreeBSD: src/sys/dev/ccd/ccd.c,v 1.73.2.1 2001/09/11 09:49:52 kris Exp $ * $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $ - * $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.45 2007/06/17 03:51:14 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.46 2007/06/17 23:50:15 dillon Exp $ */ /* @@ -136,6 +136,7 @@ #include #include #include +#include #include #include #include diff --git a/sys/dev/disk/fd/fd.c b/sys/dev/disk/fd/fd.c index 4600de9656..0e5f4719a8 100644 --- a/sys/dev/disk/fd/fd.c +++ b/sys/dev/disk/fd/fd.c @@ -51,7 +51,7 @@ * * from: @(#)fd.c 7.4 (Berkeley) 5/25/91 * $FreeBSD: src/sys/isa/fd.c,v 1.176.2.8 2002/05/15 21:56:14 joerg Exp $ - * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.39 2007/05/21 04:22:23 dillon Exp $ + * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.40 2007/06/17 23:50:15 dillon Exp $ * */ @@ -65,7 +65,6 @@ #include #include #include -#include #include #include #include diff --git a/sys/dev/raid/aac/aac_disk.c b/sys/dev/raid/aac/aac_disk.c index ff542c4f1f..5bc750790f 100644 --- a/sys/dev/raid/aac/aac_disk.c +++ b/sys/dev/raid/aac/aac_disk.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aac/aac_disk.c,v 1.3.2.8 2003/01/11 18:39:39 scottl Exp $ - * $DragonFly: src/sys/dev/raid/aac/aac_disk.c,v 1.17 2007/05/15 00:01:04 dillon Exp $ + * $DragonFly: src/sys/dev/raid/aac/aac_disk.c,v 1.18 2007/06/17 23:50:16 dillon Exp $ */ #include "opt_aac.h" @@ -42,6 +42,7 @@ #include #include #include +#include #include #include diff --git a/sys/dev/raid/amr/amr_disk.c b/sys/dev/raid/amr/amr_disk.c index e62e9d1fc8..0bf0fedbbd 100644 --- a/sys/dev/raid/amr/amr_disk.c +++ b/sys/dev/raid/amr/amr_disk.c @@ -54,7 +54,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/amr/amr_disk.c,v 1.5.2.5 2002/12/20 15:12:04 emoore Exp $ - * $DragonFly: src/sys/dev/raid/amr/amr_disk.c,v 1.14 2007/05/15 00:01:04 dillon Exp $ + * $DragonFly: src/sys/dev/raid/amr/amr_disk.c,v 1.15 2007/06/17 23:50:16 dillon Exp $ */ /* @@ -70,6 +70,7 @@ #include #include #include +#include #include #include diff --git a/sys/dev/raid/ida/ida_disk.c b/sys/dev/raid/ida/ida_disk.c index 3a2fc20919..ad74225b75 100644 --- a/sys/dev/raid/ida/ida_disk.c +++ b/sys/dev/raid/ida/ida_disk.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ida/ida_disk.c,v 1.12.2.6 2001/11/27 20:21:02 ps Exp $ - * $DragonFly: src/sys/dev/raid/ida/ida_disk.c,v 1.15 2007/05/15 00:01:04 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ida/ida_disk.c,v 1.16 2007/06/17 23:50:16 dillon Exp $ */ /* @@ -42,6 +42,7 @@ #include #include #include +#include #include #include diff --git a/sys/dev/raid/ips/ips_disk.c b/sys/dev/raid/ips/ips_disk.c index ae281c96cd..a8705954a7 100644 --- a/sys/dev/raid/ips/ips_disk.c +++ b/sys/dev/raid/ips/ips_disk.c @@ -25,13 +25,14 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips_disk.c,v 1.4 2003/09/22 04:59:07 njl Exp $ - * $DragonFly: src/sys/dev/raid/ips/ips_disk.c,v 1.12 2007/05/15 00:01:04 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips_disk.c,v 1.13 2007/06/17 23:50:16 dillon Exp $ */ #include #include #include #include +#include #include #include diff --git a/sys/dev/raid/mlx/mlx_disk.c b/sys/dev/raid/mlx/mlx_disk.c index ae801d8efe..b7d06baafa 100644 --- a/sys/dev/raid/mlx/mlx_disk.c +++ b/sys/dev/raid/mlx/mlx_disk.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/mlx/mlx_disk.c,v 1.8.2.4 2001/06/25 04:37:51 msmith Exp $ - * $DragonFly: src/sys/dev/raid/mlx/mlx_disk.c,v 1.12 2007/05/15 00:01:04 dillon Exp $ + * $DragonFly: src/sys/dev/raid/mlx/mlx_disk.c,v 1.13 2007/06/17 23:50:16 dillon Exp $ */ /* @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "mlx_compat.h" diff --git a/sys/dev/raid/twe/twe_freebsd.c b/sys/dev/raid/twe/twe_freebsd.c index 19de76e34b..5380e91cbd 100644 --- a/sys/dev/raid/twe/twe_freebsd.c +++ b/sys/dev/raid/twe/twe_freebsd.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/twe/twe_freebsd.c,v 1.2.2.9 2004/06/11 18:57:31 vkashyap Exp $ - * $DragonFly: src/sys/dev/raid/twe/twe_freebsd.c,v 1.26 2007/05/15 00:01:04 dillon Exp $ + * $DragonFly: src/sys/dev/raid/twe/twe_freebsd.c,v 1.27 2007/06/17 23:50:16 dillon Exp $ */ /* @@ -39,6 +39,7 @@ #include #include #include +#include static devclass_t twe_devclass; diff --git a/sys/dev/raid/vinum/vinumhdr.h b/sys/dev/raid/vinum/vinumhdr.h index 943fa78e95..ffb3d9524a 100644 --- a/sys/dev/raid/vinum/vinumhdr.h +++ b/sys/dev/raid/vinum/vinumhdr.h @@ -38,7 +38,7 @@ /* * $Id: vinumhdr.h,v 1.18 2001/01/04 00:14:14 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumhdr.h,v 1.16.2.1 2001/03/13 02:59:43 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumhdr.h,v 1.12 2007/05/16 05:20:21 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumhdr.h,v 1.13 2007/06/17 23:50:16 dillon Exp $ */ #include @@ -60,8 +60,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 048b696e5b..3321a91e40 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -77,7 +77,7 @@ * @(#)ufs_disksubr.c 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/subr_disk.c,v 1.20.2.6 2001/10/05 07:14:57 peter Exp $ * $FreeBSD: src/sys/ufs/ufs/ufs_disksubr.c,v 1.44.2.3 2001/03/05 05:42:19 obrien Exp $ - * $DragonFly: src/sys/kern/subr_disk.c,v 1.36 2007/06/17 03:51:10 dillon Exp $ + * $DragonFly: src/sys/kern/subr_disk.c,v 1.37 2007/06/17 23:50:16 dillon Exp $ */ #include @@ -87,7 +87,6 @@ #include #include #include -#include #include #include #include @@ -602,164 +601,6 @@ bioqdisksort(struct bio_queue_head *bioq, struct bio *bio) TAILQ_INSERT_AFTER(&bioq->queue, bq, bio, bio_act); } - -/* - * Attempt to read a disk label from a device using the indicated strategy - * routine. The label must be partly set up before this: secpercyl, secsize - * and anything required in the strategy routine (e.g., dummy bounds for the - * partition containing the label) must be filled in before calling us. - * Returns NULL on success and an error string on failure. - */ -char * -readdisklabel(cdev_t dev, struct disklabel *lp) -{ - struct buf *bp; - struct disklabel *dlp; - char *msg = NULL; - - bp = geteblk((int)lp->d_secsize); - bp->b_bio1.bio_offset = (off_t)LABELSECTOR * lp->d_secsize; - bp->b_bcount = lp->d_secsize; - bp->b_flags &= ~B_INVAL; - bp->b_cmd = BUF_CMD_READ; - dev_dstrategy(dev, &bp->b_bio1); - if (biowait(bp)) - msg = "I/O error"; - else for (dlp = (struct disklabel *)bp->b_data; - dlp <= (struct disklabel *)((char *)bp->b_data + - lp->d_secsize - sizeof(*dlp)); - dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { - if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { - if (msg == NULL) - msg = "no disk label"; - } else if (dlp->d_npartitions > MAXPARTITIONS || - dkcksum(dlp) != 0) - msg = "disk label corrupted"; - else { - *lp = *dlp; - msg = NULL; - break; - } - } - bp->b_flags |= B_INVAL | B_AGE; - brelse(bp); - return (msg); -} - -/* - * Check new disk label for sensibility before setting it. - */ -int -setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_int32_t *openmask) -{ - struct partition *opp, *npp; - int i; - - /* - * Check it is actually a disklabel we are looking at. - */ - if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || - dkcksum(nlp) != 0) - return (EINVAL); - - /* - * For each partition that we think is open, check the new disklabel - * for compatibility. Ignore special partitions (>= 128). - */ - i = 0; - while (i < 128) { - if (openmask[i >> 5] == 0) { - i += 32; - continue; - } - if ((openmask[i >> 5] & (1 << (i & 31))) == 0) { - ++i; - continue; - } - if (nlp->d_npartitions <= i) - return (EBUSY); - opp = &olp->d_partitions[i]; - npp = &nlp->d_partitions[i]; - if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size) - return (EBUSY); - /* - * Copy internally-set partition information - * if new label doesn't include it. XXX - * (If we are using it then we had better stay the same type) - * This is possibly dubious, as someone else noted (XXX) - */ - if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) { - npp->p_fstype = opp->p_fstype; - npp->p_fsize = opp->p_fsize; - npp->p_frag = opp->p_frag; - npp->p_cpg = opp->p_cpg; - } - ++i; - } - nlp->d_checksum = 0; - nlp->d_checksum = dkcksum(nlp); - *olp = *nlp; - return (0); -} - -/* - * Write disk label back to device after modification. - */ -int -writedisklabel(cdev_t dev, struct disklabel *lp) -{ - struct buf *bp; - struct disklabel *dlp; - int error = 0; - - if (lp->d_partitions[RAW_PART].p_offset != 0) - return (EXDEV); /* not quite right */ - bp = geteblk((int)lp->d_secsize); - bp->b_bio1.bio_offset = (off_t)LABELSECTOR * lp->d_secsize; - bp->b_bcount = lp->d_secsize; -#if 1 - /* - * We read the label first to see if it's there, - * in which case we will put ours at the same offset into the block.. - * (I think this is stupid [Julian]) - * Note that you can't write a label out over a corrupted label! - * (also stupid.. how do you write the first one? by raw writes?) - */ - bp->b_flags &= ~B_INVAL; - bp->b_cmd = BUF_CMD_READ; - dev_dstrategy(dkmodpart(dev, WHOLE_SLICE_PART), &bp->b_bio1); - error = biowait(bp); - if (error) - goto done; - for (dlp = (struct disklabel *)bp->b_data; - dlp <= (struct disklabel *) - ((char *)bp->b_data + lp->d_secsize - sizeof(*dlp)); - dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { - if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC && - dkcksum(dlp) == 0) { - *dlp = *lp; - bp->b_cmd = BUF_CMD_WRITE; - dev_dstrategy(dkmodpart(dev, WHOLE_SLICE_PART), &bp->b_bio1); - error = biowait(bp); - goto done; - } - } - error = ESRCH; -done: -#else - bzero(bp->b_data, lp->d_secsize); - dlp = (struct disklabel *)bp->b_data; - *dlp = *lp; - bp->b_flags &= ~B_INVAL; - bp->b_cmd = BUF_CMD_WRITE; - BUF_STRATEGY(bp, 1); - error = biowait(bp); -#endif - bp->b_flags |= B_INVAL | B_AGE; - brelse(bp); - return (error); -} - /* * Disk error is the preface to plaintive error messages * about failing disk transfers. It prints messages of the form diff --git a/sys/kern/subr_disklabel32.c b/sys/kern/subr_disklabel32.c new file mode 100644 index 0000000000..6ece8d9911 --- /dev/null +++ b/sys/kern/subr_disklabel32.c @@ -0,0 +1,589 @@ +/* + * Copyright (c) 2003-2007 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Matthew Dillon + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Copyright (c) 1994 Bruce D. Evans. + * All rights reserved. + * + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Copyright (c) 1982, 1986, 1988 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ufs_disksubr.c 8.5 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/kern/subr_disk.c,v 1.20.2.6 2001/10/05 07:14:57 peter Exp $ + * $FreeBSD: src/sys/ufs/ufs/ufs_disksubr.c,v 1.44.2.3 2001/03/05 05:42:19 obrien Exp $ + * $DragonFly: src/sys/kern/subr_disklabel32.c,v 1.1 2007/06/17 23:50:16 dillon Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* DTYPE_* constants */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include /* XXX used only for fs.h */ +#include /* XXX used only to get BBSIZE/SBSIZE */ + +static void partition_info(const char *sname, int part, struct partition *pp); +static void slice_info(const char *sname, struct diskslice *sp); + +/* + * Retrieve the partition start and extent, in blocks. Return 0 on success, + * EINVAL on error. + */ +int +getpartbounds(struct disklabel *lp, u_int32_t part, + u_int64_t *start, u_int64_t *blocks) +{ + struct partition *pp; + + if (part >= lp->d_npartitions) + return (EINVAL); + pp = &lp->d_partitions[part]; + *blocks = pp->p_size; + *start = pp->p_offset; + return(0); +} + +int +getpartfstype(struct disklabel *lp, u_int32_t part) +{ + struct partition *pp; + + if (part >= lp->d_npartitions) + return (0); + pp = &lp->d_partitions[part]; + return(pp->p_fstype); +} + +u_int32_t +getnumparts(struct disklabel *lp) +{ + return(lp->d_npartitions); +} + +/* + * Attempt to read a disk label from a device using the indicated strategy + * routine. The label must be partly set up before this: secpercyl, secsize + * and anything required in the strategy routine (e.g., dummy bounds for the + * partition containing the label) must be filled in before calling us. + * Returns NULL on success and an error string on failure. + */ +char * +readdisklabel(cdev_t dev, struct disklabel *lp) +{ + struct buf *bp; + struct disklabel *dlp; + char *msg = NULL; + + bp = geteblk((int)lp->d_secsize); + bp->b_bio1.bio_offset = (off_t)LABELSECTOR * lp->d_secsize; + bp->b_bcount = lp->d_secsize; + bp->b_flags &= ~B_INVAL; + bp->b_cmd = BUF_CMD_READ; + dev_dstrategy(dev, &bp->b_bio1); + if (biowait(bp)) + msg = "I/O error"; + else for (dlp = (struct disklabel *)bp->b_data; + dlp <= (struct disklabel *)((char *)bp->b_data + + lp->d_secsize - sizeof(*dlp)); + dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { + if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { + if (msg == NULL) + msg = "no disk label"; + } else if (dlp->d_npartitions > MAXPARTITIONS || + dkcksum(dlp) != 0) + msg = "disk label corrupted"; + else { + *lp = *dlp; + msg = NULL; + break; + } + } + bp->b_flags |= B_INVAL | B_AGE; + brelse(bp); + return (msg); +} + +/* + * Check new disk label for sensibility before setting it. + */ +int +setdisklabel(struct disklabel *olp, struct disklabel *nlp, + struct diskslice *sp, u_int32_t *openmask) +{ + struct partition *opp, *npp; + int part; + int i; + + /* + * Check it is actually a disklabel we are looking at. + */ + if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || + dkcksum(nlp) != 0) + return (EINVAL); + + /* + * For each partition that we think is open, check the new disklabel + * for compatibility. Ignore special partitions (>= 128). + */ + i = 0; + while (i < 128) { + if (openmask[i >> 5] == 0) { + i += 32; + continue; + } + if ((openmask[i >> 5] & (1 << (i & 31))) == 0) { + ++i; + continue; + } + if (nlp->d_npartitions <= i) + return (EBUSY); + opp = &olp->d_partitions[i]; + npp = &nlp->d_partitions[i]; + if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size) + return (EBUSY); + /* + * Copy internally-set partition information + * if new label doesn't include it. XXX + * (If we are using it then we had better stay the same type) + * This is possibly dubious, as someone else noted (XXX) + */ + if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) { + npp->p_fstype = opp->p_fstype; + npp->p_fsize = opp->p_fsize; + npp->p_frag = opp->p_frag; + npp->p_cpg = opp->p_cpg; + } + ++i; + } + nlp->d_checksum = 0; + nlp->d_checksum = dkcksum(nlp); + *olp = *nlp; + + if (olp->d_partitions[RAW_PART].p_offset) + return (EXDEV); + if (olp->d_secperunit > sp->ds_size) + return (ENOSPC); + for (part = 0; part < olp->d_npartitions; ++part) { + if (olp->d_partitions[part].p_size > sp->ds_size) + return(ENOSPC); + } + return (0); +} + +/* + * Write disk label back to device after modification. + */ +int +writedisklabel(cdev_t dev, struct disklabel *lp) +{ + struct buf *bp; + struct disklabel *dlp; + int error = 0; + + if (lp->d_partitions[RAW_PART].p_offset != 0) + return (EXDEV); /* not quite right */ + bp = geteblk((int)lp->d_secsize); + bp->b_bio1.bio_offset = (off_t)LABELSECTOR * lp->d_secsize; + bp->b_bcount = lp->d_secsize; +#if 1 + /* + * We read the label first to see if it's there, + * in which case we will put ours at the same offset into the block.. + * (I think this is stupid [Julian]) + * Note that you can't write a label out over a corrupted label! + * (also stupid.. how do you write the first one? by raw writes?) + */ + bp->b_flags &= ~B_INVAL; + bp->b_cmd = BUF_CMD_READ; + dev_dstrategy(dkmodpart(dev, WHOLE_SLICE_PART), &bp->b_bio1); + error = biowait(bp); + if (error) + goto done; + for (dlp = (struct disklabel *)bp->b_data; + dlp <= (struct disklabel *) + ((char *)bp->b_data + lp->d_secsize - sizeof(*dlp)); + dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { + if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC && + dkcksum(dlp) == 0) { + *dlp = *lp; + bp->b_cmd = BUF_CMD_WRITE; + dev_dstrategy(dkmodpart(dev, WHOLE_SLICE_PART), &bp->b_bio1); + error = biowait(bp); + goto done; + } + } + error = ESRCH; +done: +#else + bzero(bp->b_data, lp->d_secsize); + dlp = (struct disklabel *)bp->b_data; + *dlp = *lp; + bp->b_flags &= ~B_INVAL; + bp->b_cmd = BUF_CMD_WRITE; + BUF_STRATEGY(bp, 1); + error = biowait(bp); +#endif + bp->b_flags |= B_INVAL | B_AGE; + brelse(bp); + return (error); +} + +/* + * Create a disklabel based on a disk_info structure, initializing + * the appropriate fields and creating a raw partition that covers the + * whole disk. + * + * If a diskslice is passed, the label is truncated to the slice + */ +struct disklabel * +clone_label(struct disk_info *info, struct diskslice *sp) +{ + struct disklabel *lp1; + + lp1 = kmalloc(sizeof *lp1, M_DEVBUF, M_WAITOK | M_ZERO); + lp1->d_nsectors = info->d_secpertrack; + lp1->d_ntracks = info->d_nheads; + lp1->d_secpercyl = info->d_secpercyl; + lp1->d_secsize = info->d_media_blksize; + + if (sp) + lp1->d_secperunit = (u_int)sp->ds_size; + else + lp1->d_secperunit = (u_int)info->d_media_blocks; + + if (lp1->d_typename[0] == '\0') + strncpy(lp1->d_typename, "amnesiac", sizeof(lp1->d_typename)); + if (lp1->d_packname[0] == '\0') + strncpy(lp1->d_packname, "fictitious", sizeof(lp1->d_packname)); + if (lp1->d_nsectors == 0) + lp1->d_nsectors = 32; + if (lp1->d_ntracks == 0) + lp1->d_ntracks = 64; + lp1->d_secpercyl = lp1->d_nsectors * lp1->d_ntracks; + lp1->d_ncylinders = lp1->d_secperunit / lp1->d_secpercyl; + if (lp1->d_rpm == 0) + lp1->d_rpm = 3600; + if (lp1->d_interleave == 0) + lp1->d_interleave = 1; + if (lp1->d_npartitions < RAW_PART + 1) + lp1->d_npartitions = MAXPARTITIONS; + if (lp1->d_bbsize == 0) + lp1->d_bbsize = BBSIZE; + if (lp1->d_sbsize == 0) + lp1->d_sbsize = SBSIZE; + + /* + * Used by various devices to create a compatibility slice which + * allows us to mount root from devices which do not have a + * disklabel. Particularly: CDs. + */ + lp1->d_partitions[RAW_PART].p_size = lp1->d_secperunit; + if (info->d_dsflags & DSO_COMPATPARTA) { + lp1->d_partitions[0].p_size = lp1->d_secperunit; + lp1->d_partitions[0].p_fstype = FS_OTHER; + } + lp1->d_magic = DISKMAGIC; + lp1->d_magic2 = DISKMAGIC; + lp1->d_checksum = dkcksum(lp1); + return (lp1); +} + +void +makevirginlabel(struct disklabel *lp, struct diskslices *ssp, + struct diskslice *sp, struct disk_info *info) +{ + struct partition *pp; + + if (ssp->dss_slices[WHOLE_DISK_SLICE].ds_label) { + bcopy(ssp->dss_slices[WHOLE_DISK_SLICE].ds_label, lp, + sizeof(*lp)); + } else { + bzero(lp, sizeof(*lp)); + } + lp->d_magic = DISKMAGIC; + lp->d_magic2 = DISKMAGIC; + + lp->d_npartitions = MAXPARTITIONS; + if (lp->d_interleave == 0) + lp->d_interleave = 1; + if (lp->d_rpm == 0) + lp->d_rpm = 3600; + if (lp->d_nsectors == 0) /* sectors per track */ + lp->d_nsectors = 32; + if (lp->d_ntracks == 0) /* heads */ + lp->d_ntracks = 64; + lp->d_ncylinders = 0; + lp->d_bbsize = BBSIZE; + lp->d_sbsize = SBSIZE; + + /* + * If the slice or GPT partition is really small we could + * wind up with an absurd calculation for ncylinders. + */ + while (lp->d_ncylinders < 4) { + if (lp->d_ntracks > 1) + lp->d_ntracks >>= 1; + else if (lp->d_nsectors > 1) + lp->d_nsectors >>= 1; + else + break; + lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; + lp->d_ncylinders = sp->ds_size / lp->d_secpercyl; + } + + /* + * Set or Modify the partition sizes to accomodate the slice, + * since we started with a copy of the virgin label stored + * in the whole-disk-slice and we are probably not a + * whole-disk slice. + */ + lp->d_secperunit = sp->ds_size; + pp = &lp->d_partitions[RAW_PART]; + pp->p_offset = 0; + pp->p_size = lp->d_secperunit; + if (info->d_dsflags & DSO_COMPATPARTA) { + pp = &lp->d_partitions[0]; + pp->p_offset = 0; + pp->p_size = lp->d_secperunit; + pp->p_fstype = FS_OTHER; + } + lp->d_checksum = 0; + lp->d_checksum = dkcksum(lp); +} + +char * +fixlabel(const char *sname, struct diskslice *sp, struct disklabel *lp, int writeflag) +{ + u_int64_t start; + u_int64_t end; + u_int64_t offset; + int part; + struct partition *pp; + int warned; + + /* These errors "can't happen" so don't bother reporting details. */ + if (lp->d_magic != DISKMAGIC || lp->d_magic2 != DISKMAGIC) + return ("fixlabel: invalid magic"); + if (dkcksum(lp) != 0) + return ("fixlabel: invalid checksum"); + + pp = &lp->d_partitions[RAW_PART]; + + /* + * What a mess. For ages old backwards compatibility the disklabel + * on-disk stores absolute offsets instead of slice-relative offsets. + * So fix it up when reading, writing, or snooping. + * + * The in-core label is always slice-relative. + */ + if (writeflag) { + start = 0; + offset = sp->ds_offset; + } else { + start = sp->ds_offset; + offset = -sp->ds_offset; + } + if (pp->p_offset != start) { + if (sname != NULL) { + kprintf( +"%s: rejecting BSD label: raw partition offset != slice offset\n", + sname); + slice_info(sname, sp); + partition_info(sname, RAW_PART, pp); + } + return ("fixlabel: raw partition offset != slice offset"); + } + if (pp->p_size != sp->ds_size) { + if (sname != NULL) { + kprintf("%s: raw partition size != slice size\n", sname); + slice_info(sname, sp); + partition_info(sname, RAW_PART, pp); + } + if (pp->p_size > sp->ds_size) { + if (sname == NULL) + return ("fixlabel: raw partition size > slice size"); + kprintf("%s: truncating raw partition\n", sname); + pp->p_size = sp->ds_size; + } + } + end = start + sp->ds_size; + if (start > end) + return ("fixlabel: slice wraps"); + if (lp->d_secpercyl <= 0) + return ("fixlabel: d_secpercyl <= 0"); + pp -= RAW_PART; + warned = FALSE; + for (part = 0; part < lp->d_npartitions; part++, pp++) { + if (pp->p_offset != 0 || pp->p_size != 0) { + if (pp->p_offset < start + || pp->p_offset + pp->p_size > end + || pp->p_offset + pp->p_size < pp->p_offset) { + if (sname != NULL) { + kprintf( +"%s: rejecting partition in BSD label: it isn't entirely within the slice\n", + sname); + if (!warned) { + slice_info(sname, sp); + warned = TRUE; + } + partition_info(sname, part, pp); + } + /* XXX else silently discard junk. */ + bzero(pp, sizeof *pp); + } else { + pp->p_offset += offset; + } + } + } + lp->d_ncylinders = sp->ds_size / lp->d_secpercyl; + lp->d_secperunit = sp->ds_size; + lp->d_checksum = 0; + lp->d_checksum = dkcksum(lp); + return (NULL); +} + +void +adjust_label_reserved(struct diskslices *ssp, int slice, struct diskslice *sp) +{ + struct disklabel *lp = sp->ds_label; + + /* + * If the slice is not the whole-disk slice, setup the reserved + * area(s). + * + * The reserved area for the original bsd disklabel, inclusive of + * the label and space for boot2, is 15 sectors. If you've + * noticed people traditionally skipping 16 sectors its because + * the sector numbers start at the beginning of the slice rather + * then the beginning of the disklabel and traditional dos slices + * reserve a sector at the beginning for the boot code. + * + * NOTE! With the traditional bsdlabel, the first N bytes of boot2 + * overlap with the disklabel. The disklabel program checks that + * they are 0. + * + * When clearing a label, the bsdlabel reserved area is reset. + */ + if (slice != WHOLE_DISK_SLICE) { + if (lp) { + /* + * BSD uses in-band labels, meaning the label itself + * is accessible from partitions within the label. + * We must reserved the area taken up by the label + * itself to prevent mistakes from wiping it. + */ + sp->ds_reserved = SBSIZE / ssp->dss_secsize; + } else { + sp->ds_reserved = 0; + } + } +} + +static void +partition_info(const char *sname, int part, struct partition *pp) +{ + kprintf("%s%c: start %lu, end %lu, size %lu\n", sname, 'a' + part, + (u_long)pp->p_offset, (u_long)(pp->p_offset + pp->p_size - 1), + (u_long)pp->p_size); +} + +static void +slice_info(const char *sname, struct diskslice *sp) +{ + kprintf("%s: start %llu, end %llu, size %llu\n", sname, + sp->ds_offset, sp->ds_offset + sp->ds_size - 1, sp->ds_size); +} + diff --git a/sys/kern/subr_disklabel64.c b/sys/kern/subr_disklabel64.c new file mode 100644 index 0000000000..71f10ab73f --- /dev/null +++ b/sys/kern/subr_disklabel64.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2007 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Matthew Dillon + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/sys/kern/subr_disklabel64.c,v 1.1 2007/06/17 23:50:16 dillon Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + diff --git a/sys/kern/subr_diskslice.c b/sys/kern/subr_diskslice.c index 55beb1294c..42c61d91a7 100644 --- a/sys/kern/subr_diskslice.c +++ b/sys/kern/subr_diskslice.c @@ -44,7 +44,7 @@ * from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91 * from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $ * $FreeBSD: src/sys/kern/subr_diskslice.c,v 1.82.2.6 2001/07/24 09:49:41 dd Exp $ - * $DragonFly: src/sys/kern/subr_diskslice.c,v 1.44 2007/06/17 09:56:19 dillon Exp $ + * $DragonFly: src/sys/kern/subr_diskslice.c,v 1.45 2007/06/17 23:50:16 dillon Exp $ */ #include @@ -67,87 +67,15 @@ #include /* XXX used only for fs.h */ #include /* XXX used only to get BBSIZE/SBSIZE */ -#define TRACE(str) do { if (ds_debug) kprintf str; } while (0) - -typedef u_char bool_t; - -static volatile bool_t ds_debug; - -static struct disklabel *clone_label (struct disk_info *info, - struct diskslice *sp); static void dsiodone (struct bio *bio); -static char *fixlabel (const char *sname, struct diskslice *sp, - struct disklabel *lp, int writeflag); static int dsreadandsetlabel(cdev_t dev, u_int flags, struct diskslices *ssp, struct diskslice *sp, struct disk_info *info); static void free_ds_label (struct diskslices *ssp, int slice); -static void partition_info (const char *sname, int part, struct partition *pp); -static void slice_info (const char *sname, struct diskslice *sp); static void set_ds_label (struct diskslices *ssp, int slice, struct disklabel *lp); static void set_ds_wlabel (struct diskslices *ssp, int slice, int wlabel); -/* - * Create a disklabel based on a disk_info structure, initializing - * the appropriate fields and creating a raw partition that covers the - * whole disk. - * - * If a diskslice is passed, the label is truncated to the slice - */ -static struct disklabel * -clone_label(struct disk_info *info, struct diskslice *sp) -{ - struct disklabel *lp1; - - lp1 = kmalloc(sizeof *lp1, M_DEVBUF, M_WAITOK | M_ZERO); - lp1->d_nsectors = info->d_secpertrack; - lp1->d_ntracks = info->d_nheads; - lp1->d_secpercyl = info->d_secpercyl; - lp1->d_secsize = info->d_media_blksize; - - if (sp) - lp1->d_secperunit = (u_int)sp->ds_size; - else - lp1->d_secperunit = (u_int)info->d_media_blocks; - - if (lp1->d_typename[0] == '\0') - strncpy(lp1->d_typename, "amnesiac", sizeof(lp1->d_typename)); - if (lp1->d_packname[0] == '\0') - strncpy(lp1->d_packname, "fictitious", sizeof(lp1->d_packname)); - if (lp1->d_nsectors == 0) - lp1->d_nsectors = 32; - if (lp1->d_ntracks == 0) - lp1->d_ntracks = 64; - lp1->d_secpercyl = lp1->d_nsectors * lp1->d_ntracks; - lp1->d_ncylinders = lp1->d_secperunit / lp1->d_secpercyl; - if (lp1->d_rpm == 0) - lp1->d_rpm = 3600; - if (lp1->d_interleave == 0) - lp1->d_interleave = 1; - if (lp1->d_npartitions < RAW_PART + 1) - lp1->d_npartitions = MAXPARTITIONS; - if (lp1->d_bbsize == 0) - lp1->d_bbsize = BBSIZE; - if (lp1->d_sbsize == 0) - lp1->d_sbsize = SBSIZE; - - /* - * Used by various devices to create a compatibility slice which - * allows us to mount root from devices which do not have a - * disklabel. Particularly: CDs. - */ - lp1->d_partitions[RAW_PART].p_size = lp1->d_secperunit; - if (info->d_dsflags & DSO_COMPATPARTA) { - lp1->d_partitions[0].p_size = lp1->d_secperunit; - lp1->d_partitions[0].p_fstype = FS_OTHER; - } - lp1->d_magic = DISKMAGIC; - lp1->d_magic2 = DISKMAGIC; - lp1->d_checksum = dkcksum(lp1); - return (lp1); -} - /* * Determine the size of the transfer, and make sure it is * within the boundaries of the partition. Adjust transfer @@ -277,28 +205,19 @@ doshift: endsecno = sp->ds_size; slicerel_secno = secno; snoop = 1; - } else if ((lp = sp->ds_label) && part < lp->d_npartitions) { + } else if ((lp = sp->ds_label) != NULL) { /* - * A disklabel is present and a partition is explicitly being - * accessed (verses a whole-slice). Snooping of the - * partition is not supported even if the disklabel is - * accessible. Of course, the reserved area is still - * write protected. + * A label is present, extract the partition. Snooping of + * the disklabel is not supported even if accessible. Of + * course, the reserved area is still write protected. */ - struct partition *pp; - - pp = &lp->d_partitions[dkpart(dev)]; - endsecno = pp->p_size; - slicerel_secno = pp->p_offset + secno; + if (getpartbounds(lp, part, &slicerel_secno, &endsecno)) { + kprintf("dscheck(%s): partition %d out of bounds\n", + devtoname(dev), part); + goto bad; + } + slicerel_secno += secno; snoop = 0; - } else if (lp) { - /* - * Partition out of bounds - */ - kprintf("dscheck(%s): partition out of bounds %d/%d\n", - devtoname(dev), - part, lp->d_npartitions); - goto bad; } else { /* * Attempt to access partition when no disklabel present @@ -475,7 +394,6 @@ dsioctl(cdev_t dev, u_long cmd, caddr_t data, int flags, int slice; struct diskslice *sp; struct diskslices *ssp; - struct partition *pp; slice = dkslice(dev); part = dkpart(dev); @@ -497,60 +415,7 @@ dsioctl(cdev_t dev, u_long cmd, caddr_t data, int flags, } lp = (struct disklabel *)data; - if (ssp->dss_slices[WHOLE_DISK_SLICE].ds_label) { - *lp = *ssp->dss_slices[WHOLE_DISK_SLICE].ds_label; - } else { - bzero(lp, sizeof(struct disklabel)); - } - lp->d_magic = DISKMAGIC; - lp->d_magic2 = DISKMAGIC; - - lp->d_npartitions = MAXPARTITIONS; - if (lp->d_interleave == 0) - lp->d_interleave = 1; - if (lp->d_rpm == 0) - lp->d_rpm = 3600; - if (lp->d_nsectors == 0) /* sectors per track */ - lp->d_nsectors = 32; - if (lp->d_ntracks == 0) /* heads */ - lp->d_ntracks = 64; - lp->d_ncylinders = 0; - lp->d_bbsize = BBSIZE; - lp->d_sbsize = SBSIZE; - - /* - * If the slice or GPT partition is really small we could - * wind up with an absurd calculation for ncylinders. - */ - while (lp->d_ncylinders < 4) { - if (lp->d_ntracks > 1) - lp->d_ntracks >>= 1; - else if (lp->d_nsectors > 1) - lp->d_nsectors >>= 1; - else - break; - lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; - lp->d_ncylinders = sp->ds_size / lp->d_secpercyl; - } - - /* - * Set or Modify the partition sizes to accomodate the slice, - * since we started with a copy of the virgin label stored - * in the whole-disk-slice and we are probably not a - * whole-disk slice. - */ - lp->d_secperunit = sp->ds_size; - pp = &lp->d_partitions[RAW_PART]; - pp->p_offset = 0; - pp->p_size = lp->d_secperunit; - if (info->d_dsflags & DSO_COMPATPARTA) { - pp = &lp->d_partitions[0]; - pp->p_offset = 0; - pp->p_size = lp->d_secperunit; - pp->p_fstype = FS_OTHER; - } - lp->d_checksum = 0; - lp->d_checksum = dkcksum(lp); + makevirginlabel(lp, ssp, sp, info); return (0); case DIOCGDINFO: @@ -608,26 +473,26 @@ dsioctl(cdev_t dev, u_long cmd, caddr_t data, int flags, if (slice != WHOLE_DISK_SLICE && part != WHOLE_SLICE_PART) { - struct partition *p; - - if (lp == NULL || part >= lp->d_npartitions) + u_int64_t start; + u_int64_t blocks; + if (lp == NULL) return(EINVAL); - - p = &lp->d_partitions[part]; - dpart->fstype = p->p_fstype; - dpart->media_offset += (u_int64_t)p->p_offset * + if (getpartbounds(lp, part, &start, &blocks)) + return(EINVAL); + dpart->fstype = getpartfstype(lp, part); + dpart->media_offset += start * info->d_media_blksize; - dpart->media_size = (u_int64_t)p->p_size * + dpart->media_size = blocks * info->d_media_blksize; - dpart->media_blocks = (u_int64_t)p->p_size; + dpart->media_blocks = blocks; /* * partition starting sector (p_offset) * requires slice's reserved areas to be * adjusted. */ - if (dpart->reserved_blocks > p->p_offset) - dpart->reserved_blocks -= p->p_offset; + if (dpart->reserved_blocks > start) + dpart->reserved_blocks -= start; else dpart->reserved_blocks = 0; } @@ -676,30 +541,9 @@ dsioctl(cdev_t dev, u_long cmd, caddr_t data, int flags, bzero(openmask, sizeof(openmask)); } else { bcopy(sp->ds_openmask, openmask, sizeof(openmask)); -#if 0 - /* no longer supported, s0 is a real slice for GPT */ - if (slice == COMPATIBILITY_SLICE) { - dssetmaskfrommask(&ssp->dss_slices[ - ssp->dss_first_bsd_slice], - openmask); - } else if (slice == ssp->dss_first_bsd_slice) { - dssetmaskfrommask(&ssp->dss_slices[ - COMPATIBILITY_SLICE], - openmask); - } -#endif - } - error = setdisklabel(lp, (struct disklabel *)data, openmask); - /* XXX why doesn't setdisklabel() check this? */ - if (error == 0 && lp->d_partitions[RAW_PART].p_offset != 0) - error = EXDEV; - if (error == 0) { - if (lp->d_secperunit > sp->ds_size) - error = ENOSPC; - for (part = 0; part < lp->d_npartitions; part++) - if (lp->d_partitions[part].p_size > sp->ds_size) - error = ENOSPC; } + error = setdisklabel(lp, (struct disklabel *)data, + sp, openmask); if (error != 0) { kfree(lp, M_DEVBUF); return (error); @@ -849,7 +693,6 @@ int dsisopen(struct diskslices *ssp) { int slice; - int j; if (ssp == NULL) return (0); @@ -964,7 +807,7 @@ dsopen(cdev_t dev, int mode, u_int flags, { cdev_t dev1; int error; - bool_t need_init; + int need_init; struct diskslice *sp; struct diskslices *ssp; int slice; @@ -1004,7 +847,6 @@ dsopen(cdev_t dev, int mode, u_int flags, *sspp = dsmakeslicestruct(BASE_SLICE, info); if ((flags & DSO_ONESLICE) == 0) { - TRACE(("mbrinit\n")); error = mbrinit(dev, info, sspp); if (error != 0) { dsgone(sspp); @@ -1111,7 +953,7 @@ dsopen(cdev_t dev, int mode, u_int flags, * table need exist. */ if (part != WHOLE_SLICE_PART && slice != WHOLE_DISK_SLICE) { - if (sp->ds_label == NULL || part >= sp->ds_label->d_npartitions) + if (sp->ds_label == NULL || part >= getnumparts(sp->ds_label)) return (EINVAL); } dssetmask(sp, part); @@ -1162,8 +1004,6 @@ dsreadandsetlabel(cdev_t dev, u_int flags, } if (msg == NULL) msg = fixlabel(sname, sp, lp1, FALSE); - if (msg == NULL && lp1->d_secsize != info->d_media_blksize) - msg = "inconsistent sector size"; if (msg != NULL) { if (sp->ds_type == DOSPTYP_386BSD /* XXX */) log(LOG_WARNING, "%s: cannot find label (%s)\n", @@ -1183,6 +1023,8 @@ dssize(cdev_t dev, struct diskslices **sspp) int part; int slice; struct diskslices *ssp; + u_int64_t start; + u_int64_t blocks; slice = dkslice(dev); part = dkpart(dev); @@ -1197,7 +1039,9 @@ dssize(cdev_t dev, struct diskslices **sspp) lp = ssp->dss_slices[slice].ds_label; if (lp == NULL) return (-1); - return ((int64_t)lp->d_partitions[part].p_size); + if (getpartbounds(lp, part, &start, &blocks)) + return (-1); + return ((int64_t)blocks); } static void @@ -1214,180 +1058,18 @@ free_ds_label(struct diskslices *ssp, int slice) set_ds_label(ssp, slice, (struct disklabel *)NULL); } -static char * -fixlabel(const char *sname, struct diskslice *sp, struct disklabel *lp, int writeflag) -{ - u_int64_t start; - u_int64_t end; - u_int64_t offset; - int part; - struct partition *pp; - bool_t warned; - - /* These errors "can't happen" so don't bother reporting details. */ - if (lp->d_magic != DISKMAGIC || lp->d_magic2 != DISKMAGIC) - return ("fixlabel: invalid magic"); - if (dkcksum(lp) != 0) - return ("fixlabel: invalid checksum"); - - pp = &lp->d_partitions[RAW_PART]; - - /* - * What a mess. For ages old backwards compatibility the disklabel - * on-disk stores absolute offsets instead of slice-relative offsets. - * So fix it up when reading, writing, or snooping. - * - * The in-core label is always slice-relative. - */ - if (writeflag) { - start = 0; - offset = sp->ds_offset; - } else { - start = sp->ds_offset; - offset = -sp->ds_offset; - } - if (pp->p_offset != start) { - if (sname != NULL) { - kprintf( -"%s: rejecting BSD label: raw partition offset != slice offset\n", - sname); - slice_info(sname, sp); - partition_info(sname, RAW_PART, pp); - } - return ("fixlabel: raw partition offset != slice offset"); - } - if (pp->p_size != sp->ds_size) { - if (sname != NULL) { - kprintf("%s: raw partition size != slice size\n", sname); - slice_info(sname, sp); - partition_info(sname, RAW_PART, pp); - } - if (pp->p_size > sp->ds_size) { - if (sname == NULL) - return ("fixlabel: raw partition size > slice size"); - kprintf("%s: truncating raw partition\n", sname); - pp->p_size = sp->ds_size; - } - } - end = start + sp->ds_size; - if (start > end) - return ("fixlabel: slice wraps"); - if (lp->d_secpercyl <= 0) - return ("fixlabel: d_secpercyl <= 0"); - pp -= RAW_PART; - warned = FALSE; - for (part = 0; part < lp->d_npartitions; part++, pp++) { - if (pp->p_offset != 0 || pp->p_size != 0) { - if (pp->p_offset < start - || pp->p_offset + pp->p_size > end - || pp->p_offset + pp->p_size < pp->p_offset) { - if (sname != NULL) { - kprintf( -"%s: rejecting partition in BSD label: it isn't entirely within the slice\n", - sname); - if (!warned) { - slice_info(sname, sp); - warned = TRUE; - } - partition_info(sname, part, pp); - } - /* XXX else silently discard junk. */ - bzero(pp, sizeof *pp); - } else { - pp->p_offset += offset; - } - } - } - lp->d_ncylinders = sp->ds_size / lp->d_secpercyl; - lp->d_secperunit = sp->ds_size; - lp->d_checksum = 0; - lp->d_checksum = dkcksum(lp); - return (NULL); -} - -static void -partition_info(const char *sname, int part, struct partition *pp) -{ - kprintf("%s%c: start %lu, end %lu, size %lu\n", sname, 'a' + part, - (u_long)pp->p_offset, (u_long)(pp->p_offset + pp->p_size - 1), - (u_long)pp->p_size); -} - -static void -slice_info(const char *sname, struct diskslice *sp) -{ - kprintf("%s: start %llu, end %llu, size %llu\n", sname, - sp->ds_offset, sp->ds_offset + sp->ds_size - 1, sp->ds_size); -} - static void set_ds_label(struct diskslices *ssp, int slice, struct disklabel *lp) { - struct diskslice *sp1 = &ssp->dss_slices[slice]; -#if 0 - struct diskslice *sp2; - - if (slice == COMPATIBILITY_SLICE) - sp2 = &ssp->dss_slices[ssp->dss_first_bsd_slice]; - else if (slice == ssp->dss_first_bsd_slice) - sp2 = &ssp->dss_slices[COMPATIBILITY_SLICE]; - else - sp2 = NULL; -#endif - sp1->ds_label = lp; -#if 0 - if (sp2) - sp2->ds_label = lp; -#endif + struct diskslice *sp = &ssp->dss_slices[slice]; - /* - * If the slice is not the whole-disk slice, setup the reserved - * area(s). - * - * The reserved area for the original bsd disklabel, inclusive of - * the label and space for boot2, is 15 sectors. If you've - * noticed people traditionally skipping 16 sectors its because - * the sector numbers start at the beginning of the slice rather - * then the beginning of the disklabel and traditional dos slices - * reserve a sector at the beginning for the boot code. - * - * NOTE! With the traditional bsdlabel, the first N bytes of boot2 - * overlap with the disklabel. The disklabel program checks that - * they are 0. - * - * When clearing a label, the bsdlabel reserved area is reset. - */ - if (slice != WHOLE_DISK_SLICE) { - if (lp) { - /* - * BSD uses in-band labels, meaning the label itself - * is accessible from partitions within the label. - * We must reserved the area taken up by the label - * itself to prevent mistakes from wiping it. - */ - sp1->ds_reserved = SBSIZE / ssp->dss_secsize; -#if 0 - if (sp2) - sp2->ds_reserved = sp1->ds_reserved; -#endif - } else { - sp1->ds_reserved = 0; -#if 0 - if (sp2) - sp2->ds_reserved = sp1->ds_reserved; -#endif - } - } + sp->ds_label = lp; + adjust_label_reserved(ssp, slice, sp); } static void set_ds_wlabel(struct diskslices *ssp, int slice, int wlabel) { ssp->dss_slices[slice].ds_wlabel = wlabel; -#if 0 - if (slice == COMPATIBILITY_SLICE) - ssp->dss_slices[ssp->dss_first_bsd_slice].ds_wlabel = wlabel; - else if (slice == ssp->dss_first_bsd_slice) - ssp->dss_slices[COMPATIBILITY_SLICE].ds_wlabel = wlabel; -#endif } + diff --git a/sys/kern/vfs_conf.c b/sys/kern/vfs_conf.c index 92be9a3623..9c299f9fab 100644 --- a/sys/kern/vfs_conf.c +++ b/sys/kern/vfs_conf.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/vfs_conf.c,v 1.49.2.5 2003/01/07 11:56:53 joerg Exp $ - * $DragonFly: src/sys/kern/vfs_conf.c,v 1.31 2007/05/27 18:37:23 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_conf.c,v 1.32 2007/06/17 23:50:16 dillon Exp $ */ /* @@ -54,7 +54,6 @@ #include #include #include -#include #include #include #include diff --git a/sys/platform/pc32/i386/autoconf.c b/sys/platform/pc32/i386/autoconf.c index 07c7fd6c64..a2c1f7587a 100644 --- a/sys/platform/pc32/i386/autoconf.c +++ b/sys/platform/pc32/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.37 2007/05/08 02:31:42 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.38 2007/06/17 23:50:16 dillon Exp $ */ /* @@ -61,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -286,18 +285,8 @@ setroot(void) return; } - /* - * XXX kludge for inconsistent unit numbering and lack of slice - * support for floppies. - */ - if (majdev == FD_CDEV_MAJOR) { - slice = COMPATIBILITY_SLICE; - part = RAW_PART; - mindev = unit << FDUNITSHIFT; - } else { - part = B_PARTITION(bootdev); - mindev = dkmakeminor(unit, slice, part); - } + part = B_PARTITION(bootdev); + mindev = dkmakeminor(unit, slice, part); newrootdev = udev2dev(makeudev(majdev, mindev), 0); if (!dev_is_good(newrootdev)) return; diff --git a/sys/platform/vkernel/i386/autoconf.c b/sys/platform/vkernel/i386/autoconf.c index 6a21946f1d..269963990b 100644 --- a/sys/platform/vkernel/i386/autoconf.c +++ b/sys/platform/vkernel/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/platform/vkernel/i386/autoconf.c,v 1.12 2007/06/07 23:45:52 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/autoconf.c,v 1.13 2007/06/17 23:50:16 dillon Exp $ */ /* @@ -62,7 +62,6 @@ #include #include #include -#include #include #include #include diff --git a/sys/sys/disk.h b/sys/sys/disk.h index 7d02b7d938..810334f94e 100644 --- a/sys/sys/disk.h +++ b/sys/sys/disk.h @@ -39,7 +39,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/sys/disk.h,v 1.16.2.3 2001/06/20 16:11:01 scottl Exp $ - * $DragonFly: src/sys/sys/disk.h,v 1.16 2007/05/19 02:39:04 dillon Exp $ + * $DragonFly: src/sys/sys/disk.h,v 1.17 2007/06/17 23:50:12 dillon Exp $ */ #ifndef _SYS_DISK_H_ @@ -52,9 +52,6 @@ #ifndef _SYS_DISKSLICE_H_ #include #endif -#ifndef _SYS_DISKLABEL_H_ -#include -#endif #ifndef _SYS_QUEUE_H_ #include #endif diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index cda63f76bd..7dc749eaeb 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/disklabel.h,v 1.25 2007/06/13 20:58:38 dillon Exp $ + * $DragonFly: src/sys/sys/disklabel.h,v 1.26 2007/06/17 23:50:12 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -179,98 +179,6 @@ dkcksum(struct disklabel *lp) .set d_end_,276 /* size of disk label */ #endif /* LOCORE */ -/* d_type values: */ -#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ -#define DTYPE_MSCP 2 /* MSCP */ -#define DTYPE_DEC 3 /* other DEC (rk, rl) */ -#define DTYPE_SCSI 4 /* SCSI */ -#define DTYPE_ESDI 5 /* ESDI interface */ -#define DTYPE_ST506 6 /* ST506 etc. */ -#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ -#define DTYPE_HPFL 8 /* HP Fiber-link */ -#define DTYPE_FLOPPY 10 /* floppy */ -#define DTYPE_CCD 11 /* concatenated disk */ -#define DTYPE_VINUM 12 /* vinum volume */ -#define DTYPE_DOC2K 13 /* Msys DiskOnChip */ - -#ifdef DKTYPENAMES -static const char *dktypenames[] = { - "unknown", - "SMD", - "MSCP", - "old DEC", - "SCSI", - "ESDI", - "ST506", - "HP-IB", - "HP-FL", - "type 9", - "floppy", - "CCD", - "Vinum", - "DOC2K", - NULL -}; -#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) -#endif - -/* - * Filesystem type and version. - * Used to interpret other filesystem-specific - * per-partition information. - */ -#define FS_UNUSED 0 /* unused */ -#define FS_SWAP 1 /* swap */ -#define FS_V6 2 /* Sixth Edition */ -#define FS_V7 3 /* Seventh Edition */ -#define FS_SYSV 4 /* System V */ -#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ -#define FS_V8 6 /* Eighth Edition, 4K blocks */ -#define FS_BSDFFS 7 /* 4.2BSD fast file system */ -#define FS_MSDOS 8 /* MSDOS file system */ -#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ -#define FS_OTHER 10 /* in use, but unknown/unsupported */ -#define FS_HPFS 11 /* OS/2 high-performance file system */ -#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ -#define FS_BOOT 13 /* partition contains bootstrap */ -#define FS_VINUM 14 /* Vinum drive partition */ -#define FS_RAID 15 -#define FS_RESERVED16 16 -#define FS_RESERVED17 17 -#define FS_RESERVED18 18 -#define FS_CCD 19 /* CCD drive partition */ -#define FS_RESERVED20 20 -#define FS_JFS2 21 - -#ifdef DKTYPENAMES -static const char *fstypenames[] = { - "unused", - "swap", - "Version 6", - "Version 7", - "System V", - "4.1BSD", - "Eighth Edition", - "4.2BSD", - "MSDOS", - "4.4LFS", - "unknown", - "HPFS", - "ISO9660", - "boot", - "vinum", - "raid", - "?", - "?", - "?", - "ccd", - "?", /* don't use in case freebsd reassigns jfs / bug in freebsd */ - "jfs", - NULL -}; -#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) -#endif - #ifndef LOCORE /* @@ -283,10 +191,24 @@ static const char *fstypenames[] = { #ifdef _KERNEL +struct diskslice; +struct diskslices; +struct disk_info; + char *readdisklabel (cdev_t dev, struct disklabel *lp); int setdisklabel (struct disklabel *olp, struct disklabel *nlp, - u_int32_t *openmask); + struct diskslice *sp, u_int32_t *openmask); int writedisklabel (cdev_t dev, struct disklabel *lp); +struct disklabel *clone_label(struct disk_info *info, struct diskslice *sp); +char *fixlabel(const char *sname, struct diskslice *sp, + struct disklabel *lp, int writeflag); +void adjust_label_reserved(struct diskslices *ssp, int slice, struct diskslice *sp); +int getpartbounds(struct disklabel *lp, u_int32_t part, + u_int64_t *start, u_int64_t *blocks); +int getpartfstype(struct disklabel *lp, u_int32_t part); +u_int32_t getnumparts(struct disklabel *lp); +void makevirginlabel(struct disklabel *lp, struct diskslices *ssp, + struct diskslice *sp, struct disk_info *info); #endif /* _KERNEL */ diff --git a/sys/sys/disklabel32.h b/sys/sys/disklabel32.h index f7ed786866..4b8710df9f 100644 --- a/sys/sys/disklabel32.h +++ b/sys/sys/disklabel32.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/disklabel32.h,v 1.25 2007/06/13 20:58:38 dillon Exp $ + * $DragonFly: src/sys/sys/disklabel32.h,v 1.26 2007/06/17 23:50:12 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -179,98 +179,6 @@ dkcksum(struct disklabel *lp) .set d_end_,276 /* size of disk label */ #endif /* LOCORE */ -/* d_type values: */ -#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ -#define DTYPE_MSCP 2 /* MSCP */ -#define DTYPE_DEC 3 /* other DEC (rk, rl) */ -#define DTYPE_SCSI 4 /* SCSI */ -#define DTYPE_ESDI 5 /* ESDI interface */ -#define DTYPE_ST506 6 /* ST506 etc. */ -#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ -#define DTYPE_HPFL 8 /* HP Fiber-link */ -#define DTYPE_FLOPPY 10 /* floppy */ -#define DTYPE_CCD 11 /* concatenated disk */ -#define DTYPE_VINUM 12 /* vinum volume */ -#define DTYPE_DOC2K 13 /* Msys DiskOnChip */ - -#ifdef DKTYPENAMES -static const char *dktypenames[] = { - "unknown", - "SMD", - "MSCP", - "old DEC", - "SCSI", - "ESDI", - "ST506", - "HP-IB", - "HP-FL", - "type 9", - "floppy", - "CCD", - "Vinum", - "DOC2K", - NULL -}; -#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) -#endif - -/* - * Filesystem type and version. - * Used to interpret other filesystem-specific - * per-partition information. - */ -#define FS_UNUSED 0 /* unused */ -#define FS_SWAP 1 /* swap */ -#define FS_V6 2 /* Sixth Edition */ -#define FS_V7 3 /* Seventh Edition */ -#define FS_SYSV 4 /* System V */ -#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ -#define FS_V8 6 /* Eighth Edition, 4K blocks */ -#define FS_BSDFFS 7 /* 4.2BSD fast file system */ -#define FS_MSDOS 8 /* MSDOS file system */ -#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ -#define FS_OTHER 10 /* in use, but unknown/unsupported */ -#define FS_HPFS 11 /* OS/2 high-performance file system */ -#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ -#define FS_BOOT 13 /* partition contains bootstrap */ -#define FS_VINUM 14 /* Vinum drive partition */ -#define FS_RAID 15 -#define FS_RESERVED16 16 -#define FS_RESERVED17 17 -#define FS_RESERVED18 18 -#define FS_CCD 19 /* CCD drive partition */ -#define FS_RESERVED20 20 -#define FS_JFS2 21 - -#ifdef DKTYPENAMES -static const char *fstypenames[] = { - "unused", - "swap", - "Version 6", - "Version 7", - "System V", - "4.1BSD", - "Eighth Edition", - "4.2BSD", - "MSDOS", - "4.4LFS", - "unknown", - "HPFS", - "ISO9660", - "boot", - "vinum", - "raid", - "?", - "?", - "?", - "ccd", - "?", /* don't use in case freebsd reassigns jfs / bug in freebsd */ - "jfs", - NULL -}; -#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) -#endif - #ifndef LOCORE /* @@ -283,10 +191,24 @@ static const char *fstypenames[] = { #ifdef _KERNEL +struct diskslice; +struct diskslices; +struct disk_info; + char *readdisklabel (cdev_t dev, struct disklabel *lp); int setdisklabel (struct disklabel *olp, struct disklabel *nlp, - u_int32_t *openmask); + struct diskslice *sp, u_int32_t *openmask); int writedisklabel (cdev_t dev, struct disklabel *lp); +struct disklabel *clone_label(struct disk_info *info, struct diskslice *sp); +char *fixlabel(const char *sname, struct diskslice *sp, + struct disklabel *lp, int writeflag); +void adjust_label_reserved(struct diskslices *ssp, int slice, struct diskslice *sp); +int getpartbounds(struct disklabel *lp, u_int32_t part, + u_int64_t *start, u_int64_t *blocks); +int getpartfstype(struct disklabel *lp, u_int32_t part); +u_int32_t getnumparts(struct disklabel *lp); +void makevirginlabel(struct disklabel *lp, struct diskslices *ssp, + struct diskslice *sp, struct disk_info *info); #endif /* _KERNEL */ diff --git a/sys/sys/dtype.h b/sys/sys/dtype.h new file mode 100644 index 0000000000..9a33cf58b0 --- /dev/null +++ b/sys/sys/dtype.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ + * $DragonFly: src/sys/sys/dtype.h,v 1.1 2007/06/17 23:50:12 dillon Exp $ + */ + +#ifndef _SYS_DTYPE_H_ +#define _SYS_DTYPE_H_ + +#ifndef _SYS_TYPES_H_ +#include +#endif + +/* d_type values: */ +#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define DTYPE_MSCP 2 /* MSCP */ +#define DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define DTYPE_SCSI 4 /* SCSI */ +#define DTYPE_ESDI 5 /* ESDI interface */ +#define DTYPE_ST506 6 /* ST506 etc. */ +#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define DTYPE_HPFL 8 /* HP Fiber-link */ +#define DTYPE_FLOPPY 10 /* floppy */ +#define DTYPE_CCD 11 /* concatenated disk */ +#define DTYPE_VINUM 12 /* vinum volume */ +#define DTYPE_DOC2K 13 /* Msys DiskOnChip */ + +#ifdef DKTYPENAMES +static const char *dktypenames[] = { + "unknown", + "SMD", + "MSCP", + "old DEC", + "SCSI", + "ESDI", + "ST506", + "HP-IB", + "HP-FL", + "type 9", + "floppy", + "CCD", + "Vinum", + "DOC2K", + NULL +}; +#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) +#endif + +/* + * Filesystem type and version. + * Used to interpret other filesystem-specific + * per-partition information. + */ +#define FS_UNUSED 0 /* unused */ +#define FS_SWAP 1 /* swap */ +#define FS_V6 2 /* Sixth Edition */ +#define FS_V7 3 /* Seventh Edition */ +#define FS_SYSV 4 /* System V */ +#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ +#define FS_V8 6 /* Eighth Edition, 4K blocks */ +#define FS_BSDFFS 7 /* 4.2BSD fast file system */ +#define FS_MSDOS 8 /* MSDOS file system */ +#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ +#define FS_OTHER 10 /* in use, but unknown/unsupported */ +#define FS_HPFS 11 /* OS/2 high-performance file system */ +#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ +#define FS_BOOT 13 /* partition contains bootstrap */ +#define FS_VINUM 14 /* Vinum drive partition */ +#define FS_RAID 15 +#define FS_RESERVED16 16 +#define FS_RESERVED17 17 +#define FS_RESERVED18 18 +#define FS_CCD 19 /* CCD drive partition */ +#define FS_RESERVED20 20 +#define FS_JFS2 21 + +#ifdef DKTYPENAMES +static const char *fstypenames[] = { + "unused", + "swap", + "Version 6", + "Version 7", + "System V", + "4.1BSD", + "Eighth Edition", + "4.2BSD", + "MSDOS", + "4.4LFS", + "unknown", + "HPFS", + "ISO9660", + "boot", + "vinum", + "raid", + "?", + "?", + "?", + "ccd", + "?", /* don't use in case freebsd reassigns jfs / bug in freebsd */ + "jfs", + NULL +}; +#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) +#endif + +#endif /* SYS_DTYPE_H_ */ -- 2.41.0