Clean up Ultrix compatiblity code: redo Ultrix label reading code

to have the same interface as native readdisklabel(), call it cleanly
from caller of readdisklabel(), and fix bug that left d_npartitions at 1
for ultrix-compat labels. Ultrix labels now actually work.
This commit is contained in:
jonathan 1995-07-14 01:05:22 +00:00
parent 68b7908bf9
commit 9c4be79d84
2 changed files with 115 additions and 56 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rz.c,v 1.8 1994/12/08 18:33:19 dean Exp $ */
/* $NetBSD: rz.c,v 1.9 1995/07/14 01:05:30 jonathan Exp $ */
/*
* Copyright (c) 1992, 1993
@ -111,6 +111,21 @@ static struct size rzdefaultpart[MAXPARTITIONS] = {
#endif
};
extern char *readdisklabel __P((dev_t dev, void (*strat)(),
struct disklabel *lp, struct cpu_disklabel *osdep));
/*
* Ultrix disklabel declarations
*/
#ifdef COMPAT_ULTRIX
#include "../../stand/dec_boot.h"
extern char *
compat_label __P((dev_t dev, void (*strat)(),
struct disklabel *lp, struct cpu_disklabel *osdep));
#endif
#define RAWPART 2 /* 'c' partition */ /* XXX */
struct rzstats {
@ -714,9 +729,6 @@ rzdone(unit, error, resid, status)
}
}
#ifdef COMPAT_ULTRIX
#include "../../stand/dec_boot.h"
#endif
/*
* Read or constuct a disklabel
@ -731,7 +743,6 @@ rzgetinfo(dev)
register int i;
char *msg;
int part;
extern char *readdisklabel();
struct cpu_disklabel cd;
part = rzpart(dev);
@ -771,8 +782,23 @@ rzgetinfo(dev)
msg = readdisklabel(dev, rzstrategy, lp, &cd);
if (msg == NULL)
return;
printf("rz%d: WARNING: %s\n", unit, msg);
#ifdef COMPAT_ULTRIX
/*
* No native label, try and substitute Ultrix label
*/
msg = compat_label(dev, rzstrategy, lp, &cd);
if (msg == NULL) {
printf("rz%d: WARNING: using ULTRIX partition information",
unit);
return;
}
printf("rz%d: WARNING: Ultrix label, %s\n", unit, msg);
#endif
/*
* No label found. Concoct one from compile-time default.
*/
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_type = DTYPE_SCSI;
@ -783,16 +809,11 @@ rzgetinfo(dev)
lp->d_npartitions = MAXPARTITIONS;
lp->d_bbsize = BBSIZE;
lp->d_sbsize = SBSIZE;
#ifdef COMPAT_ULTRIX
if(sc->sc_label.d_magic != DEC_LABEL_MAGIC){
#endif
for (i = 0; i < MAXPARTITIONS; i++) {
lp->d_partitions[i].p_size = rzdefaultpart[i].nblocks;
lp->d_partitions[i].p_offset = rzdefaultpart[i].strtblk;
}
#ifdef COMPAT_ULTRIX
}
#endif
lp->d_partitions[RAWPART].p_size = sc->sc_blks;
}
@ -829,7 +850,8 @@ rzopen(dev, flags, mode, p)
printf("rzopen: ENXIO on rz%d%c unit %d part %d\n",
unit, "abcdefg"[part], unit, part);
printf("# partions %d, size of %d = %d\n",
lp->d_npartitions, lp->d_partitions[part].p_size);
lp->d_npartitions, part,
lp->d_partitions[part].p_size);
return (ENXIO);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: disksubr.c,v 1.4 1994/11/28 18:42:22 dean Exp $ */
/* $NetBSD: disksubr.c,v 1.5 1995/07/14 01:05:22 jonathan Exp $ */
/*
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@ -45,6 +45,11 @@
#ifdef COMPAT_ULTRIX
#include "../../stand/dec_boot.h"
extern char *
compat_label __P((dev_t dev, void (*strat)(),
struct disklabel *lp, struct cpu_disklabel *osdep));
#endif
@ -65,9 +70,6 @@ readdisklabel(dev, strat, lp, osdep)
{
register struct buf *bp;
struct disklabel *dlp;
#ifdef COMPAT_ULTRIX
Dec_DiskLabel *Dec_dlp;
#endif
char *msg = NULL;
if (lp->d_secperunit == 0)
@ -101,50 +103,85 @@ readdisklabel(dev, strat, lp, osdep)
break;
}
}
#ifdef COMPAT_ULTRIX /* look for ultrix disklabel
gallatin@isds.duke.edu , 8/21/94 */
if(msg){
msg = NULL;
bp->b_dev = dev;
bp->b_blkno = DEC_LABEL_SECTOR;
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ;
bp->b_cylin = DEC_LABEL_SECTOR / lp->d_secpercyl;
(*strat)(bp);
if (biowait(bp)) {
msg = "I/O error";
} else for (Dec_dlp = (Dec_DiskLabel *)bp->b_un.b_addr;
Dec_dlp <= (Dec_DiskLabel *)(bp->b_un.b_addr+DEV_BSIZE-sizeof(*Dec_dlp));
Dec_dlp = (Dec_DiskLabel *)((char *)Dec_dlp + sizeof(long))) {
if (Dec_dlp->magic != DEC_LABEL_MAGIC) {
printf("label: %x\n",Dec_dlp->magic);
if (msg == NULL)
msg = "no disk label";
}
else {
int i;
lp->d_magic=DEC_LABEL_MAGIC;
for(i=0;i<((MAXPARTITIONS<DEC_NUM_DISK_PARTS) ?
MAXPARTITIONS : DEC_NUM_DISK_PARTS); i++) {
lp->d_partitions[i].p_size = Dec_dlp->map[i].numBlocks;
lp->d_partitions[i].p_offset = Dec_dlp->map[i].startBlock;
lp->d_partitions[i].p_fsize = 1024;
if(i==1)
lp->d_partitions[i].p_fstype=FS_SWAP;
else
lp->d_partitions[i].p_fstype=FS_BSDFFS;
}
msg = "using ULTRIX partition information";
break;
}
}
}
#endif /* COMPAT_ULTRIX */
bp->b_flags = B_INVAL | B_AGE;
brelse(bp);
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)();
register 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_BUSY | B_READ;
bp->b_cylin = DEC_LABEL_SECTOR / lp->d_secpercyl;
(*strat)(bp);
if (biowait(bp)) {
msg = "I/O error";
goto done;
}
for (dlp = (Dec_DiskLabel *)bp->b_un.b_addr;
dlp <= (Dec_DiskLabel *)(bp->b_un.b_addr+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;
}
/*XXX*/ printf("Ultrix label loop\n");
lp->d_magic = DEC_LABEL_MAGIC;
lp->d_npartitions = 0;
for (part = 0;
part <((MAXPARTITIONS<DEC_NUM_DISK_PARTS) ?
MAXPARTITIONS : DEC_NUM_DISK_PARTS);
part++) {
lp->d_partitions[part].p_size = dlp->map[part].numBlocks;
lp->d_partitions[part].p_offset = dlp->map[part].startBlock;
lp->d_partitions[part].p_fsize = 1024;
lp->d_partitions[part].p_fstype =
(part==1) ? FS_SWAP : FS_BSDFFS;
lp->d_npartitions += 1;
#ifdef DEBUG
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:
bp->b_flags = B_INVAL | B_AGE;
brelse(bp);
return (msg);
}
#endif /* COMPAT_ULTRIX */
/*
* Check new disk label for sensibility
* before setting it.