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 *
| 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: head/sys/geom/geom_sunlabel.c 113432 2003-04-13 09:02:06Z phk $
| 35 * $FreeBSD: head/sys/geom/geom_sunlabel.c 113819 2003-04-21 19:54:11Z phk $
|
36 */ 37 38 39#include <sys/param.h> 40#include <sys/endian.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/conf.h> 44#include <sys/bio.h> 45#include <sys/malloc.h> 46#include <sys/lock.h> 47#include <sys/mutex.h>
| 36 */ 37 38 39#include <sys/param.h> 40#include <sys/endian.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/conf.h> 44#include <sys/bio.h> 45#include <sys/malloc.h> 46#include <sys/lock.h> 47#include <sys/mutex.h>
|
| 48#include <sys/sun_disklabel.h>
|
48#include <geom/geom.h> 49#include <geom/geom_slice.h> 50#include <machine/endian.h> 51 52#define SUNLABEL_CLASS_NAME "SUN" 53 54struct g_sunlabel_softc { 55 int sectorsize; 56 int nheads; 57 int nsects; 58 int nalt; 59}; 60 61static int 62g_sunlabel_modify(struct g_geom *gp, struct g_sunlabel_softc *ms, u_char *sec0) 63{ 64 int i, error; 65 u_int u, v, csize;
| 49#include <geom/geom.h> 50#include <geom/geom_slice.h> 51#include <machine/endian.h> 52 53#define SUNLABEL_CLASS_NAME "SUN" 54 55struct g_sunlabel_softc { 56 int sectorsize; 57 int nheads; 58 int nsects; 59 int nalt; 60}; 61 62static int 63g_sunlabel_modify(struct g_geom *gp, struct g_sunlabel_softc *ms, u_char *sec0) 64{ 65 int i, error; 66 u_int u, v, csize;
|
| 67 struct sun_disklabel sl;
|
66
| 68
|
67 /* The second last short is a magic number */ 68 if (be16dec(sec0 + 508) != 0xdabe) 69 return (EBUSY);
| 69 error = sunlabel_dec(sec0, &sl); 70 if (error) 71 return (error);
|
70
| 72
|
71 /* The shortword parity of the entire thing must be even */ 72 u = 0; 73 for (i = 0; i < 512; i += 2) 74 u ^= be16dec(sec0 + i); 75 if (u != 0) 76 return(EBUSY);
| 73 csize = sl.sl_ntracks * sl.sl_nsectors;
|
77
| 74
|
78 csize = be16dec(sec0 + 436) * be16dec(sec0 + 438); 79 80 for (i = 0; i < 8; i++) { 81 v = be32dec(sec0 + 444 + i * 8); 82 u = be32dec(sec0 + 448 + i * 8);
| 75 for (i = 0; i < SUN_NPART; i++) { 76 v = sl.sl_part[i].sdkp_cyloffset; 77 u = sl.sl_part[i].sdkp_nsectors;
|
83 g_topology_lock(); 84 error = g_slice_config(gp, i, G_SLICE_CONFIG_CHECK, 85 ((off_t)v * csize) << 9ULL, 86 ((off_t)u) << 9ULL, 87 ms->sectorsize, 88 "%s%c", gp->name, 'a' + i); 89 g_topology_unlock(); 90 if (error) 91 return (error); 92 }
| 78 g_topology_lock(); 79 error = g_slice_config(gp, i, G_SLICE_CONFIG_CHECK, 80 ((off_t)v * csize) << 9ULL, 81 ((off_t)u) << 9ULL, 82 ms->sectorsize, 83 "%s%c", gp->name, 'a' + i); 84 g_topology_unlock(); 85 if (error) 86 return (error); 87 }
|
93 for (i = 0; i < 8; i++) { 94 v = be32dec(sec0 + 444 + i * 8); 95 u = be32dec(sec0 + 448 + i * 8);
| 88 for (i = 0; i < SUN_NPART; i++) { 89 v = sl.sl_part[i].sdkp_cyloffset; 90 u = sl.sl_part[i].sdkp_nsectors;
|
96 g_topology_lock(); 97 g_slice_config(gp, i, G_SLICE_CONFIG_SET, 98 ((off_t)v * csize) << 9ULL, 99 ((off_t)u) << 9ULL, 100 ms->sectorsize, 101 "%s%c", gp->name, 'a' + i); 102 g_topology_unlock(); 103 }
| 91 g_topology_lock(); 92 g_slice_config(gp, i, G_SLICE_CONFIG_SET, 93 ((off_t)v * csize) << 9ULL, 94 ((off_t)u) << 9ULL, 95 ms->sectorsize, 96 "%s%c", gp->name, 'a' + i); 97 g_topology_unlock(); 98 }
|
104 ms->nalt = be16dec(sec0 + 434); 105 ms->nheads = be16dec(sec0 + 436); 106 ms->nsects = be16dec(sec0 + 438);
| 99 ms->nalt = sl.sl_acylinders; 100 ms->nheads = sl.sl_ntracks; 101 ms->nsects = sl.sl_nsectors;
|
107 108 return (0); 109} 110 111static int 112g_sunlabel_start(struct bio *bp) 113{ 114 struct g_geom *gp; 115 struct g_sunlabel_softc *ms; 116 struct g_slicer *gsp; 117 118 gp = bp->bio_to->geom; 119 gsp = gp->softc; 120 ms = gsp->softc; 121 return (0); 122} 123 124static void 125g_sunlabel_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp) 126{ 127 struct g_slicer *gsp; 128 struct g_sunlabel_softc *ms; 129 130 gsp = gp->softc; 131 ms = gsp->softc; 132 g_slice_dumpconf(sb, indent, gp, cp, pp); 133 if (indent == NULL) { 134 sbuf_printf(sb, " sc %u hd %u alt %u", 135 ms->nsects, ms->nheads, ms->nalt); 136 } 137} 138 139static struct g_geom * 140g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags) 141{ 142 struct g_geom *gp; 143 struct g_consumer *cp;
| 102 103 return (0); 104} 105 106static int 107g_sunlabel_start(struct bio *bp) 108{ 109 struct g_geom *gp; 110 struct g_sunlabel_softc *ms; 111 struct g_slicer *gsp; 112 113 gp = bp->bio_to->geom; 114 gsp = gp->softc; 115 ms = gsp->softc; 116 return (0); 117} 118 119static void 120g_sunlabel_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp) 121{ 122 struct g_slicer *gsp; 123 struct g_sunlabel_softc *ms; 124 125 gsp = gp->softc; 126 ms = gsp->softc; 127 g_slice_dumpconf(sb, indent, gp, cp, pp); 128 if (indent == NULL) { 129 sbuf_printf(sb, " sc %u hd %u alt %u", 130 ms->nsects, ms->nheads, ms->nalt); 131 } 132} 133 134static struct g_geom * 135g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags) 136{ 137 struct g_geom *gp; 138 struct g_consumer *cp;
|
144 int error, i, npart;
| 139 int error, npart;
|
145 u_char *buf; 146 struct g_sunlabel_softc *ms; 147 off_t mediasize; 148 struct g_slicer *gsp; 149 150 g_trace(G_T_TOPOLOGY, "g_sunlabel_taste(%s,%s)", mp->name, pp->name); 151 g_topology_assert(); 152 if (flags == G_TF_NORMAL && 153 !strcmp(pp->geom->class->name, SUNLABEL_CLASS_NAME)) 154 return (NULL); 155 gp = g_slice_new(mp, 8, pp, &cp, &ms, sizeof *ms, g_sunlabel_start); 156 if (gp == NULL) 157 return (NULL); 158 gsp = gp->softc; 159 g_topology_unlock(); 160 gp->dumpconf = g_sunlabel_dumpconf; 161 npart = 0; 162 do { 163 if (gp->rank != 2 && flags == G_TF_NORMAL) 164 break; 165 ms->sectorsize = cp->provider->sectorsize; 166 if (ms->sectorsize < 512) 167 break; 168 mediasize = cp->provider->mediasize; 169 buf = g_read_data(cp, 0, ms->sectorsize, &error); 170 if (buf == NULL || error != 0) 171 break;
| 140 u_char *buf; 141 struct g_sunlabel_softc *ms; 142 off_t mediasize; 143 struct g_slicer *gsp; 144 145 g_trace(G_T_TOPOLOGY, "g_sunlabel_taste(%s,%s)", mp->name, pp->name); 146 g_topology_assert(); 147 if (flags == G_TF_NORMAL && 148 !strcmp(pp->geom->class->name, SUNLABEL_CLASS_NAME)) 149 return (NULL); 150 gp = g_slice_new(mp, 8, pp, &cp, &ms, sizeof *ms, g_sunlabel_start); 151 if (gp == NULL) 152 return (NULL); 153 gsp = gp->softc; 154 g_topology_unlock(); 155 gp->dumpconf = g_sunlabel_dumpconf; 156 npart = 0; 157 do { 158 if (gp->rank != 2 && flags == G_TF_NORMAL) 159 break; 160 ms->sectorsize = cp->provider->sectorsize; 161 if (ms->sectorsize < 512) 162 break; 163 mediasize = cp->provider->mediasize; 164 buf = g_read_data(cp, 0, ms->sectorsize, &error); 165 if (buf == NULL || error != 0) 166 break;
|
172 173 if (bootverbose) { 174 g_hexdump(buf, 128); 175 for (i = 0; i < 8; i++) { 176 printf("part %d %u %u\n", i, 177 be32dec(buf + 444 + i * 8), 178 be32dec(buf + 448 + i * 8)); 179 } 180 printf("v_version = %d\n", be32dec(buf + 128)); 181 printf("v_nparts = %d\n", be16dec(buf + 140)); 182 for (i = 0; i < 8; i++) { 183 printf("v_part[%d] = %d %d\n", 184 i, be16dec(buf + 142 + i * 4), 185 be16dec(buf + 144 + i * 4)); 186 } 187 printf("v_sanity %x\n", be32dec(buf + 186)); 188 printf("v_version = %d\n", be32dec(buf + 128)); 189 printf("v_rpm %d\n", be16dec(buf + 420)); 190 printf("v_totalcyl %d\n", be16dec(buf + 422)); 191 printf("v_cyl %d\n", be16dec(buf + 432)); 192 printf("v_alt %d\n", be16dec(buf + 434)); 193 printf("v_head %d\n", be16dec(buf + 436)); 194 printf("v_sec %d\n", be16dec(buf + 438)); 195 }
| |
196 197 g_sunlabel_modify(gp, ms, buf); 198 199 break; 200 } while (0); 201 g_topology_lock(); 202 g_access_rel(cp, -1, 0, 0); 203 if (LIST_EMPTY(&gp->provider)) { 204 g_std_spoiled(cp); 205 return (NULL); 206#ifdef notyet 207 } else { 208 g_slice_conf_hot(gp, 0, 0, ms->sectorsize); 209#endif 210 } 211 return (gp); 212} 213 214static struct g_class g_sunlabel_class = { 215 .name = SUNLABEL_CLASS_NAME, 216 .taste = g_sunlabel_taste, 217 G_CLASS_INITIALIZER 218}; 219 220DECLARE_GEOM_CLASS(g_sunlabel_class, g_sunlabel);
| 167 168 g_sunlabel_modify(gp, ms, buf); 169 170 break; 171 } while (0); 172 g_topology_lock(); 173 g_access_rel(cp, -1, 0, 0); 174 if (LIST_EMPTY(&gp->provider)) { 175 g_std_spoiled(cp); 176 return (NULL); 177#ifdef notyet 178 } else { 179 g_slice_conf_hot(gp, 0, 0, ms->sectorsize); 180#endif 181 } 182 return (gp); 183} 184 185static struct g_class g_sunlabel_class = { 186 .name = SUNLABEL_CLASS_NAME, 187 .taste = g_sunlabel_taste, 188 G_CLASS_INITIALIZER 189}; 190 191DECLARE_GEOM_CLASS(g_sunlabel_class, g_sunlabel);
|