From fd011e452f830fbb76efb6f65ecc7e54d36c8051 Mon Sep 17 00:00:00 2001 From: mhitch Date: Thu, 30 Nov 2006 05:14:24 +0000 Subject: [PATCH] Something I've wanted to do for quite some time: while looking for the RDSK block, check for a valid native NetBSD label. If found, use the NetBSD label. When writedisklabel() gets called, if no RDB was found, write out the native NetBSD label. The disk won't be usable by AmigaDOS, but is usable as a 'normal' NetBSD drive, with partition changes saved in the disk label. --- sys/arch/amiga/amiga/disksubr.c | 48 ++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/sys/arch/amiga/amiga/disksubr.c b/sys/arch/amiga/amiga/disksubr.c index e41c8553b3ed..e8997a60cfa0 100644 --- a/sys/arch/amiga/amiga/disksubr.c +++ b/sys/arch/amiga/amiga/disksubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: disksubr.c,v 1.51 2006/11/25 18:45:03 mhitch Exp $ */ +/* $NetBSD: disksubr.c,v 1.52 2006/11/30 05:14:24 mhitch Exp $ */ /* * Copyright (c) 1982, 1986, 1988 Regents of the University of California. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.51 2006/11/25 18:45:03 mhitch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.52 2006/11/30 05:14:24 mhitch Exp $"); #include #include @@ -143,6 +143,7 @@ readdisklabel(dev, strat, lp, clp) char *bcpls, *s, bcpli; int cindex, i, nopname; u_long nextb; + struct disklabel *dlp; clp->rdblock = RDBNULL; /* @@ -207,6 +208,18 @@ readdisklabel(dev, strat, lp, clp) else msg = "rdb bad checksum"; } + /* Check for native NetBSD label? */ + dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + if (dlp->d_magic == DISKMAGIC) { + if (dkcksum(dlp)) + msg = "NetBSD disk label corrupted"; + else { + /* remember block and continue searching? */ + *lp = *dlp; + brelse(bp); + return(msg); + } + } } if (nextb == RDB_MAXBLOCKS) { if (msg == NULL) @@ -537,9 +550,36 @@ writedisklabel(dev, strat, lp, clp) { struct rdbmap *bmap; struct buf *bp; - bp = NULL; /* XXX */ + struct disklabel *dlp; + int error = 0; + + /* If RDB was present, we don't support writing them yet. */ + if (clp->rdblock != RDBNULL) + return(EINVAL); + + /* RDB was not present, write out native NetBSD label */ + bp = geteblk((int)lp->d_secsize); + bp->b_dev = dev; + bp->b_blkno = LABELSECTOR; + bp->b_cylinder = 0; + bp->b_bcount = lp->d_secsize; + bp->b_flags |= B_READ; /* get current label */ + (*strat)(bp); + if ((error = biowait(bp)) != 0) + goto done; + + dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + *dlp = *lp; /* struct assignment */ + + bp->b_flags &= ~(B_READ|B_DONE); + bp->b_flags |= B_WRITE; + (*strat)(bp); + error = biowait(bp); + +done: + brelse(bp); + return (error); - return(EINVAL); /* * get write out partition list iff cpu_label is valid. */