From 5e40948decded173519ff6ea627dac2bdf59be92 Mon Sep 17 00:00:00 2001 From: ragge Date: Mon, 10 Jun 2002 17:45:53 +0000 Subject: [PATCH] Support for reading Ultrix disklabels. From the pmax port, fixed and tested by Valeriy E. Ushakov. --- sys/arch/vax/vax/disksubr.c | 102 +++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/sys/arch/vax/vax/disksubr.c b/sys/arch/vax/vax/disksubr.c index 730313768d71..f91438d4a786 100644 --- a/sys/arch/vax/vax/disksubr.c +++ b/sys/arch/vax/vax/disksubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: disksubr.c,v 1.30 2002/03/05 09:40:42 simonb Exp $ */ +/* $NetBSD: disksubr.c,v 1.31 2002/06/10 17:45:54 ragge Exp $ */ /* * Copyright (c) 1982, 1986, 1988 Regents of the University of California. @@ -53,6 +53,16 @@ #include /* For disk encoding scheme */ +#include "opt_compat_ultrix.h" +#ifdef COMPAT_ULTRIX +#include +#include /* XXX for fs.h */ +#include /* XXX for BBSIZE & SBSIZE */ + +char *compat_label(dev_t dev, void (*strat)(struct buf *bp), + struct disklabel *lp, struct cpu_disklabel *osdep); +#endif /* COMPAT_ULTRIX */ + /* * Determine the size of the transfer, and make sure it is * within the boundaries of the partition. Adjust transfer @@ -141,9 +151,99 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), } } brelse(bp); + +#ifdef COMPAT_ULTRIX + /* + * If no NetBSD label was found, check for an Ultrix label and + * construct tne incore label from the Ultrix partition information. + */ + if (msg != NULL) { + msg = compat_label(dev, strat, lp, osdep); + if (msg == NULL) { + printf("WARNING: using Ultrix partition information\n"); + /* set geometry? */ + } + } +#endif return (msg); } +#ifdef COMPAT_ULTRIX +/* + * Given a buffer bp, try and interpret it as an Ultrix disk label, + * putting the partition info into a native NetBSD label + */ +char * +compat_label(dev, strat, lp, osdep) + dev_t dev; + void (*strat)(struct buf *bp); + struct disklabel *lp; + struct cpu_disklabel *osdep; +{ + dec_disklabel *dlp; + struct buf *bp = NULL; + char *msg = NULL; + + bp = geteblk((int)lp->d_secsize); + bp->b_dev = dev; + bp->b_blkno = DEC_LABEL_SECTOR; + bp->b_bcount = lp->d_secsize; + bp->b_flags |= B_READ; + bp->b_cylinder = DEC_LABEL_SECTOR / lp->d_secpercyl; + (*strat)(bp); + + if (biowait(bp)) { + msg = "I/O error"; + goto done; + } + + for (dlp = (dec_disklabel *)bp->b_data; + dlp <= (dec_disklabel *)(bp->b_data+DEV_BSIZE-sizeof(*dlp)); + dlp = (dec_disklabel *)((char *)dlp + sizeof(long))) { + + int part; + + if (dlp->magic != DEC_LABEL_MAGIC) { + printf("label: %x\n",dlp->magic); + msg = ((msg != NULL) ? msg: "no disk label"); + goto done; + } + + lp->d_magic = DEC_LABEL_MAGIC; + lp->d_npartitions = 0; + strncpy(lp->d_packname, "Ultrix label", 16); + lp->d_rpm = 3600; + lp->d_interleave = 1; + lp->d_flags = 0; + lp->d_bbsize = BBSIZE; + lp->d_sbsize = SBSIZE; + for (part = 0; + part <((MAXPARTITIONSd_partitions[part].p_size = dlp->map[part].num_blocks; + lp->d_partitions[part].p_offset = dlp->map[part].start_block; + lp->d_partitions[part].p_fsize = 1024; + lp->d_partitions[part].p_fstype = + (part==1) ? FS_SWAP : FS_BSDFFS; + lp->d_npartitions += 1; + +#ifdef DIAGNOSTIC + printf(" Ultrix label rz%d%c: start %d len %d\n", + DISKUNIT(dev), "abcdefgh"[part], + lp->d_partitions[part].p_offset, + lp->d_partitions[part].p_size); +#endif + } + break; + } + +done: + brelse(bp); + return (msg); +} +#endif /* COMPAT_ULTRIX */ + /* * Check new disk label for sensibility * before setting it.