Deleted Added
full compact
geom_pc98.c (94285) geom_pc98.c (94287)
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_pc98.c 94285 2002-04-09 15:17:59Z phk $
35 * $FreeBSD: head/sys/geom/geom_pc98.c 94287 2002-04-09 15:43:32Z 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 <sys/errno.h>
56#include <geom/geom.h>
57#include <geom/geom_slice.h>
58#include <machine/endian.h>
59
60#define PC98_CLASS_NAME "PC98-class"
61
62struct g_pc98_softc {
63 int foo;
64};
65
66static int
67g_pc98_start(struct bio *bp)
68{
69 struct g_geom *gp;
70 struct g_pc98_softc *ms;
71 struct g_slicer *gsp;
72
73 gp = bp->bio_to->geom;
74 gsp = gp->softc;
75 ms = gsp->softc;
76 return (0);
77}
78
79static void
80g_pc98_dumpconf(struct sbuf *sb, char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp)
81{
82
83 g_slice_dumpconf(sb, indent, gp, cp, pp);
84}
85
86static struct g_geom *
87g_pc98_taste(struct g_class *mp, struct g_provider *pp, int flags)
88{
89 struct g_geom *gp;
90 struct g_consumer *cp;
91 struct g_provider *pp2;
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 <sys/errno.h>
56#include <geom/geom.h>
57#include <geom/geom_slice.h>
58#include <machine/endian.h>
59
60#define PC98_CLASS_NAME "PC98-class"
61
62struct g_pc98_softc {
63 int foo;
64};
65
66static int
67g_pc98_start(struct bio *bp)
68{
69 struct g_geom *gp;
70 struct g_pc98_softc *ms;
71 struct g_slicer *gsp;
72
73 gp = bp->bio_to->geom;
74 gsp = gp->softc;
75 ms = gsp->softc;
76 return (0);
77}
78
79static void
80g_pc98_dumpconf(struct sbuf *sb, char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp)
81{
82
83 g_slice_dumpconf(sb, indent, gp, cp, pp);
84}
85
86static struct g_geom *
87g_pc98_taste(struct g_class *mp, struct g_provider *pp, int flags)
88{
89 struct g_geom *gp;
90 struct g_consumer *cp;
91 struct g_provider *pp2;
92 int error, i, j, npart;
92 int error, i, npart;
93 u_char *buf;
94 struct g_pc98_softc *ms;
95 u_int sectorsize, u, v;
96 u_int fwsect, fwhead;
97 off_t mediasize, start, length;
93 u_char *buf;
94 struct g_pc98_softc *ms;
95 u_int sectorsize, u, v;
96 u_int fwsect, fwhead;
97 off_t mediasize, start, length;
98 struct g_slicer *gsp;
98
99 g_trace(G_T_TOPOLOGY, "g_pc98_taste(%s,%s)", mp->name, pp->name);
100 g_topology_assert();
101 if (flags == G_TF_NORMAL &&
102 !strcmp(pp->geom->class->name, PC98_CLASS_NAME))
103 return (NULL);
104 gp = g_slice_new(mp, 8, pp, &cp, &ms, sizeof *ms, g_pc98_start);
105 if (gp == NULL)
106 return (NULL);
99
100 g_trace(G_T_TOPOLOGY, "g_pc98_taste(%s,%s)", mp->name, pp->name);
101 g_topology_assert();
102 if (flags == G_TF_NORMAL &&
103 !strcmp(pp->geom->class->name, PC98_CLASS_NAME))
104 return (NULL);
105 gp = g_slice_new(mp, 8, pp, &cp, &ms, sizeof *ms, g_pc98_start);
106 if (gp == NULL)
107 return (NULL);
108 gsp = gp->softc;
107 g_topology_unlock();
108 gp->dumpconf = g_pc98_dumpconf;
109 npart = 0;
110 while (1) { /* a trick to allow us to use break */
111 if (gp->rank != 2 && flags == G_TF_NORMAL)
112 break;
109 g_topology_unlock();
110 gp->dumpconf = g_pc98_dumpconf;
111 npart = 0;
112 while (1) { /* a trick to allow us to use break */
113 if (gp->rank != 2 && flags == G_TF_NORMAL)
114 break;
113 j = sizeof sectorsize;
114 error = g_io_getattr("GEOM::sectorsize", cp, &j, &sectorsize);
115 error = g_getattr("GEOM::sectorsize", cp, &sectorsize);
115 if (error) {
116 sectorsize = 512;
117 printf("g_pc98_taste: error %d Sectors are %d bytes\n",
118 error, sectorsize);
119 }
116 if (error) {
117 sectorsize = 512;
118 printf("g_pc98_taste: error %d Sectors are %d bytes\n",
119 error, sectorsize);
120 }
120 j = sizeof mediasize;
121 error = g_io_getattr("GEOM::mediasize", cp, &j, &mediasize);
121 error = g_getattr("GEOM::mediasize", cp, &mediasize);
122 if (error) {
123 mediasize = 0;
124 printf("g_error %d Mediasize is %lld bytes\n",
125 error, (long long)mediasize);
126 }
122 if (error) {
123 mediasize = 0;
124 printf("g_error %d Mediasize is %lld bytes\n",
125 error, (long long)mediasize);
126 }
127 j = sizeof fwsect;
128 error = g_io_getattr("GEOM::fwsectors", cp, &j, &fwsect);
127 error = g_getattr("GEOM::fwsectors", cp, &fwsect);
129 if (error || fwsect == 0) {
130 fwsect = 17;
131 printf("g_pc98_taste: error %d guessing %d sectors\n",
132 error, fwsect);
133 }
128 if (error || fwsect == 0) {
129 fwsect = 17;
130 printf("g_pc98_taste: error %d guessing %d sectors\n",
131 error, fwsect);
132 }
134 j = sizeof fwhead;
135 error = g_io_getattr("GEOM::fwheads", cp, &j, &fwhead);
133 error = g_getattr("GEOM::fwheads", cp, &fwhead);
136 if (error || fwhead == 0) {
137 fwhead = 8;
138 printf("g_pc98_taste: error %d guessing %d heads\n",
139 error, fwhead);
140 }
134 if (error || fwhead == 0) {
135 fwhead = 8;
136 printf("g_pc98_taste: error %d guessing %d heads\n",
137 error, fwhead);
138 }
139 gsp->frontstuff = fwsect * sectorsize;
141 buf = g_read_data(cp, 0,
142 sectorsize < 1024 ? 1024 : sectorsize, &error);
143 if (buf == NULL || error != 0)
144 break;
145
146 if (buf[0x1fe] != 0x55 || buf[0x1ff] != 0xaa)
147 break;
148 if (buf[4] != 'I' || buf[5] != 'P' ||
149 buf[6] != 'L' || buf[7] != '1')
150 break;
151
152
153 for (i = 0; i < 16; i++) {
154 v = g_dec_le2(buf + 512 + 10 + i * 32);
155 u = g_dec_le2(buf + 512 + 14 + i * 32);
156 if (u == 0)
157 continue;
158 printf("Index: %d\n", i);
159 g_hexdump(buf+512 + i * 32, 32);
160 start = v * fwsect * fwhead * sectorsize;
161 length = (u - v) * fwsect * fwhead * sectorsize;
162 printf("c%d - c%d (%llx - %llx) = %s\n",
163 v, u, start, length, buf + 512 + 16 + i * 32);
164 npart++;
165 pp2 = g_slice_addslice(gp, i,
166 start, length,
167 "%ss%d", pp->name, 1 + i);
168 g_error_provider(pp2, 0);
169 }
170 break;
171 }
172 g_topology_lock();
173 error = g_access_rel(cp, -1, 0, 0);
174 if (npart > 0)
175 return (gp);
176 g_std_spoiled(cp);
177 return (NULL);
178}
179
180static struct g_class g_pc98_class = {
181 PC98_CLASS_NAME,
182 g_pc98_taste,
183 NULL,
184 G_CLASS_INITSTUFF
185};
186
187DECLARE_GEOM_CLASS(g_pc98_class, g_pc98);
140 buf = g_read_data(cp, 0,
141 sectorsize < 1024 ? 1024 : sectorsize, &error);
142 if (buf == NULL || error != 0)
143 break;
144
145 if (buf[0x1fe] != 0x55 || buf[0x1ff] != 0xaa)
146 break;
147 if (buf[4] != 'I' || buf[5] != 'P' ||
148 buf[6] != 'L' || buf[7] != '1')
149 break;
150
151
152 for (i = 0; i < 16; i++) {
153 v = g_dec_le2(buf + 512 + 10 + i * 32);
154 u = g_dec_le2(buf + 512 + 14 + i * 32);
155 if (u == 0)
156 continue;
157 printf("Index: %d\n", i);
158 g_hexdump(buf+512 + i * 32, 32);
159 start = v * fwsect * fwhead * sectorsize;
160 length = (u - v) * fwsect * fwhead * sectorsize;
161 printf("c%d - c%d (%llx - %llx) = %s\n",
162 v, u, start, length, buf + 512 + 16 + i * 32);
163 npart++;
164 pp2 = g_slice_addslice(gp, i,
165 start, length,
166 "%ss%d", pp->name, 1 + i);
167 g_error_provider(pp2, 0);
168 }
169 break;
170 }
171 g_topology_lock();
172 error = g_access_rel(cp, -1, 0, 0);
173 if (npart > 0)
174 return (gp);
175 g_std_spoiled(cp);
176 return (NULL);
177}
178
179static struct g_class g_pc98_class = {
180 PC98_CLASS_NAME,
181 g_pc98_taste,
182 NULL,
183 G_CLASS_INITSTUFF
184};
185
186DECLARE_GEOM_CLASS(g_pc98_class, g_pc98);