The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/geom/geom_sunlabel.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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
    9  * DARPA CHATS research program.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. The names of the authors may not be used to endorse or promote
   20  *    products derived from this software without specific prior written
   21  *    permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   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: releng/5.0/sys/geom/geom_sunlabel.c 108141 2002-12-20 21:52:03Z phk $
   36  */
   37 
   38 
   39 #include <sys/param.h>
   40 #ifndef _KERNEL
   41 #include <stdio.h>
   42 #include <string.h>
   43 #include <stdlib.h>
   44 #include <signal.h>
   45 #include <err.h>
   46 #else
   47 #include <sys/systm.h>
   48 #include <sys/kernel.h>
   49 #include <sys/conf.h>
   50 #include <sys/bio.h>
   51 #include <sys/malloc.h>
   52 #include <sys/lock.h>
   53 #include <sys/mutex.h>
   54 #endif
   55 #include <geom/geom.h>
   56 #include <geom/geom_slice.h>
   57 #include <machine/endian.h>
   58 
   59 #define SUNLABEL_CLASS_NAME "SUN"
   60 
   61 struct g_sunlabel_softc {
   62         int nheads;
   63         int nsects;
   64         int nalt;
   65 };
   66 
   67 static int
   68 g_sunlabel_start(struct bio *bp)
   69 {
   70         struct g_geom *gp;
   71         struct g_sunlabel_softc *ms;
   72         struct g_slicer *gsp;
   73 
   74         gp = bp->bio_to->geom;
   75         gsp = gp->softc;
   76         ms = gsp->softc;
   77         return (0);
   78 }
   79 
   80 static void
   81 g_sunlabel_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp)
   82 {
   83         struct g_slicer *gsp;
   84         struct g_sunlabel_softc *ms;
   85 
   86         gsp = gp->softc;
   87         ms = gsp->softc;
   88         g_slice_dumpconf(sb, indent, gp, cp, pp);
   89         if (indent == NULL) {
   90                 sbuf_printf(sb, " sc %u hd %u alt %u",
   91                     ms->nsects, ms->nheads, ms->nalt);
   92         }
   93 }
   94 
   95 static struct g_geom *
   96 g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags)
   97 {
   98         struct g_geom *gp;
   99         struct g_consumer *cp;
  100         int error, i, npart;
  101         u_char *buf;
  102         struct g_sunlabel_softc *ms;
  103         u_int sectorsize, u, v, csize;
  104         off_t mediasize;
  105         struct g_slicer *gsp;
  106 
  107         g_trace(G_T_TOPOLOGY, "g_sunlabel_taste(%s,%s)", mp->name, pp->name);
  108         g_topology_assert();
  109         if (flags == G_TF_NORMAL &&
  110             !strcmp(pp->geom->class->name, SUNLABEL_CLASS_NAME))
  111                 return (NULL);
  112         gp = g_slice_new(mp, 8, pp, &cp, &ms, sizeof *ms, g_sunlabel_start);
  113         if (gp == NULL)
  114                 return (NULL);
  115         gsp = gp->softc;
  116         g_topology_unlock();
  117         gp->dumpconf = g_sunlabel_dumpconf;
  118         npart = 0;
  119         while (1) {     /* a trick to allow us to use break */
  120                 if (gp->rank != 2 && flags == G_TF_NORMAL)
  121                         break;
  122                 sectorsize = cp->provider->sectorsize;
  123                 if (sectorsize < 512)
  124                         break;
  125                 gsp->frontstuff = 16 * sectorsize;
  126                 mediasize = cp->provider->mediasize;
  127                 buf = g_read_data(cp, 0, sectorsize, &error);
  128                 if (buf == NULL || error != 0)
  129                         break;
  130 
  131                 /* The second last short is a magic number */
  132                 if (g_dec_be2(buf + 508) != 0xdabe)
  133                         break;
  134                 /* The shortword parity of the entire thing must be even */
  135                 u = 0;
  136                 for (i = 0; i < 512; i += 2)
  137                         u ^= g_dec_be2(buf + i);
  138                 if (u != 0)
  139                         break;
  140                 if (bootverbose) {
  141                         g_hexdump(buf, 128);
  142                         for (i = 0; i < 8; i++) {
  143                                 printf("part %d %u %u\n", i,
  144                                     g_dec_be4(buf + 444 + i * 8),
  145                                     g_dec_be4(buf + 448 + i * 8));
  146                         }
  147                         printf("v_version = %d\n", g_dec_be4(buf + 128));
  148                         printf("v_nparts = %d\n", g_dec_be2(buf + 140));
  149                         for (i = 0; i < 8; i++) {
  150                                 printf("v_part[%d] = %d %d\n",
  151                                     i, g_dec_be2(buf + 142 + i * 4),
  152                                     g_dec_be2(buf + 144 + i * 4));
  153                         }
  154                         printf("v_sanity %x\n", g_dec_be4(buf + 186));
  155                         printf("v_version = %d\n", g_dec_be4(buf + 128));
  156                         printf("v_rpm %d\n", g_dec_be2(buf + 420));
  157                         printf("v_totalcyl %d\n", g_dec_be2(buf + 422));
  158                         printf("v_cyl %d\n", g_dec_be2(buf + 432));
  159                         printf("v_alt %d\n", g_dec_be2(buf + 434));
  160                         printf("v_head %d\n", g_dec_be2(buf + 436));
  161                         printf("v_sec %d\n", g_dec_be2(buf + 438));
  162                 }
  163                 ms->nalt = g_dec_be2(buf + 434);
  164                 ms->nheads = g_dec_be2(buf + 436);
  165                 ms->nsects = g_dec_be2(buf + 438);
  166 
  167                 csize = ms->nheads * ms->nsects;
  168 
  169                 for (i = 0; i < 8; i++) {
  170                         v = g_dec_be4(buf + 444 + i * 8);
  171                         u = g_dec_be4(buf + 448 + i * 8);
  172                         if (u == 0)
  173                                 continue;
  174                         npart++;
  175                         g_topology_lock();
  176                         g_slice_config(gp, i, G_SLICE_CONFIG_SET,
  177                             ((off_t)v * csize) << 9ULL,
  178                             ((off_t)u) << 9ULL,
  179                             sectorsize,
  180                             "%s%c", pp->name, 'a' + i);
  181                         g_topology_unlock();
  182                 }
  183                 break;
  184         }
  185         g_topology_lock();
  186         g_access_rel(cp, -1, 0, 0);
  187         if (LIST_EMPTY(&gp->provider)) {
  188                 g_std_spoiled(cp);
  189                 return (NULL);
  190         }
  191         return (gp);
  192 }
  193 
  194 static struct g_class g_sunlabel_class = {
  195         SUNLABEL_CLASS_NAME,
  196         g_sunlabel_taste,
  197         NULL,
  198         G_CLASS_INITIALIZER
  199 };
  200 
  201 DECLARE_GEOM_CLASS(g_sunlabel_class, g_sunlabel);

Cache object: 55c6c372883d6c90599350f11e1406b1


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.