Deleted Added
full compact
geom_sunlabel.c (113432) geom_sunlabel.c (113819)
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

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

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

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

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;

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

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;

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

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 &&

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

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 &&

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

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)) {

--- 17 unchanged lines hidden ---
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)) {

--- 17 unchanged lines hidden ---