1,4 → 1,9 |
/*- |
* Copyright 2005, Anatoli Klassen <anatoli@aksoft.net> |
* All rights reserved. |
* |
* The code is based on code of geom_bsd module by Poul-Henning Kamp. |
* |
* Copyright (c) 2002 Poul-Henning Kamp |
* Copyright (c) 2002 Networks Associates Technology, Inc. |
* All rights reserved. |
39,19 → 44,12 |
* it will serve as the source in future copy&paste operations. |
*/ |
|
#include <sys/cdefs.h> |
__FBSDID("$FreeBSD: src/sys/geom/geom_bsd.c,v 1.73 2005/03/16 20:48:13 pjd Exp $"); |
|
#include <sys/param.h> |
#include <sys/endian.h> |
#include <sys/systm.h> |
#include <sys/kernel.h> |
#include <sys/fcntl.h> |
#include <sys/conf.h> |
#include <sys/bio.h> |
#include <sys/malloc.h> |
#include <sys/lock.h> |
#include <sys/mutex.h> |
#include <sys/md5.h> |
#include <sys/errno.h> |
#include <geom/geom.h> |
61,8 → 59,6 |
|
#define NBSD_CLASS_NAME "NetBSD" |
|
#define ALPHA_LABEL_OFFSET 64 |
|
#define LABELSIZE (148 + 16 * NBSD_MAXPARTITIONS) |
|
/* |
87,36 → 83,31 |
static int |
g_nbsd_modify(struct g_geom *gp, struct g_nbsd_softc *ms) |
{ |
int i, error; |
char useable[NBSD_MAXPARTITIONS]; |
MD5_CTX md5sum; |
struct partition *ppp; |
struct g_slicer *gsp; |
struct g_consumer *cp; |
struct disklabel *dl; |
off_t rawoffset, fullsize, o; |
int i, error; |
u_int secsize, u; |
off_t rawoffset, fullsize, o; |
struct disklabel dl; |
MD5_CTX md5sum; |
char useable[NBSD_MAXPARTITIONS]; |
|
g_topology_assert(); |
gsp = gp->softc; |
dl = &ms->ondisk; |
|
/* XXX double work */ |
error = nbsd_disklabel_le_dec(ms->label, &dl, NBSD_MAXPARTITIONS); |
if (error) { |
return (error); |
} |
|
/* Get dimensions of our device. */ |
cp = LIST_FIRST(&gp->consumer); |
secsize = cp->provider->sectorsize; |
|
/* ... or a smaller sector size. */ |
if (dl.d_secsize < secsize) { |
if (dl->d_secsize < secsize) { |
return (EINVAL); |
} |
|
/* ... or a non-multiple sector size. */ |
if (dl.d_secsize % secsize != 0) { |
if (dl->d_secsize % secsize != 0) { |
return (EINVAL); |
} |
|
123,12 → 114,12 |
rawoffset = ms->mbroffset; |
fullsize = cp->provider->mediasize; |
|
for (i = 0; i < dl.d_npartitions; i++) { |
ppp = &dl.d_partitions[i]; |
for (i = 0; i < dl->d_npartitions; i++) { |
ppp = &dl->d_partitions[i]; |
/* skip partitions with no type or outside of slide */ |
if (ppp->p_size == 0 || ppp->p_fstype == 0 || |
(off_t)ppp->p_offset * dl.d_secsize < rawoffset || |
(off_t)(ppp->p_offset + ppp->p_size) * dl.d_secsize |
(off_t)ppp->p_offset * dl->d_secsize < rawoffset || |
(off_t)(ppp->p_offset + ppp->p_size) * dl->d_secsize |
> (rawoffset + fullsize)) |
useable[i] = 0; |
else |
136,18 → 127,15 |
} |
|
/* Don't munge open partitions. */ |
for (i = 0; i < dl.d_npartitions; i++) { |
for (i = 0; i < dl->d_npartitions; i++) { |
if(!useable[i]) continue; |
|
ppp = &dl.d_partitions[i]; |
|
o = (off_t)ppp->p_offset * dl.d_secsize; |
ppp = &dl->d_partitions[i]; |
o = (off_t)ppp->p_offset * dl->d_secsize; |
if (o == 0) |
o = rawoffset; |
error = g_slice_config(gp, i, G_SLICE_CONFIG_CHECK, |
o - rawoffset, |
(off_t)ppp->p_size * dl.d_secsize, |
dl.d_secsize, |
o - rawoffset, (off_t)ppp->p_size * dl->d_secsize, dl->d_secsize, |
"%s%c", gp->name, 'a' + i); |
if (error) |
return (error); |
157,19 → 145,18 |
for (u = 0; u < gsp->nslice; u++) { |
if(!useable[u]) continue; |
|
ppp = &dl.d_partitions[u]; |
o = (off_t)ppp->p_offset * dl.d_secsize; |
ppp = &dl->d_partitions[u]; |
o = (off_t)ppp->p_offset * dl->d_secsize; |
if (o == 0) |
o = rawoffset; |
g_slice_config(gp, u, G_SLICE_CONFIG_SET, |
o - rawoffset, |
(off_t)ppp->p_size * dl.d_secsize, |
dl.d_secsize, |
(off_t)ppp->p_size * dl->d_secsize, |
dl->d_secsize, |
"%s%c", gp->name, 'a' + u); |
} |
|
/* Update our softc */ |
ms->ondisk = dl; |
ms->rawoffset = rawoffset; |
|
/* |
193,7 → 180,8 |
*/ |
|
static int |
g_nbsd_try(struct g_geom *gp, struct g_slicer *gsp, struct g_consumer *cp, int secsize, struct g_nbsd_softc *ms, off_t offset) |
g_nbsd_try(struct g_geom *gp, struct g_slicer *gsp, struct g_consumer *cp, |
int secsize, struct g_nbsd_softc *ms, off_t offset) |
{ |
int error; |
u_char *buf; |
243,23 → 231,8 |
static int |
g_nbsd_ioctl(struct g_provider *pp, u_long cmd, void *data, int fflag, struct thread *td) |
{ |
struct g_geom *gp; |
struct g_nbsd_softc *ms; |
struct g_slicer *gsp; |
|
gp = pp->geom; |
gsp = gp->softc; |
ms = gsp->softc; |
|
switch(cmd) { |
case DIOCGDINFO: |
/* Return a copy of the disklabel to userland. */ |
nbsd_disklabel_le_dec(ms->label, data, NBSD_MAXPARTITIONS); |
return(0); |
default: |
return (ENOIOCTL); |
} |
} |
|
static int |
g_nbsd_start(struct bio *bp) |
285,7 → 258,8 |
* consumer and provider. We let g_slice_dumpconf() do most of the work. |
*/ |
static void |
g_nbsd_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp) |
g_nbsd_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, |
struct g_consumer *cp, struct g_provider *pp) |
{ |
struct g_nbsd_softc *ms; |
struct g_slicer *gsp; |
333,14 → 307,14 |
static struct g_geom * |
g_nbsd_taste(struct g_class *mp, struct g_provider *pp, int flags) |
{ |
MD5_CTX md5sum; |
u_char hash[16]; |
struct g_geom *gp; |
struct g_consumer *cp; |
struct g_nbsd_softc *ms; |
struct g_slicer *gsp; |
int error; |
struct g_nbsd_softc *ms; |
u_int secsize; |
struct g_slicer *gsp; |
u_char hash[16]; |
MD5_CTX md5sum; |
|
g_trace(G_T_TOPOLOGY, "nbsd_taste(%s,%s)", mp->name, pp->name); |
g_topology_assert(); |