Deleted Added
full compact
geom_bsd.c (107832) geom_bsd.c (107953)
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_bsd.c 107832 2002-12-13 21:31:13Z phk $
35 * $FreeBSD: head/sys/geom/geom_bsd.c 107953 2002-12-16 22:33:27Z phk $
36 *
37 * This is the method for dealing with BSD disklabels. It has been
38 * extensively (by my standards at least) commented, in the vain hope that
39 * it will server as the source in future copy&paste operations.
40 */
41
42#include <sys/param.h>
43#ifndef _KERNEL

--- 267 unchanged lines hidden (view full) ---

311 */
312static int
313g_bsd_modify(struct g_geom *gp, struct disklabel *dl)
314{
315 int i, error;
316 struct partition *ppp;
317 struct g_slicer *gsp;
318 struct g_consumer *cp;
36 *
37 * This is the method for dealing with BSD disklabels. It has been
38 * extensively (by my standards at least) commented, in the vain hope that
39 * it will server as the source in future copy&paste operations.
40 */
41
42#include <sys/param.h>
43#ifndef _KERNEL

--- 267 unchanged lines hidden (view full) ---

311 */
312static int
313g_bsd_modify(struct g_geom *gp, struct disklabel *dl)
314{
315 int i, error;
316 struct partition *ppp;
317 struct g_slicer *gsp;
318 struct g_consumer *cp;
319 u_int secsize;
319 u_int secsize, u;
320 off_t mediasize;
321
322 /* Basic check that this is indeed a disklabel. */
323 error = g_bsd_checklabel(dl);
324 if (error)
325 return (error);
326
327 /* Make sure the checksum is OK. */

--- 52 unchanged lines hidden (view full) ---

380 "%s%c", gp->name, 'a' + i);
381 if (error) {
382 g_topology_unlock();
383 return (error);
384 }
385 }
386
387 /* Look good, go for it... */
320 off_t mediasize;
321
322 /* Basic check that this is indeed a disklabel. */
323 error = g_bsd_checklabel(dl);
324 if (error)
325 return (error);
326
327 /* Make sure the checksum is OK. */

--- 52 unchanged lines hidden (view full) ---

380 "%s%c", gp->name, 'a' + i);
381 if (error) {
382 g_topology_unlock();
383 return (error);
384 }
385 }
386
387 /* Look good, go for it... */
388 for (i = 0; i < gsp->nslice; i++) {
389 ppp = &dl->d_partitions[i];
390 g_slice_config(gp, i, G_SLICE_CONFIG_SET,
388 for (u = 0; u < gsp->nslice; u++) {
389 ppp = &dl->d_partitions[u];
390 g_slice_config(gp, u, G_SLICE_CONFIG_SET,
391 (off_t)ppp->p_offset * dl->d_secsize,
392 (off_t)ppp->p_size * dl->d_secsize,
393 dl->d_secsize,
391 (off_t)ppp->p_offset * dl->d_secsize,
392 (off_t)ppp->p_size * dl->d_secsize,
393 dl->d_secsize,
394 "%s%c", gp->name, 'a' + i);
394 "%s%c", gp->name, 'a' + u);
395 }
396 return (0);
397}
398
399/*
400 * Calculate a disklabel checksum for a little-endian byte-stream.
401 * We need access to the decoded disklabel because the checksum only
402 * covers the partition data for the first d_npartitions.

--- 158 unchanged lines hidden (view full) ---

561 u_char *p;
562 int error;
563
564 bp = arg;
565 gp = bp->bio_to->geom;
566 gsp = gp->softc;
567 ms = gsp->softc;
568 gsl = &gsp->slices[bp->bio_to->index];
395 }
396 return (0);
397}
398
399/*
400 * Calculate a disklabel checksum for a little-endian byte-stream.
401 * We need access to the decoded disklabel because the checksum only
402 * covers the partition data for the first d_npartitions.

--- 158 unchanged lines hidden (view full) ---

561 u_char *p;
562 int error;
563
564 bp = arg;
565 gp = bp->bio_to->geom;
566 gsp = gp->softc;
567 ms = gsp->softc;
568 gsl = &gsp->slices[bp->bio_to->index];
569 p = bp->bio_data + ms->labeloffset
569 p = (u_char*)bp->bio_data + ms->labeloffset
570 - (bp->bio_offset + gsl->offset);
571 g_bsd_ledec_disklabel(p, &fake.ondisk);
572
573 ondisk2inram(&fake);
574 if (g_bsd_checklabel(&fake.inram)) {
575 g_io_deliver(bp, EPERM);
576 return;
577 }

--- 92 unchanged lines hidden (view full) ---

670}
671
672/*
673 * Dump configuration information in XML format.
674 * Notice that the function is called once for the geom and once for each
675 * consumer and provider. We let g_slice_dumpconf() do most of the work.
676 */
677static void
570 - (bp->bio_offset + gsl->offset);
571 g_bsd_ledec_disklabel(p, &fake.ondisk);
572
573 ondisk2inram(&fake);
574 if (g_bsd_checklabel(&fake.inram)) {
575 g_io_deliver(bp, EPERM);
576 return;
577 }

--- 92 unchanged lines hidden (view full) ---

670}
671
672/*
673 * Dump configuration information in XML format.
674 * Notice that the function is called once for the geom and once for each
675 * consumer and provider. We let g_slice_dumpconf() do most of the work.
676 */
677static void
678g_bsd_dumpconf(struct sbuf *sb, char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp)
678g_bsd_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp)
679{
680 struct g_bsd_softc *ms;
681 struct g_slicer *gsp;
682
683 gsp = gp->softc;
684 ms = gsp->softc;
685 g_slice_dumpconf(sb, indent, gp, cp, pp);
686 if (indent != NULL && pp == NULL && cp == NULL) {

--- 169 unchanged lines hidden ---
679{
680 struct g_bsd_softc *ms;
681 struct g_slicer *gsp;
682
683 gsp = gp->softc;
684 ms = gsp->softc;
685 g_slice_dumpconf(sb, indent, gp, cp, pp);
686 if (indent != NULL && pp == NULL && cp == NULL) {

--- 169 unchanged lines hidden ---