View | Details | Raw Unified | Return to bug 199476 | Differences between
and this patch

Collapse All | Expand All

(-)head/sys/geom/uncompress/g_uncompress.c (-17 / +26 lines)
Lines 464-470 g_uncompress_taste(struct g_class *mp, struct g_pr Link Here
464
	struct g_provider *pp2;
464
	struct g_provider *pp2;
465
	struct g_consumer *cp;
465
	struct g_consumer *cp;
466
	struct g_geom *gp;
466
	struct g_geom *gp;
467
	uint32_t i, total_offsets, type;
467
	uint64_t *offsets;
468
	uint32_t i, r, total, type;
468
	uint8_t *buf;
469
	uint8_t *buf;
469
	int error;
470
	int error;
470
471
Lines 499-506 g_uncompress_taste(struct g_class *mp, struct g_pr Link Here
499
	 */
500
	 */
500
	DPRINTF(("%s: media sectorsize %u, mediasize %jd\n",
501
	DPRINTF(("%s: media sectorsize %u, mediasize %jd\n",
501
	    gp->name, pp->sectorsize, (intmax_t)pp->mediasize));
502
	    gp->name, pp->sectorsize, (intmax_t)pp->mediasize));
502
	i = roundup(sizeof(struct cloop_header), pp->sectorsize);
503
	total = roundup(sizeof(struct cloop_header), pp->sectorsize);
503
	buf = g_read_data(cp, 0, i, NULL);
504
	buf = g_read_data(cp, 0, total, NULL);
504
	if (buf == NULL)
505
	if (buf == NULL)
505
		goto err;
506
		goto err;
506
	header = (struct cloop_header *) buf;
507
	header = (struct cloop_header *) buf;
Lines 550-576 g_uncompress_taste(struct g_class *mp, struct g_pr Link Here
550
		printf("%s: block size (%u) should not be larger than %d.\n",
551
		printf("%s: block size (%u) should not be larger than %d.\n",
551
		    gp->name, sc->blksz, MAX_BLKSZ);
552
		    gp->name, sc->blksz, MAX_BLKSZ);
552
	}
553
	}
553
	total_offsets = sc->nblocks + 1;
554
	if (sizeof(struct cloop_header) +
554
	if (sizeof(struct cloop_header) +
555
	    total_offsets * sizeof(uint64_t) > pp->mediasize) {
555
	    sc->nblocks * sizeof(uint64_t) >= pp->mediasize) {
556
		printf("%s: media too small for %u blocks\n",
556
		printf("%s: media too small for %u blocks\n",
557
		    gp->name, sc->nblocks);
557
		    gp->name, sc->nblocks);
558
		goto err;
558
		goto err;
559
	}
559
	}
560
	free(buf, M_GEOM);
560
	g_free(buf);
561
561
562
	i = roundup((sizeof(struct cloop_header) +
562
	sc->offsets = malloc(sc->nblocks * sizeof(uint64_t),
563
	    total_offsets * sizeof(uint64_t)), pp->sectorsize);
564
	buf = g_read_data(cp, 0, i, NULL);
565
	if (buf == NULL)
566
		goto err;
567
	sc->offsets = malloc(total_offsets * sizeof(uint64_t),
568
	    M_GEOM_UNCOMPRESS, M_WAITOK);
563
	    M_GEOM_UNCOMPRESS, M_WAITOK);
569
	for (i = 0; i <= total_offsets; i++) {
564
	total = roundup((sizeof(struct cloop_header) +
570
		sc->offsets[i] = be64toh(((uint64_t *)
565
	    sc->nblocks * sizeof(uint64_t)), pp->sectorsize);
571
		    (buf+sizeof(struct cloop_header)))[i]);
566
#define	RSZ	(total - r > MAXPHYS ? MAXPHYS: total - r)
567
	for (r = 0, i = 0; r < total; r += MAXPHYS) {
568
		buf = g_read_data(cp, r, RSZ, &error);
569
		if (buf == NULL) {
570
			free(sc->offsets, M_GEOM_UNCOMPRESS);
571
			goto err;
572
		}
573
		offsets = (uint64_t *)buf;
574
		if (r == 0)
575
			offsets +=
576
			    sizeof(struct cloop_header) / sizeof(uint64_t);
577
		for (; i < sc->nblocks && offsets < (uint64_t *)(buf + RSZ);
578
		    i++, offsets++)
579
			sc->offsets[i] = be64toh(*offsets);
580
		g_free(buf);
572
	}
581
	}
573
	free(buf, M_GEOM);
582
#undef RSZ
574
	buf = NULL;
583
	buf = NULL;
575
	DPRINTF(("%s: done reading offsets\n", gp->name));
584
	DPRINTF(("%s: done reading offsets\n", gp->name));
576
	mtx_init(&sc->last_mtx, "geom_uncompress cache", NULL, MTX_DEF);
585
	mtx_init(&sc->last_mtx, "geom_uncompress cache", NULL, MTX_DEF);
Lines 619-625 err: Link Here
619
	g_topology_lock();
628
	g_topology_lock();
620
	g_access(cp, -1, 0, 0);
629
	g_access(cp, -1, 0, 0);
621
	if (buf != NULL)
630
	if (buf != NULL)
622
		free(buf, M_GEOM);
631
		g_free(buf);
623
	if (gp->softc != NULL) {
632
	if (gp->softc != NULL) {
624
		g_uncompress_softc_free(gp->softc, NULL);
633
		g_uncompress_softc_free(gp->softc, NULL);
625
		gp->softc = NULL;
634
		gp->softc = NULL;

Return to bug 199476