Deleted Added
full compact
1/*-
2 * Copyright (c) 2010-2012 Aleksandr Rybalko
3 * Copyright (c) 2004 Max Khon
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

29 * GEOM UNCOMPRESS module - simple decompression module for use with read-only
30 * copressed images maked by mkuzip(8) or mkulzma(8) utilities.
31 *
32 * To enable module in kernel config, put this line:
33 * device geom_uncompress
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: stable/10/sys/geom/uncompress/g_uncompress.c 283900 2015-06-02 02:05:32Z ae $");
37__FBSDID("$FreeBSD: stable/10/sys/geom/uncompress/g_uncompress.c 266220 2014-05-16 14:28:55Z loos $");
38
39#include <sys/param.h>
40#include <sys/bio.h>
41#include <sys/endian.h>
42#include <sys/errno.h>
43#include <sys/kernel.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>

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

459static struct g_geom *
460g_uncompress_taste(struct g_class *mp, struct g_provider *pp, int flags)
461{
462 struct cloop_header *header;
463 struct g_uncompress_softc *sc;
464 struct g_provider *pp2;
465 struct g_consumer *cp;
466 struct g_geom *gp;
467 uint64_t *offsets;
468 uint32_t i, r, total, total_offsets, type;
467 uint32_t i, total_offsets, type;
468 uint8_t *buf;
469 int error;
470
471 g_trace(G_T_TOPOLOGY, "%s(%s,%s)", __func__, mp->name, pp->name);
472 g_topology_assert();
473
474 /* Skip providers that are already open for writing. */
475 if (pp->acw > 0)

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

494 g_topology_unlock();
495
496 /*
497 * Read cloop header, look for CLOOP magic, perform
498 * other validity checks.
499 */
500 DPRINTF(("%s: media sectorsize %u, mediasize %jd\n",
501 gp->name, pp->sectorsize, (intmax_t)pp->mediasize));
503 total = roundup(sizeof(struct cloop_header), pp->sectorsize);
504 buf = g_read_data(cp, 0, total, NULL);
502 i = roundup(sizeof(struct cloop_header), pp->sectorsize);
503 buf = g_read_data(cp, 0, i, NULL);
504 if (buf == NULL)
505 goto err;
506 header = (struct cloop_header *) buf;
507 if (strncmp(header->magic, CLOOP_MAGIC_START,
508 sizeof(CLOOP_MAGIC_START) - 1) != 0) {
509 DPRINTF(("%s: no CLOOP magic\n", gp->name));
510 goto err;
511 }

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

552 }
553 total_offsets = sc->nblocks + 1;
554 if (sizeof(struct cloop_header) +
555 total_offsets * sizeof(uint64_t) > pp->mediasize) {
556 printf("%s: media too small for %u blocks\n",
557 gp->name, sc->nblocks);
558 goto err;
559 }
561 g_free(buf);
560 free(buf, M_GEOM);
561
563 sc->offsets = malloc(total_offsets * sizeof(uint64_t),
564 M_GEOM_UNCOMPRESS, M_WAITOK | M_ZERO);
565 total = roundup((sizeof(struct cloop_header) +
562 i = roundup((sizeof(struct cloop_header) +
563 total_offsets * sizeof(uint64_t)), pp->sectorsize);
567#define RSZ ((total - r) > MAXPHYS ? MAXPHYS: (total - r))
568 for (r = 0, i = 0; r < total; r += MAXPHYS) {
569 buf = g_read_data(cp, r, RSZ, &error);
570 if (buf == NULL) {
571 free(sc->offsets, M_GEOM_UNCOMPRESS);
572 goto err;
573 }
574 offsets = (uint64_t *)buf;
575 if (r == 0)
576 offsets +=
577 sizeof(struct cloop_header) / sizeof(uint64_t);
578 for (; i < total_offsets && offsets < (uint64_t *)(buf + RSZ);
579 i++, offsets++)
580 sc->offsets[i] = be64toh(*offsets);
581 g_free(buf);
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);
569 for (i = 0; i <= total_offsets; i++) {
570 sc->offsets[i] = be64toh(((uint64_t *)
571 (buf+sizeof(struct cloop_header)))[i]);
572 }
583#undef RSZ
584 buf = NULL;
573 free(buf, M_GEOM);
574 DPRINTF(("%s: done reading offsets\n", gp->name));
575 mtx_init(&sc->last_mtx, "geom_uncompress cache", NULL, MTX_DEF);
576 sc->last_blk = -1;
577 sc->last_buf = malloc(sc->blksz, M_GEOM_UNCOMPRESS, M_WAITOK);
578 sc->req_total = 0;
579 sc->req_cached = 0;
580
581 switch (sc->type) {

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

613 pp2->stripeoffset, pp2->stripesize, pp2->flags));
614 printf("%s: %u x %u blocks\n", gp->name, sc->nblocks, sc->blksz);
615 return (gp);
616
617err:
618 g_topology_lock();
619 g_access(cp, -1, 0, 0);
620 if (buf != NULL)
632 g_free(buf);
621 free(buf, M_GEOM);
622 if (gp->softc != NULL) {
623 g_uncompress_softc_free(gp->softc, NULL);
624 gp->softc = NULL;
625 }
626 g_detach(cp);
627 g_destroy_consumer(cp);
628 g_destroy_geom(gp);
629

--- 44 unchanged lines hidden ---