Author: loos
Date: Thu May  1 14:47:27 2014
New Revision: 265193
URL: http://svnweb.freebsd.org/changeset/base/265193

Log:
  Some style and whitespace fixes.  Reduce the difference between geom_uzip(4)
  and geom_uncompress(4).  Now, they produce an almost clean diff(1) output.
  
  Remove a duplicated variable from g_uncompress.c and an unnecessary header
  from g_uzip.c.
  
  No functional changes.

Modified:
  head/sys/geom/uncompress/g_uncompress.c
  head/sys/geom/uzip/g_uzip.c

Modified: head/sys/geom/uncompress/g_uncompress.c
==============================================================================
--- head/sys/geom/uncompress/g_uncompress.c     Thu May  1 14:19:14 2014        
(r265192)
+++ head/sys/geom/uncompress/g_uncompress.c     Thu May  1 14:47:27 2014        
(r265193)
@@ -116,7 +116,7 @@ g_uncompress_softc_free(struct g_uncompr
        }
        if (sc->offsets != NULL) {
                free(sc->offsets, M_GEOM_UNCOMPRESS);
-               sc->offsets = 0;
+               sc->offsets = NULL;
        }
 
        switch (sc->type) {
@@ -150,6 +150,7 @@ z_alloc(void *nil, u_int type, u_int siz
        void *ptr;
 
        ptr = malloc(type * size, M_GEOM_UNCOMPRESS, M_NOWAIT);
+
        return (ptr);
 }
 
@@ -221,11 +222,11 @@ g_uncompress_done(struct bio *bp)
            (intmax_t)bp2->bio_offset, sc->blksz, bsize));
 
        for (i = start_blk; upos < bp2->bio_length; i++) {
-               off_t len, dlen, ulen, uoff;
+               off_t len, ulen, uoff;
 
                uoff = i == start_blk ? bp2->bio_offset % sc->blksz : 0;
                ulen = MIN(sc->blksz - uoff, bp2->bio_length - upos);
-               dlen = len = sc->offsets[i + 1] - sc->offsets[i];
+               len = sc->offsets[i + 1] - sc->offsets[i];
 
                DPRINTF((
                    "%s: done: inflate block %d, start %ju, end %ju len %jd\n",
@@ -239,19 +240,17 @@ g_uncompress_done(struct bio *bp)
                        bp2->bio_completed += ulen;
                        continue;
                }
-
                if (len > iolen) {
                        DPRINTF(("%s: done: early termination: len (%jd) > "
                            "iolen (%jd)\n",
                            gp->name, (intmax_t)len, (intmax_t)iolen));
                        break;
                }
-
                mtx_lock(&sc->last_mtx);
 
 #ifdef GEOM_UNCOMPRESS_DEBUG
                if (g_debugflags & 32)
-                       hexdump(bp->bio_data + pos, dlen, 0, 0);
+                       hexdump(bp->bio_data + pos, len, 0, 0);
 #endif
 
                switch (sc->type) {
@@ -259,7 +258,7 @@ g_uncompress_done(struct bio *bp)
                        sc->b->in = bp->bio_data + pos;
                        sc->b->out = sc->last_buf;
                        sc->b->in_pos = sc->b->out_pos = 0;
-                       sc->b->in_size = dlen;
+                       sc->b->in_size = len;
                        sc->b->out_size = (size_t)-1;
 
                        err = (xz_dec_run(sc->s, sc->b) != XZ_STREAM_END) ?
@@ -268,7 +267,7 @@ g_uncompress_done(struct bio *bp)
                        break;
                case GEOM_UZIP:
                        sc->zs->next_in = bp->bio_data + pos;
-                       sc->zs->avail_in = dlen;
+                       sc->zs->avail_in = len;
                        sc->zs->next_out = sc->last_buf;
                        sc->zs->avail_out = sc->blksz;
 
@@ -328,7 +327,6 @@ g_uncompress_start(struct bio *bp)
        uint32_t start_blk, end_blk;
        size_t bsize;
 
-
        pp = bp->bio_to;
        gp = pp->geom;
        DPRINTF(("%s: start (%d:%s) to %s off=%jd len=%jd\n",
@@ -347,10 +345,8 @@ g_uncompress_start(struct bio *bp)
 
        start_blk = bp->bio_offset / sc->blksz;
        end_blk   = howmany(bp->bio_offset + bp->bio_length, sc->blksz);
-       KASSERT(start_blk < sc->nblocks,
-               ("start_blk out of range"));
-       KASSERT(end_blk <= sc->nblocks,
-               ("end_blk out of range"));
+       KASSERT(start_blk < sc->nblocks, ("start_blk out of range"));
+       KASSERT(end_blk <= sc->nblocks, ("end_blk out of range"));
 
        sc->req_total++;
        if (start_blk + 1 == end_blk) {
@@ -385,9 +381,7 @@ g_uncompress_start(struct bio *bp)
            gp->name, start_blk, end_blk,
            pp->name, pp->sectorsize, (intmax_t)pp->mediasize,
            pp2->name, pp2->sectorsize, (intmax_t)pp2->mediasize));
-
        bsize = pp2->sectorsize;
-
        bp2->bio_done = g_uncompress_done;
        bp2->bio_offset = rounddown(sc->offsets[start_blk], bsize);
        while (1) {
@@ -401,14 +395,12 @@ g_uncompress_start(struct bio *bp)
                    "%s: bio_length (%jd) > MAXPHYS: lowering end_blk to %u\n",
                    gp->name, (intmax_t)bp2->bio_length, end_blk));
        }
-
        DPRINTF(("%s: start %jd + %jd -> %ju + %ju -> %jd + %jd\n",
            gp->name,
            (intmax_t)bp->bio_offset, (intmax_t)bp->bio_length,
            (uintmax_t)sc->offsets[start_blk],
            (uintmax_t)sc->offsets[end_blk] - sc->offsets[start_blk],
            (intmax_t)bp2->bio_offset, (intmax_t)bp2->bio_length));
-
        bp2->bio_data = malloc(bp2->bio_length, M_GEOM_UNCOMPRESS, M_NOWAIT);
        if (bp2->bio_data == NULL) {
                g_destroy_bio(bp2);
@@ -425,8 +417,7 @@ g_uncompress_orphan(struct g_consumer *c
 {
        struct g_geom *gp;
 
-       g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp,
-               cp->provider->name);
+       g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp, cp->provider->name);
        g_topology_assert();
 
        gp = cp->geom;
@@ -508,15 +499,13 @@ g_uncompress_taste(struct g_class *mp, s
         */
        DPRINTF(("%s: media sectorsize %u, mediasize %jd\n",
            gp->name, pp->sectorsize, (intmax_t)pp->mediasize));
-
        i = roundup(sizeof(struct cloop_header), pp->sectorsize);
        buf = g_read_data(cp, 0, i, NULL);
        if (buf == NULL)
                goto err;
-
        header = (struct cloop_header *) buf;
        if (strncmp(header->magic, CLOOP_MAGIC_START,
-                   sizeof(CLOOP_MAGIC_START) - 1) != 0) {
+           sizeof(CLOOP_MAGIC_START) - 1) != 0) {
                DPRINTF(("%s: no CLOOP magic\n", gp->name));
                goto err;
        }
@@ -571,7 +560,7 @@ g_uncompress_taste(struct g_class *mp, s
        free(buf, M_GEOM);
 
        i = roundup((sizeof(struct cloop_header) +
-               total_offsets * sizeof(uint64_t)),pp->sectorsize);
+           total_offsets * sizeof(uint64_t)), pp->sectorsize);
        buf = g_read_data(cp, 0, i, NULL);
        if (buf == NULL)
                goto err;
@@ -581,6 +570,7 @@ g_uncompress_taste(struct g_class *mp, s
                sc->offsets[i] = be64toh(((uint64_t *)
                    (buf+sizeof(struct cloop_header)))[i]);
        }
+       free(buf, M_GEOM);
        DPRINTF(("%s: done reading offsets\n", gp->name));
        mtx_init(&sc->last_mtx, "geom_uncompress cache", NULL, MTX_DEF);
        sc->last_blk = -1;
@@ -615,15 +605,13 @@ g_uncompress_taste(struct g_class *mp, s
                pp2->stripeoffset = pp->stripeoffset;
        }
        g_error_provider(pp2, 0);
-       free(buf, M_GEOM);
        g_access(cp, -1, 0, 0);
 
        DPRINTF(("%s: taste ok (%d, %jd), (%d, %d), %x\n",
            gp->name,
            pp2->sectorsize, (intmax_t)pp2->mediasize,
            pp2->stripeoffset, pp2->stripesize, pp2->flags));
-       printf("%s: %u x %u blocks\n",
-           gp->name, sc->nblocks, sc->blksz);
+       printf("%s: %u x %u blocks\n", gp->name, sc->nblocks, sc->blksz);
        return (gp);
 
 err:
@@ -638,6 +626,7 @@ err:
        g_detach(cp);
        g_destroy_consumer(cp);
        g_destroy_geom(gp);
+
        return (NULL);
 }
 
@@ -664,6 +653,7 @@ g_uncompress_destroy_geom(struct gctl_re
        g_uncompress_softc_free(gp->softc, gp);
        gp->softc = NULL;
        g_wither_geom(gp, ENXIO);
+
        return (0);
 }
 

Modified: head/sys/geom/uzip/g_uzip.c
==============================================================================
--- head/sys/geom/uzip/g_uzip.c Thu May  1 14:19:14 2014        (r265192)
+++ head/sys/geom/uzip/g_uzip.c Thu May  1 14:47:27 2014        (r265193)
@@ -36,7 +36,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/malloc.h>
 #include <sys/systm.h>
-#include <sys/sysctl.h>
 
 #include <geom/geom.h>
 #include <net/zlib.h>
@@ -45,19 +44,19 @@ FEATURE(geom_uzip, "GEOM uzip read-only 
 
 #undef GEOM_UZIP_DEBUG
 #ifdef GEOM_UZIP_DEBUG
-#define DPRINTF(a)     printf a
+#define        DPRINTF(a)      printf a
 #else
-#define DPRINTF(a)
+#define        DPRINTF(a)
 #endif
 
 static MALLOC_DEFINE(M_GEOM_UZIP, "geom_uzip", "GEOM UZIP data structures");
 
-#define UZIP_CLASS_NAME        "UZIP"
+#define        UZIP_CLASS_NAME "UZIP"
 
 /*
  * Maximum allowed valid block size (to prevent foot-shooting)
  */
-#define MAX_BLKSZ      (MAXPHYS - MAXPHYS / 1000 - 12)
+#define        MAX_BLKSZ       (MAXPHYS - MAXPHYS / 1000 - 12)
 
 /*
  * Integer values (block size, number of blocks, offsets)
@@ -65,7 +64,7 @@ static MALLOC_DEFINE(M_GEOM_UZIP, "geom_
  * and in native order in struct g_uzip_softc
  */
 
-#define CLOOP_MAGIC_LEN 128
+#define        CLOOP_MAGIC_LEN 128
 static char CLOOP_MAGIC_START[] = "#!/bin/sh\n";
 
 struct cloop_header {
@@ -89,12 +88,15 @@ struct g_uzip_softc {
 static void
 g_uzip_softc_free(struct g_uzip_softc *sc, struct g_geom *gp)
 {
+
        if (gp != NULL) {
                printf("%s: %d requests, %d cached\n",
                    gp->name, sc->req_total, sc->req_cached);
        }
-       if (sc->offsets != NULL)
+       if (sc->offsets != NULL) {
                free(sc->offsets, M_GEOM_UZIP);
+               sc->offsets = NULL;
+       }
        mtx_destroy(&sc->last_mtx);
        free(sc->last_buf, M_GEOM_UZIP);
        free(sc, M_GEOM_UZIP);
@@ -106,12 +108,14 @@ z_alloc(void *nil, u_int type, u_int siz
        void *ptr;
 
        ptr = malloc(type * size, M_GEOM_UZIP, M_NOWAIT);
-       return ptr;
+
+       return (ptr);
 }
 
 static void
 z_free(void *nil, void *ptr)
 {
+
        free(ptr, M_GEOM_UZIP);
 }
 
@@ -258,10 +262,8 @@ g_uzip_start(struct bio *bp)
 
        start_blk = bp->bio_offset / sc->blksz;
        end_blk = (bp->bio_offset + bp->bio_length + sc->blksz - 1) / sc->blksz;
-       KASSERT(start_blk < sc->nblocks,
-               ("start_blk out of range"));
-       KASSERT(end_blk <= sc->nblocks,
-               ("end_blk out of range"));
+       KASSERT(start_blk < sc->nblocks, ("start_blk out of range"));
+       KASSERT(end_blk <= sc->nblocks, ("end_blk out of range"));
 
        sc->req_total++;
        if (start_blk + 1 == end_blk) {
@@ -331,7 +333,7 @@ g_uzip_orphan(struct g_consumer *cp)
 {
        struct g_geom *gp;
 
-       g_trace(G_T_TOPOLOGY, "g_uzip_orphan(%p/%s)", cp, cp->provider->name);
+       g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp, cp->provider->name);
        g_topology_assert();
 
        gp = cp->geom;
@@ -351,7 +353,7 @@ g_uzip_access(struct g_provider *pp, int
        KASSERT (cp != NULL, ("g_uzip_access but no consumer"));
 
        if (cp->acw + dw > 0)
-               return EROFS;
+               return (EROFS);
 
        return (g_access(cp, dr, dw, de));
 }
@@ -362,7 +364,7 @@ g_uzip_spoiled(struct g_consumer *cp)
        struct g_geom *gp;
 
        gp = cp->geom;
-       g_trace(G_T_TOPOLOGY, "g_uzip_spoiled(%p/%s)", cp, gp->name);
+       g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp, gp->name);
        g_topology_assert();
 
        g_uzip_softc_free(gp->softc, gp);
@@ -382,7 +384,7 @@ g_uzip_taste(struct g_class *mp, struct 
        struct g_provider *pp2;
        struct g_uzip_softc *sc;
 
-       g_trace(G_T_TOPOLOGY, "g_uzip_taste(%s,%s)", mp->name, pp->name);
+       g_trace(G_T_TOPOLOGY, "%s(%s,%s)", __func__, mp->name, pp->name);
        g_topology_assert();
 
        /* Skip providers that are already open for writing. */
@@ -418,7 +420,7 @@ g_uzip_taste(struct g_class *mp, struct 
                goto err;
        header = (struct cloop_header *) buf;
        if (strncmp(header->magic, CLOOP_MAGIC_START,
-                   sizeof(CLOOP_MAGIC_START) - 1) != 0) {
+           sizeof(CLOOP_MAGIC_START) - 1) != 0) {
                DPRINTF(("%s: no CLOOP magic\n", gp->name));
                goto err;
        }
@@ -447,7 +449,7 @@ g_uzip_taste(struct g_class *mp, struct 
        if (sizeof(struct cloop_header) +
            total_offsets * sizeof(uint64_t) > pp->mediasize) {
                printf("%s: media too small for %u blocks\n",
-                      gp->name, sc->nblocks);
+                   gp->name, sc->nblocks);
                goto err;
        }
        sc->offsets = malloc(
@@ -487,8 +489,8 @@ g_uzip_taste(struct g_class *mp, struct 
        pp2 = g_new_providerf(gp, "%s", gp->name);
        pp2->sectorsize = 512;
        pp2->mediasize = (off_t)sc->nblocks * sc->blksz;
-        pp2->stripesize = pp->stripesize;
-        pp2->stripeoffset = pp->stripeoffset;
+       pp2->stripesize = pp->stripesize;
+       pp2->stripeoffset = pp->stripeoffset;
        g_error_provider(pp2, 0);
        g_access(cp, -1, 0, 0);
 
@@ -496,8 +498,7 @@ g_uzip_taste(struct g_class *mp, struct 
            gp->name,
            pp2->sectorsize, (intmax_t)pp2->mediasize,
            pp2->stripeoffset, pp2->stripesize, pp2->flags));
-       printf("%s: %u x %u blocks\n",
-              gp->name, sc->nblocks, sc->blksz);
+       printf("%s: %u x %u blocks\n", gp->name, sc->nblocks, sc->blksz);
        return (gp);
 
 err:
@@ -512,6 +513,7 @@ err:
        g_detach(cp);
        g_destroy_consumer(cp);
        g_destroy_geom(gp);
+
        return (NULL);
 }
 
@@ -520,7 +522,7 @@ g_uzip_destroy_geom(struct gctl_req *req
 {
        struct g_provider *pp;
 
-       g_trace(G_T_TOPOLOGY, "g_uzip_destroy_geom(%s, %s)", mp->name, 
gp->name);
+       g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, gp->name);
        g_topology_assert();
 
        if (gp->softc == NULL) {
@@ -537,6 +539,7 @@ g_uzip_destroy_geom(struct gctl_req *req
        g_uzip_softc_free(gp->softc, gp);
        gp->softc = NULL;
        g_wither_geom(gp, ENXIO);
+
        return (0);
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to