From ff912372cb4352b44e9a059b61bd706a618b8c1c Mon Sep 17 00:00:00 2001 From: grog Date: Thu, 21 Jan 1999 00:41:31 +0000 Subject: Retain some of the RAID5 texts even in the non-RAID5 versions. Previously, accidentally starting the wrong version could corrupt the RAID5 configuration. Add functions Volno, Plexno and Sdno to replace the old defines VOLNO, PLEXNO and SDNO. --- sys/dev/vinum/vinumutil.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'sys') diff --git a/sys/dev/vinum/vinumutil.c b/sys/dev/vinum/vinumutil.c index 0b5ef0f..22d8be8 100644 --- a/sys/dev/vinum/vinumutil.c +++ b/sys/dev/vinum/vinumutil.c @@ -33,7 +33,7 @@ * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: util.c,v 1.3 1998/12/28 04:56:24 peter Exp $ + * $Id: vinumutil.c,v 1.10 1999/01/02 00:39:04 grog Exp grog $ */ /* This file contains utility routines used both in kernel and user context */ @@ -100,6 +100,9 @@ plex_org(enum plexorg org) return "striped"; break; + case plex_raid5: /* RAID5 plex */ + return "raid5"; + break; default: sprintf(numeric_state, "Invalid org %d", (int) org); @@ -212,3 +215,66 @@ sizespec(char *spec) /* NOTREACHED */ return -1; } + +/* Extract the volume number from a device number. + * Perform no checking. */ +int +Volno(dev_t dev) +{ + int x = (int) dev; + return (x & MASK(VINUM_VOL_WIDTH)) >> VINUM_VOL_SHIFT; +} + +/* Extract a plex number from a device number. + * Don't check the major number, but check the + * type. Return -1 for invalid types. */ +int +Plexno(dev_t dev) +{ + int x = (int) dev; + + switch (DEVTYPE(dev)) { + case VINUM_VOLUME_TYPE: + case VINUM_DRIVE_TYPE: + case VINUM_SUPERDEV_TYPE: + case VINUM_RAWSD_TYPE: + return -1; + + case VINUM_PLEX_TYPE: + case VINUM_SD_TYPE: + return VOL[Volno(x)].plex[(x >> VINUM_PLEX_SHIFT) & (MASK(VINUM_PLEX_WIDTH))]; + + case VINUM_RAWPLEX_TYPE: + return ((x & MASK(VINUM_VOL_WIDTH)) >> VINUM_VOL_SHIFT) /* low order 8 bits */ + |((x >> VINUM_RAWPLEX_SHIFT) + & (MASK(VINUM_RAWPLEX_WIDTH) + << (VINUM_VOL_SHIFT + VINUM_VOL_WIDTH))); /* upper 12 bits */ + } + return 0; /* compiler paranoia */ +} + +/* Extract a subdisk number from a device number. + * Don't check the major number, but check the + * type. Return -1 for invalid types. */ +int +Sdno(dev_t dev) +{ + int x = (int) dev; + + switch (DEVTYPE(dev)) { + case VINUM_VOLUME_TYPE: + case VINUM_DRIVE_TYPE: + case VINUM_SUPERDEV_TYPE: + case VINUM_PLEX_TYPE: + case VINUM_RAWPLEX_TYPE: + return -1; + + case VINUM_SD_TYPE: + return PLEX[Plexno(x)].sdnos[(x >> VINUM_SD_SHIFT) & (MASK(VINUM_SD_WIDTH))]; + + case VINUM_RAWSD_TYPE: + return ((x & MASK(VINUM_VOL_WIDTH)) >> VINUM_VOL_SHIFT) /* low order 8 bits */ + |((x >> VINUM_RAWPLEX_SHIFT) & (MASK(VINUM_RAWPLEX_WIDTH) << (VINUM_VOL_SHIFT + VINUM_VOL_WIDTH))); /* upper 12 bits */ + } + return -1; /* compiler paranoia */ +} -- cgit v1.1