Moved allocation of the slices struct to the right place. Initialize

everything in it (the devsw pointers were not initialized early or at
all for the !DEVFS case, but this was harmless on i386's).
This commit is contained in:
Bruce Evans 1998-07-20 13:39:45 +00:00
parent 8a261b8f7f
commit 92d1f65ed2
4 changed files with 56 additions and 58 deletions

View File

@ -35,10 +35,9 @@
*
* from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91
* from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $
* $Id: diskslice_machdep.c,v 1.27 1997/12/02 21:06:20 phk Exp $
* $Id: diskslice_machdep.c,v 1.28 1998/07/11 07:45:35 bde Exp $
*/
#include <stddef.h>
#include <sys/param.h>
#include <sys/buf.h>
#include <sys/conf.h>
@ -174,21 +173,6 @@ dsinit(dname, dev, strat, lp, sspp)
struct diskslice *sp;
struct diskslices *ssp;
/*
* Allocate a dummy slices "struct" and initialize it to contain
* only an empty compatibility slice (pointing to itself) and a
* whole disk slice (covering the disk as described by the label).
* If there is an error, then the dummy struct becomes final.
*/
ssp = malloc(offsetof(struct diskslices, dss_slices)
+ BASE_SLICE * sizeof *sp, M_DEVBUF, M_WAITOK);
*sspp = ssp;
ssp->dss_first_bsd_slice = COMPATIBILITY_SLICE;
ssp->dss_nslices = BASE_SLICE;
sp = &ssp->dss_slices[0];
bzero(sp, BASE_SLICE * sizeof *sp);
sp[WHOLE_DISK_SLICE].ds_size = lp->d_secperunit;
mbr_offset = DOSBBSECTOR;
reread_mbr:
/* Read master boot record. */
@ -315,21 +299,18 @@ dsinit(dname, dev, strat, lp, sspp)
}
/*
* Free the dummy slices "struct" and allocate a real new one.
* Initialize special slices as above.
* We are passed a pointer to a suitably initialized minimal
* slices "struct" with no dangling pointers in it. Replace it
* by a maximal one. This usually oversizes the "struct", but
* enlarging it while searching for logical drives would be
* inconvenient.
*/
free(ssp, M_DEVBUF);
ssp = malloc(offsetof(struct diskslices, dss_slices)
#define MAX_SLICES_SUPPORTED MAX_SLICES /* was (BASE_SLICE + NDOSPART) */
+ MAX_SLICES_SUPPORTED * sizeof *sp, M_DEVBUF, M_WAITOK);
free(*sspp, M_DEVBUF);
ssp = dsmakeslicestruct(MAX_SLICES, lp);
*sspp = ssp;
ssp->dss_first_bsd_slice = COMPATIBILITY_SLICE;
sp = &ssp->dss_slices[0];
bzero(sp, MAX_SLICES_SUPPORTED * sizeof *sp);
sp[WHOLE_DISK_SLICE].ds_size = lp->d_secperunit;
/* Initialize normal slices. */
sp += BASE_SLICE;
sp = &ssp->dss_slices[BASE_SLICE];
for (dospart = 0, dp = dp0; dospart < NDOSPART; dospart++, dp++, sp++) {
sp->ds_offset = mbr_offset + dp->dp_start;
sp->ds_size = dp->dp_size;

View File

@ -35,10 +35,9 @@
*
* from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91
* from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $
* $Id: diskslice_machdep.c,v 1.27 1997/12/02 21:06:20 phk Exp $
* $Id: diskslice_machdep.c,v 1.28 1998/07/11 07:45:35 bde Exp $
*/
#include <stddef.h>
#include <sys/param.h>
#include <sys/buf.h>
#include <sys/conf.h>
@ -174,21 +173,6 @@ dsinit(dname, dev, strat, lp, sspp)
struct diskslice *sp;
struct diskslices *ssp;
/*
* Allocate a dummy slices "struct" and initialize it to contain
* only an empty compatibility slice (pointing to itself) and a
* whole disk slice (covering the disk as described by the label).
* If there is an error, then the dummy struct becomes final.
*/
ssp = malloc(offsetof(struct diskslices, dss_slices)
+ BASE_SLICE * sizeof *sp, M_DEVBUF, M_WAITOK);
*sspp = ssp;
ssp->dss_first_bsd_slice = COMPATIBILITY_SLICE;
ssp->dss_nslices = BASE_SLICE;
sp = &ssp->dss_slices[0];
bzero(sp, BASE_SLICE * sizeof *sp);
sp[WHOLE_DISK_SLICE].ds_size = lp->d_secperunit;
mbr_offset = DOSBBSECTOR;
reread_mbr:
/* Read master boot record. */
@ -315,21 +299,18 @@ dsinit(dname, dev, strat, lp, sspp)
}
/*
* Free the dummy slices "struct" and allocate a real new one.
* Initialize special slices as above.
* We are passed a pointer to a suitably initialized minimal
* slices "struct" with no dangling pointers in it. Replace it
* by a maximal one. This usually oversizes the "struct", but
* enlarging it while searching for logical drives would be
* inconvenient.
*/
free(ssp, M_DEVBUF);
ssp = malloc(offsetof(struct diskslices, dss_slices)
#define MAX_SLICES_SUPPORTED MAX_SLICES /* was (BASE_SLICE + NDOSPART) */
+ MAX_SLICES_SUPPORTED * sizeof *sp, M_DEVBUF, M_WAITOK);
free(*sspp, M_DEVBUF);
ssp = dsmakeslicestruct(MAX_SLICES, lp);
*sspp = ssp;
ssp->dss_first_bsd_slice = COMPATIBILITY_SLICE;
sp = &ssp->dss_slices[0];
bzero(sp, MAX_SLICES_SUPPORTED * sizeof *sp);
sp[WHOLE_DISK_SLICE].ds_size = lp->d_secperunit;
/* Initialize normal slices. */
sp += BASE_SLICE;
sp = &ssp->dss_slices[BASE_SLICE];
for (dospart = 0, dp = dp0; dospart < NDOSPART; dospart++, dp++, sp++) {
sp->ds_offset = mbr_offset + dp->dp_start;
sp->ds_size = dp->dp_size;

View File

@ -43,11 +43,13 @@
* from: wd.c,v 1.55 1994/10/22 01:57:12 phk Exp $
* from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91
* from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $
* $Id: subr_diskslice.c,v 1.48 1998/07/11 07:45:42 bde Exp $
* $Id: subr_diskslice.c,v 1.49 1998/07/20 12:37:59 bde Exp $
*/
#include "opt_devfs.h"
#include <stddef.h>
#include <sys/param.h>
#include <sys/buf.h>
#include <sys/conf.h>
@ -556,6 +558,32 @@ dsisopen(ssp)
return (0);
}
/*
* Allocate a slices "struct" and initialize it to contain only an empty
* compatibility slice (pointing to itself), a whole disk slice (covering
* the disk as described by the label), and (nslices - BASE_SLICES) empty
* slices beginning at BASE_SLICE.
*/
struct diskslices *
dsmakeslicestruct(nslices, lp)
int nslices;
struct disklabel *lp;
{
struct diskslice *sp;
struct diskslices *ssp;
ssp = malloc(offsetof(struct diskslices, dss_slices) +
nslices * sizeof *sp, M_DEVBUF, M_WAITOK);
ssp->dss_bdevsw = NULL;
ssp->dss_cdevsw = NULL;
ssp->dss_first_bsd_slice = COMPATIBILITY_SLICE;
ssp->dss_nslices = nslices;
sp = &ssp->dss_slices[0];
bzero(sp, nslices * sizeof *sp);
sp[WHOLE_DISK_SLICE].ds_size = lp->d_secperunit;
return (ssp);
}
char *
dsname(dname, unit, slice, part, partname)
char *dname;
@ -623,6 +651,13 @@ dsopen(dname, dev, mode, sspp, lp, strat, setgeom, bdevsw, cdevsw)
if (ssp != NULL && need_init)
dsgone(sspp);
if (need_init) {
/*
* Allocate a minimal slices "struct". This will become
* the final slices "struct" if we don't want real slices
* or if we can't find any real slices.
*/
*sspp = dsmakeslicestruct(BASE_SLICE, lp);
TRACE(("dsinit\n"));
error = dsinit(dname, dev, strat, lp, sspp);
if (error != 0) {

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: diskslice.h,v 1.22 1998/06/06 02:32:51 bde Exp $
* $Id: diskslice.h,v 1.23 1998/07/04 22:30:26 julian Exp $
*/
#ifndef _SYS_DISKSLICE_H_
@ -96,6 +96,7 @@ int dsioctl __P((char *dname, dev_t dev, int cmd, caddr_t data, int flags,
struct diskslices **sspp, void (*strat)(struct buf *bp),
ds_setgeom_t *setgeom));
int dsisopen __P((struct diskslices *ssp));
struct diskslices *dsmakeslicestruct __P((int nslices, struct disklabel *lp));
char *dsname __P((char *dname, int unit, int slice, int part,
char *partname));
int dsopen __P((char *dname, dev_t dev, int mode, struct diskslices **sspp,