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

Collapse All | Expand All

(-)sys/geom/uncompress/g_uncompress.c (-8 / +23 lines)
Lines 464-470 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
	uint32_t i, total_offsets, type, offsets_read, blk;
468
	uint8_t *buf;
468
	uint8_t *buf;
469
	int error;
469
	int error;
470
470
Lines 557-574 Link Here
557
		    gp->name, sc->nblocks);
557
		    gp->name, sc->nblocks);
558
		goto err;
558
		goto err;
559
	}
559
	}
560
	free(buf, M_GEOM);
561
560
562
	i = roundup((sizeof(struct cloop_header) +
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),
561
	sc->offsets = malloc(total_offsets * sizeof(uint64_t),
568
	    M_GEOM_UNCOMPRESS, M_WAITOK);
562
	    M_GEOM_UNCOMPRESS, M_WAITOK);
569
	for (i = 0; i <= total_offsets; i++) {
563
	offsets_read = MIN(total_offsets,
564
	    (pp->sectorsize - sizeof(struct cloop_header)) / sizeof(uint64_t));
565
	for (i = 0; i < offsets_read; i++)
570
		sc->offsets[i] = be64toh(((uint64_t *)
566
		sc->offsets[i] = be64toh(((uint64_t *)
571
		    (buf+sizeof(struct cloop_header)))[i]);
567
		    (buf+sizeof(struct cloop_header)))[i]);
568
	DPRINTF(("%s: %u offsets in the first sector\n",
569
		gp->name, offsets_read));
570
	for (blk = 1; offsets_read < total_offsets; blk++) {
571
		uint32_t nread;
572
573
		free(buf, M_GEOM);
574
		buf = g_read_data(
575
		    cp, blk * pp->sectorsize, pp->sectorsize, NULL);
576
		if (buf == NULL)
577
			goto err;
578
		nread = MIN(total_offsets - offsets_read,
579
		    pp->sectorsize / sizeof(uint64_t));
580
		DPRINTF(("%s: %u offsets read from sector %d\n",
581
		    gp->name, nread, blk));
582
		for (i = 0; i < nread; i++) {
583
			sc->offsets[offsets_read + i] =
584
			    be64toh(((uint64_t *) buf)[i]);
585
		}
586
		offsets_read += nread;
572
	}
587
	}
573
	free(buf, M_GEOM);
588
	free(buf, M_GEOM);
574
	DPRINTF(("%s: done reading offsets\n", gp->name));
589
	DPRINTF(("%s: done reading offsets\n", gp->name));

Return to bug 199476