Extend struct devdesc with a unit field, called d_unit. Promote the

device (kind) specific unit field to the common field. This change
allows a future version of libefi to work without requiring anything
more than what is defined in struct devdesc and as such makes it
possible to compile said version of libefi for different platforms
without requiring that those platforms have identical derivatives
of struct devdesc.
This commit is contained in:
Marcel Moolenaar 2006-11-02 01:23:18 +00:00
parent bd3fd815a7
commit 932d8c46a2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=163897
19 changed files with 58 additions and 70 deletions

View File

@ -43,6 +43,7 @@ struct devdesc
#define DEVT_DISK 1
#define DEVT_NET 2
#define DEVT_CD 3
int d_unit;
};
/* Commands and return values; nonzero return sets command_errmsg != NULL */

View File

@ -146,7 +146,7 @@ efi_parsedev(struct efi_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
idev->d_kind.efidisk.unit = unit;
idev->d_unit = unit;
idev->d_kind.efidisk.slice = slice;
idev->d_kind.efidisk.partition = partition;
@ -169,7 +169,7 @@ efi_parsedev(struct efi_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
idev->d_kind.netif.unit = unit;
idev->d_unit = unit;
if (path != NULL)
*path = (*cp == 0) ? cp : cp + 1;
break;
@ -207,7 +207,7 @@ efi_fmtdev(void *vdev)
case DEVT_DISK:
cp = buf;
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.efidisk.unit);
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
if (dev->d_kind.efidisk.slice > 0)
cp += sprintf(cp, "s%d", dev->d_kind.efidisk.slice);
if (dev->d_kind.efidisk.partition >= 0)
@ -216,7 +216,7 @@ efi_fmtdev(void *vdev)
break;
case DEVT_NET:
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit);
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
break;
}
return(buf);

View File

@ -40,16 +40,13 @@ struct efi_devdesc {
#define DEVT_NONE 0
#define DEVT_DISK 1
#define DEVT_NET 2
int d_unit;
EFI_HANDLE d_handle;
union {
struct {
int unit;
int slice;
int partition;
} efidisk;
struct {
int unit; /* XXX net layer lives over these? */
} netif;
} d_kind;
};

View File

@ -365,7 +365,7 @@ efifs_dev_open(struct open_file *f, ...)
dev = va_arg(args, struct efi_devdesc*);
va_end(args);
unit = dev->d_kind.efidisk.unit;
unit = dev->d_unit;
if (unit < 0 || unit >= fs_handle_count) {
printf("attempt to open nonexistent EFI filesystem\n");
return(ENXIO);

View File

@ -195,7 +195,7 @@ bc_open(struct open_file *f, ...)
va_start(ap, f);
dev = va_arg(ap, struct i386_devdesc *);
va_end(ap);
if (dev->d_kind.bioscd.unit >= nbcinfo) {
if (dev->d_unit >= nbcinfo) {
DEBUG("attempt to open nonexistent disk");
return(ENXIO);
}
@ -230,7 +230,7 @@ bc_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf,
if (rw != F_READ)
return(EROFS);
dev = (struct i386_devdesc *)devdata;
unit = dev->d_kind.bioscd.unit;
unit = dev->d_unit;
blks = size / BIOSCD_SECSIZE;
if (dblk % (BIOSCD_SECSIZE / DEV_BSIZE) != 0)
return (EINVAL);
@ -331,7 +331,7 @@ bc_getdev(struct i386_devdesc *dev)
int major;
int rootdev;
unit = dev->d_kind.bioscd.unit;
unit = dev->d_unit;
biosdev = bc_unit2bios(unit);
DEBUG("unit %d BIOS device %d", unit, biosdev);
if (biosdev == -1) /* not a BIOS device */

View File

@ -251,7 +251,7 @@ bd_print(int verbose)
pager_output(line);
/* try to open the whole disk */
dev.d_kind.biosdisk.unit = i;
dev.d_unit = i;
dev.d_kind.biosdisk.slice = -1;
dev.d_kind.biosdisk.partition = -1;
@ -454,7 +454,7 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
int error;
char buf[BUFSIZE];
if (dev->d_kind.biosdisk.unit >= nbdinfo) {
if (dev->d_unit >= nbdinfo) {
DEBUG("attempt to open nonexistent disk");
return(ENXIO);
}
@ -466,14 +466,14 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
}
/* Look up BIOS unit number, intialise open_disk structure */
od->od_dkunit = dev->d_kind.biosdisk.unit;
od->od_dkunit = dev->d_unit;
od->od_unit = bdinfo[od->od_dkunit].bd_unit;
od->od_flags = bdinfo[od->od_dkunit].bd_flags;
od->od_boff = 0;
od->od_nslices = 0;
error = 0;
DEBUG("open '%s', unit 0x%x slice %d partition %c",
i386_fmtdev(dev), dev->d_kind.biosdisk.unit,
i386_fmtdev(dev), dev->d_unit,
dev->d_kind.biosdisk.slice, dev->d_kind.biosdisk.partition + 'a');
/* Get geometry for this open (removable device may have changed) */
@ -1177,8 +1177,8 @@ bd_getdev(struct i386_devdesc *dev)
char *nip, *cp;
int unitofs = 0, i, unit;
biosdev = bd_unit2bios(dev->d_kind.biosdisk.unit);
DEBUG("unit %d BIOS device %d", dev->d_kind.biosdisk.unit, biosdev);
biosdev = bd_unit2bios(dev->d_unit);
DEBUG("unit %d BIOS device %d", dev->d_unit, biosdev);
if (biosdev == -1) /* not a BIOS device */
return(-1);
if (bd_opendisk(&od, dev) != 0) /* oops, not a viable device */
@ -1186,7 +1186,7 @@ bd_getdev(struct i386_devdesc *dev)
if (biosdev < 0x80) {
/* floppy (or emulated floppy) or ATAPI device */
if (bdinfo[dev->d_kind.biosdisk.unit].bd_type == DT_ATAPI) {
if (bdinfo[dev->d_unit].bd_type == DT_ATAPI) {
/* is an ATAPI disk */
major = WFDMAJOR;
} else {

View File

@ -172,13 +172,13 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t
switch(rootdev->d_type) {
case DEVT_CD:
/* Pass in BIOS device number. */
bi.bi_bios_dev = bc_unit2bios(rootdev->d_kind.bioscd.unit);
bi.bi_bios_dev = bc_unit2bios(rootdev->d_unit);
bootdevnr = bc_getdev(rootdev);
break;
case DEVT_DISK:
/* pass in the BIOS device number of the current disk */
bi.bi_bios_dev = bd_unit2bios(rootdev->d_kind.biosdisk.unit);
bi.bi_bios_dev = bd_unit2bios(rootdev->d_unit);
bootdevnr = bd_getdev(rootdev);
break;

View File

@ -142,7 +142,7 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
idev->d_kind.biosdisk.unit = unit;
idev->d_unit = unit;
idev->d_kind.biosdisk.slice = slice;
idev->d_kind.biosdisk.partition = partition;
if (path != NULL)
@ -165,10 +165,7 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
if (dv->dv_type == DEVT_NET)
idev->d_kind.netif.unit = unit;
else
idev->d_kind.bioscd.unit = unit;
idev->d_unit = unit;
if (path != NULL)
*path = (*cp == 0) ? cp : cp + 1;
break;
@ -205,12 +202,12 @@ i386_fmtdev(void *vdev)
break;
case DEVT_CD:
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.bioscd.unit);
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
break;
case DEVT_DISK:
cp = buf;
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.biosdisk.unit);
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
if (dev->d_kind.biosdisk.slice > 0)
cp += sprintf(cp, "s%d", dev->d_kind.biosdisk.slice);
if (dev->d_kind.biosdisk.partition >= 0)
@ -219,7 +216,7 @@ i386_fmtdev(void *vdev)
break;
case DEVT_NET:
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit);
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
break;
}
return(buf);

View File

@ -36,24 +36,19 @@ struct i386_devdesc
{
struct devsw *d_dev;
int d_type;
int d_unit;
union
{
struct
{
int unit;
void *data;
int slice;
int partition;
void *data;
} biosdisk;
struct
{
int unit;
void *data;
} bioscd;
struct
{
int unit; /* XXX net layer lives over these? */
} netif;
} d_kind;
};

View File

@ -201,11 +201,11 @@ extract_currdev(void)
if ((kargs->bootflags & KARGS_FLAGS_CD) != 0) {
/* we are booting from a CD with cdboot */
new_currdev.d_dev = &bioscd;
new_currdev.d_kind.bioscd.unit = bc_bios2unit(initial_bootdev);
new_currdev.d_unit = bc_bios2unit(initial_bootdev);
} else if ((kargs->bootflags & KARGS_FLAGS_PXE) != 0) {
/* we are booting from pxeldr */
new_currdev.d_dev = &pxedisk;
new_currdev.d_kind.netif.unit = 0;
new_currdev.d_unit = 0;
} else {
/* we don't know what our boot device is */
new_currdev.d_kind.biosdisk.slice = -1;
@ -240,10 +240,10 @@ extract_currdev(void)
* which one we booted off of, just use disk0: as a reasonable default.
*/
if ((new_currdev.d_type == biosdisk.dv_type) &&
((new_currdev.d_kind.biosdisk.unit = bd_bios2unit(biosdev)) == -1)) {
((new_currdev.d_unit = bd_bios2unit(biosdev)) == -1)) {
printf("Can't work out which disk we are booting from.\n"
"Guessed BIOS device 0x%x not found by probes, defaulting to disk0:\n", biosdev);
new_currdev.d_kind.biosdisk.unit = 0;
new_currdev.d_unit = 0;
}
env_setenv("currdev", EV_VOLATILE, i386_fmtdev(&new_currdev),
i386_setcurrdev, env_nounset);

View File

@ -146,7 +146,7 @@ efi_parsedev(struct efi_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
idev->d_kind.efidisk.unit = unit;
idev->d_unit = unit;
idev->d_kind.efidisk.slice = slice;
idev->d_kind.efidisk.partition = partition;
@ -169,7 +169,7 @@ efi_parsedev(struct efi_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
idev->d_kind.netif.unit = unit;
idev->d_unit = unit;
if (path != NULL)
*path = (*cp == 0) ? cp : cp + 1;
break;
@ -207,7 +207,7 @@ efi_fmtdev(void *vdev)
case DEVT_DISK:
cp = buf;
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.efidisk.unit);
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
if (dev->d_kind.efidisk.slice > 0)
cp += sprintf(cp, "s%d", dev->d_kind.efidisk.slice);
if (dev->d_kind.efidisk.partition >= 0)
@ -216,7 +216,7 @@ efi_fmtdev(void *vdev)
break;
case DEVT_NET:
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit);
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
break;
}
return(buf);

View File

@ -135,13 +135,13 @@ main(int argc, CHAR16 *argv[])
i = efifs_get_unit(img->DeviceHandle);
if (i >= 0) {
currdev.d_dev = devsw[0]; /* XXX disk */
currdev.d_kind.efidisk.unit = i;
currdev.d_unit = i;
/* XXX should be able to detect this, default to autoprobe */
currdev.d_kind.efidisk.slice = -1;
currdev.d_kind.efidisk.partition = 0;
} else {
currdev.d_dev = devsw[1]; /* XXX net */
currdev.d_kind.netif.unit = 0; /* XXX */
currdev.d_unit = 0; /* XXX */
}
currdev.d_type = currdev.d_dev->dv_type;

View File

@ -143,7 +143,7 @@ ski_parsedev(struct ski_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
idev->d_kind.skidisk.unit = unit;
idev->d_unit = unit;
idev->d_kind.skidisk.slice = slice;
idev->d_kind.skidisk.partition = partition;
@ -166,7 +166,7 @@ ski_parsedev(struct ski_devdesc **dev, const char *devspec, const char **path)
goto fail;
}
idev->d_kind.netif.unit = unit;
idev->d_unit = unit;
if (path != NULL)
*path = (*cp == 0) ? cp : cp + 1;
break;
@ -204,7 +204,7 @@ ski_fmtdev(void *vdev)
case DEVT_DISK:
cp = buf;
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_kind.skidisk.unit);
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
if (dev->d_kind.skidisk.slice > 0)
cp += sprintf(cp, "s%d", dev->d_kind.skidisk.slice);
if (dev->d_kind.skidisk.partition >= 0)
@ -213,7 +213,7 @@ ski_fmtdev(void *vdev)
break;
case DEVT_NET:
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_kind.netif.unit);
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
break;
}
return(buf);

View File

@ -35,15 +35,12 @@ struct ski_devdesc {
#define DEVT_NONE 0
#define DEVT_DISK 1
#define DEVT_NET 2
int d_unit;
union {
struct {
int unit;
int slice;
int partition;
} skidisk;
struct {
int unit; /* XXX net layer lives over these? */
} netif;
} d_kind;
};

View File

@ -89,7 +89,7 @@ ski_main(void)
/* XXX presumes that biosdisk is first in devsw */
currdev.d_dev = devsw[0];
currdev.d_type = currdev.d_dev->dv_type;
currdev.d_kind.skidisk.unit = 0;
currdev.d_unit = 0;
/* XXX should be able to detect this, default to autoprobe */
currdev.d_kind.skidisk.slice = -1;
/* default to 'a' */

View File

@ -31,6 +31,7 @@
struct ofw_devdesc {
struct devsw *d_dev;
int d_type;
int d_unit;
ihandle_t d_handle;
char d_path[256];
};

View File

@ -192,7 +192,7 @@ bc_open(struct open_file *f, ...)
va_start(ap, f);
dev = va_arg(ap, struct i386_devdesc *);
va_end(ap);
if (dev->d_kind.bioscd.unit >= nbcinfo) {
if (dev->d_unit >= nbcinfo) {
DEBUG("attempt to open nonexistent disk");
return(ENXIO);
}
@ -227,7 +227,7 @@ bc_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf,
if (rw != F_READ)
return(EROFS);
dev = (struct i386_devdesc *)devdata;
unit = dev->d_kind.bioscd.unit;
unit = dev->d_unit;
blks = size / BIOSCD_SECSIZE;
if (dblk % (BIOSCD_SECSIZE / DEV_BSIZE) != 0)
return (EINVAL);
@ -321,7 +321,7 @@ bc_getdev(struct i386_devdesc *dev)
int major;
int rootdev;
unit = dev->d_kind.bioscd.unit;
unit = dev->d_unit;
biosdev = bc_unit2bios(unit);
DEBUG("unit %d BIOS device %d", unit, biosdev);
if (biosdev == -1) /* not a BIOS device */

View File

@ -256,7 +256,7 @@ bd_print(int verbose)
pager_output(line);
/* try to open the whole disk */
dev.d_kind.biosdisk.unit = i;
dev.d_unit = i;
dev.d_kind.biosdisk.slice = -1;
dev.d_kind.biosdisk.partition = -1;
@ -385,7 +385,7 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
int error;
char buf[BUFSIZE];
if (dev->d_kind.biosdisk.unit >= nbdinfo) {
if (dev->d_unit >= nbdinfo) {
DEBUG("attempt to open nonexistent disk");
return(ENXIO);
}
@ -397,14 +397,14 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
}
/* Look up BIOS unit number, intialise open_disk structure */
od->od_dkunit = dev->d_kind.biosdisk.unit;
od->od_dkunit = dev->d_unit;
od->od_unit = bdinfo[od->od_dkunit].bd_unit;
od->od_flags = bdinfo[od->od_dkunit].bd_flags;
od->od_boff = 0;
od->od_nslices = 0;
error = 0;
DEBUG("open '%s', unit 0x%x slice %d partition %c",
i386_fmtdev(dev), dev->d_kind.biosdisk.unit,
i386_fmtdev(dev), dev->d_unit,
dev->d_kind.biosdisk.slice, dev->d_kind.biosdisk.partition + 'a');
/* Get geometry for this open (removable device may have changed) */
@ -1058,8 +1058,8 @@ bd_getdev(struct i386_devdesc *dev)
char *nip, *cp;
int unitofs = 0, i, unit;
biosdev = bd_unit2bios(dev->d_kind.biosdisk.unit);
DEBUG("unit %d BIOS device %d", dev->d_kind.biosdisk.unit, biosdev);
biosdev = bd_unit2bios(dev->d_unit);
DEBUG("unit %d BIOS device %d", dev->d_unit, biosdev);
if (biosdev == -1) /* not a BIOS device */
return(-1);
if (bd_opendisk(&od, dev) != 0) /* oops, not a viable device */
@ -1067,7 +1067,7 @@ bd_getdev(struct i386_devdesc *dev)
if ((biosdev & 0xf0) == 0x90 || (biosdev & 0xf0) == 0x30) {
/* floppy (or emulated floppy) or ATAPI device */
if (bdinfo[dev->d_kind.biosdisk.unit].bd_type == DT_ATAPI) {
if (bdinfo[dev->d_unit].bd_type == DT_ATAPI) {
/* is an ATAPI disk */
major = WFDMAJOR;
} else {
@ -1093,7 +1093,7 @@ bd_getdev(struct i386_devdesc *dev)
}
/* default root disk unit number */
if ((biosdev & 0xf0) == 0xa0)
unit = bdinfo[dev->d_kind.biosdisk.unit].bd_da_unit;
unit = bdinfo[dev->d_unit].bd_da_unit;
else
unit = biosdev & 0xf;

View File

@ -193,11 +193,11 @@ extract_currdev(void)
if ((kargs->bootflags & KARGS_FLAGS_CD) != 0) {
/* we are booting from a CD with cdboot */
new_currdev.d_dev = &bioscd;
new_currdev.d_kind.bioscd.unit = bc_bios2unit(initial_bootdev);
new_currdev.d_unit = bc_bios2unit(initial_bootdev);
} else if ((kargs->bootflags & KARGS_FLAGS_PXE) != 0) {
/* we are booting from pxeldr */
new_currdev.d_dev = &pxedisk;
new_currdev.d_kind.netif.unit = 0;
new_currdev.d_unit = 0;
} else {
/* we don't know what our boot device is */
new_currdev.d_kind.biosdisk.slice = -1;
@ -236,10 +236,10 @@ extract_currdev(void)
* which one we booted off of, just use disk0: as a reasonable default.
*/
if ((new_currdev.d_type == biosdisk.dv_type) &&
((new_currdev.d_kind.biosdisk.unit = bd_bios2unit(biosdev)) == -1)) {
((new_currdev.d_unit = bd_bios2unit(biosdev)) == -1)) {
printf("Can't work out which disk we are booting from.\n"
"Guessed BIOS device 0x%x not found by probes, defaulting to disk0:\n", biosdev);
new_currdev.d_kind.biosdisk.unit = 0;
new_currdev.d_unit = 0;
}
env_setenv("currdev", EV_VOLATILE, i386_fmtdev(&new_currdev),
i386_setcurrdev, env_nounset);