geom_slice.c (93778) | geom_slice.c (94287) |
---|---|
1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the --- 18 unchanged lines hidden (view full) --- 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * | 1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the --- 18 unchanged lines hidden (view full) --- 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * |
35 * $FreeBSD: head/sys/geom/geom_slice.c 93778 2002-04-04 09:58:20Z phk $ | 35 * $FreeBSD: head/sys/geom/geom_slice.c 94287 2002-04-09 15:43:32Z phk $ |
36 */ 37 38 39#include <sys/param.h> 40#ifndef _KERNEL 41#include <stdio.h> 42#include <unistd.h> 43#include <stdlib.h> --- 80 unchanged lines hidden (view full) --- 124{ 125 struct bio *bp2; 126 struct g_provider *pp; 127 struct g_geom *gp; 128 struct g_consumer *cp; 129 struct g_slicer *gsp; 130 struct g_slice *gsl; 131 int index; | 36 */ 37 38 39#include <sys/param.h> 40#ifndef _KERNEL 41#include <stdio.h> 42#include <unistd.h> 43#include <stdlib.h> --- 80 unchanged lines hidden (view full) --- 124{ 125 struct bio *bp2; 126 struct g_provider *pp; 127 struct g_geom *gp; 128 struct g_consumer *cp; 129 struct g_slicer *gsp; 130 struct g_slice *gsl; 131 int index; |
132 off_t t; |
|
132 133 pp = bp->bio_to; 134 gp = pp->geom; 135 gsp = gp->softc; 136 cp = LIST_FIRST(&gp->consumer); 137 index = pp->index; | 133 134 pp = bp->bio_to; 135 gp = pp->geom; 136 gsp = gp->softc; 137 cp = LIST_FIRST(&gp->consumer); 138 index = pp->index; |
139 gsl = &gsp->slices[index]; |
|
138 switch(bp->bio_cmd) { 139 case BIO_READ: 140 case BIO_WRITE: 141 case BIO_DELETE: | 140 switch(bp->bio_cmd) { 141 case BIO_READ: 142 case BIO_WRITE: 143 case BIO_DELETE: |
142 gsl = &gsp->slices[index]; | |
143 if (bp->bio_offset > gsl->length) { 144 bp->bio_error = EINVAL; /* XXX: EWHAT ? */ 145 g_io_deliver(bp); 146 return; 147 } 148 bp2 = g_clone_bio(bp); 149 if (bp2->bio_offset + bp2->bio_length > gsl->length) 150 bp2->bio_length = gsl->length - bp2->bio_offset; 151 bp2->bio_done = g_std_done; 152 bp2->bio_offset += gsl->offset; 153 g_io_request(bp2, cp); 154 return; 155 case BIO_GETATTR: 156 case BIO_SETATTR: | 144 if (bp->bio_offset > gsl->length) { 145 bp->bio_error = EINVAL; /* XXX: EWHAT ? */ 146 g_io_deliver(bp); 147 return; 148 } 149 bp2 = g_clone_bio(bp); 150 if (bp2->bio_offset + bp2->bio_length > gsl->length) 151 bp2->bio_length = gsl->length - bp2->bio_offset; 152 bp2->bio_done = g_std_done; 153 bp2->bio_offset += gsl->offset; 154 g_io_request(bp2, cp); 155 return; 156 case BIO_GETATTR: 157 case BIO_SETATTR: |
158 /* Give the real method a chance to override */ 159 if (gsp->start(bp)) 160 return; |
|
157 if (g_haveattr_off_t(bp, "GEOM::mediasize", 158 gsp->slices[index].length)) 159 return; | 161 if (g_haveattr_off_t(bp, "GEOM::mediasize", 162 gsp->slices[index].length)) 163 return; |
160 if (gsp->start(bp)) | 164 if (!strcmp("GEOM::frontstuff", bp->bio_attribute)) { 165 t = gsp->cfrontstuff; 166 if (gsp->frontstuff > t) 167 t = gsp->frontstuff; 168 t -= gsl->offset; 169 if (t < 0) 170 t = 0; 171 if (t > gsl->length) 172 t = gsl->length; 173 g_haveattr_off_t(bp, "GEOM::frontstuff", t); |
161 return; | 174 return; |
175 } |
|
162 bp2 = g_clone_bio(bp); 163 bp2->bio_done = g_std_done; 164 g_io_request(bp2, cp); 165 break; 166 default: 167 bp->bio_error = EOPNOTSUPP; 168 g_io_deliver(bp); 169 return; 170 } 171} 172 173void 174g_slice_dumpconf(struct sbuf *sb, char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp) 175{ 176 struct g_mbr_softc *mp; 177 struct g_slicer *gsp; 178 179 gsp = gp->softc; 180 mp = gsp->softc; | 176 bp2 = g_clone_bio(bp); 177 bp2->bio_done = g_std_done; 178 g_io_request(bp2, cp); 179 break; 180 default: 181 bp->bio_error = EOPNOTSUPP; 182 g_io_deliver(bp); 183 return; 184 } 185} 186 187void 188g_slice_dumpconf(struct sbuf *sb, char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp) 189{ 190 struct g_mbr_softc *mp; 191 struct g_slicer *gsp; 192 193 gsp = gp->softc; 194 mp = gsp->softc; |
195 if (gp != NULL) { 196 sbuf_printf(sb, "%s<frontstuff>%llu</frontstuff>\n", 197 indent, (unsigned long long)gsp->frontstuff); 198 } |
|
181 if (pp != NULL) { 182 sbuf_printf(sb, "%s<index>%u</index>\n", indent, pp->index); 183 sbuf_printf(sb, "%s<length>%llu</length>\n", 184 indent, (unsigned long long)gsp->slices[pp->index].length); 185 sbuf_printf(sb, "%s<seclength>%llu</seclength>\n", indent, 186 (unsigned long long)gsp->slices[pp->index].length / 512); 187 sbuf_printf(sb, "%s<offset>%llu</offset>\n", indent, 188 (unsigned long long)gsp->slices[pp->index].offset); --- 30 unchanged lines hidden (view full) --- 219 220struct g_geom * 221g_slice_new(struct g_class *mp, int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start) 222{ 223 struct g_geom *gp; 224 struct g_slicer *gsp; 225 struct g_consumer *cp; 226 void **vp; | 199 if (pp != NULL) { 200 sbuf_printf(sb, "%s<index>%u</index>\n", indent, pp->index); 201 sbuf_printf(sb, "%s<length>%llu</length>\n", 202 indent, (unsigned long long)gsp->slices[pp->index].length); 203 sbuf_printf(sb, "%s<seclength>%llu</seclength>\n", indent, 204 (unsigned long long)gsp->slices[pp->index].length / 512); 205 sbuf_printf(sb, "%s<offset>%llu</offset>\n", indent, 206 (unsigned long long)gsp->slices[pp->index].offset); --- 30 unchanged lines hidden (view full) --- 237 238struct g_geom * 239g_slice_new(struct g_class *mp, int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start) 240{ 241 struct g_geom *gp; 242 struct g_slicer *gsp; 243 struct g_consumer *cp; 244 void **vp; |
227 int error; | 245 int error, i; |
228 229 g_topology_assert(); 230 vp = (void **)extrap; 231 gp = g_new_geomf(mp, "%s", pp->name); 232 gsp = g_slice_init(slices, extra); 233 gsp->start = start; 234 gp->access = g_slice_access; 235 gp->orphan = g_slice_orphan; --- 7 unchanged lines hidden (view full) --- 243 if (error) { 244 g_dettach(cp); 245 g_destroy_consumer(cp); 246 g_free(gsp->slices); 247 g_free(gp->softc); 248 g_destroy_geom(gp); 249 return (NULL); 250 } | 246 247 g_topology_assert(); 248 vp = (void **)extrap; 249 gp = g_new_geomf(mp, "%s", pp->name); 250 gsp = g_slice_init(slices, extra); 251 gsp->start = start; 252 gp->access = g_slice_access; 253 gp->orphan = g_slice_orphan; --- 7 unchanged lines hidden (view full) --- 261 if (error) { 262 g_dettach(cp); 263 g_destroy_consumer(cp); 264 g_free(gsp->slices); 265 g_free(gp->softc); 266 g_destroy_geom(gp); 267 return (NULL); 268 } |
269 /* Find out if there are any magic bytes on the consumer */ 270 i = sizeof gsp->cfrontstuff; 271 error = g_io_getattr("GEOM::frontstuff", cp, &i, &gsp->cfrontstuff); 272 if (error) 273 gsp->cfrontstuff = 0; |
|
251 *vp = gsp->softc; 252 *cpp = cp; 253 return (gp); 254} 255 256static void 257g_slice_orphan(struct g_consumer *cp) 258{ --- 18 unchanged lines hidden --- | 274 *vp = gsp->softc; 275 *cpp = cp; 276 return (gp); 277} 278 279static void 280g_slice_orphan(struct g_consumer *cp) 281{ --- 18 unchanged lines hidden --- |