Deleted Added
full compact
geom_pc98.c (116196) geom_pc98.c (119660)
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

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

26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
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

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

26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/geom/geom_pc98.c 116196 2003-06-11 06:49:16Z obrien $");
34__FBSDID("$FreeBSD: head/sys/geom/geom_pc98.c 119660 2003-09-01 20:45:32Z phk $");
35
36#include <sys/param.h>
37#include <sys/endian.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/malloc.h>
41#include <sys/bio.h>
42#include <sys/lock.h>

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

129 ms->sectorsize, "%ss%d", gp->name, i + 1);
130 }
131
132 bcopy(sec, ms->sec, sizeof (ms->sec));
133
134 return (0);
135}
136
35
36#include <sys/param.h>
37#include <sys/endian.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/malloc.h>
41#include <sys/bio.h>
42#include <sys/lock.h>

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

129 ms->sectorsize, "%ss%d", gp->name, i + 1);
130 }
131
132 bcopy(sec, ms->sec, sizeof (ms->sec));
133
134 return (0);
135}
136
137static void
138g_pc98_ioctl(void *arg, int flag)
137static int
138g_pc98_ioctl(struct g_provider *pp, u_long cmd, void *data, struct thread *td)
139{
139{
140 struct bio *bp;
141 struct g_geom *gp;
140 struct g_geom *gp;
142 struct g_slicer *gsp;
143 struct g_pc98_softc *ms;
141 struct g_pc98_softc *ms;
144 struct g_ioctl *gio;
142 struct g_slicer *gsp;
145 struct g_consumer *cp;
143 struct g_consumer *cp;
146 u_char *sec;
147 int error;
148
144 int error;
145
149 bp = arg;
150 if (flag == EV_CANCEL) {
151 g_io_deliver(bp, ENXIO);
152 return;
153 }
154 gp = bp->bio_to->geom;
146 gp = pp->geom;
155 gsp = gp->softc;
156 ms = gsp->softc;
147 gsp = gp->softc;
148 ms = gsp->softc;
157 gio = (struct g_ioctl *)bp->bio_data;
158
149
159 /* The disklabel to set is the ioctl argument. */
160 sec = gio->data;
161
162 error = g_pc98_modify(gp, ms, sec);
163 if (error) {
164 g_io_deliver(bp, error);
165 return;
150 switch(cmd) {
151 case DIOCSPC98: {
152 DROP_GIANT();
153 g_topology_lock();
154 /* Validate and modify our slicer instance to match. */
155 error = g_pc98_modify(gp, ms, data);
156 cp = LIST_FIRST(&gp->consumer);
157 error = g_write_data(cp, 0, data, 8192);
158 g_topology_unlock();
159 PICKUP_GIANT();
160 return(error);
166 }
161 }
167 cp = LIST_FIRST(&gp->consumer);
168 error = g_write_data(cp, 0, sec, 8192);
169 g_io_deliver(bp, error);
162 default:
163 return (ENOIOCTL);
164 }
170}
171
172static int
173g_pc98_start(struct bio *bp)
174{
175 struct g_provider *pp;
176 struct g_geom *gp;
177 struct g_pc98_softc *mp;
178 struct g_slicer *gsp;
165}
166
167static int
168g_pc98_start(struct bio *bp)
169{
170 struct g_provider *pp;
171 struct g_geom *gp;
172 struct g_pc98_softc *mp;
173 struct g_slicer *gsp;
179 struct g_ioctl *gio;
180 int idx, error;
174 int idx;
181
182 pp = bp->bio_to;
183 idx = pp->index;
184 gp = pp->geom;
185 gsp = gp->softc;
186 mp = gsp->softc;
187 if (bp->bio_cmd == BIO_GETATTR) {
188 if (g_handleattr_int(bp, "PC98::type", mp->type[idx]))
189 return (1);
190 if (g_handleattr_off_t(bp, "PC98::offset",
191 gsp->slices[idx].offset))
192 return (1);
193 }
194
175
176 pp = bp->bio_to;
177 idx = pp->index;
178 gp = pp->geom;
179 gsp = gp->softc;
180 mp = gsp->softc;
181 if (bp->bio_cmd == BIO_GETATTR) {
182 if (g_handleattr_int(bp, "PC98::type", mp->type[idx]))
183 return (1);
184 if (g_handleattr_off_t(bp, "PC98::offset",
185 gsp->slices[idx].offset))
186 return (1);
187 }
188
195 /* We only handle ioctl(2) requests of the right format. */
196 if (strcmp(bp->bio_attribute, "GEOM::ioctl"))
197 return (0);
198 else if (bp->bio_length != sizeof(*gio))
199 return (0);
200 /* Get hold of the ioctl parameters. */
201 gio = (struct g_ioctl *)bp->bio_data;
202
203 switch (gio->cmd) {
204 case DIOCSPC98:
205 /*
206 * These we cannot do without the topology lock and some
207 * some I/O requests. Ask the event-handler to schedule
208 * us in a less restricted environment.
209 */
210 error = g_post_event(g_pc98_ioctl, bp, M_NOWAIT, gp, NULL);
211 if (error)
212 g_io_deliver(bp, error);
213 /*
214 * We must return non-zero to indicate that we will deal
215 * with this bio, even though we have not done so yet.
216 */
217 return (1);
218 default:
219 return (0);
220 }
189 return (0);
221}
222
223static void
224g_pc98_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
225 struct g_consumer *cp __unused, struct g_provider *pp)
226{
227 struct g_pc98_softc *mp;
228 struct g_slicer *gsp;

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

265 if (flags == G_TF_NORMAL &&
266 !strcmp(pp->geom->class->name, PC98_CLASS_NAME))
267 return (NULL);
268 gp = g_slice_new(mp, NDOSPART, pp, &cp, &ms, sizeof *ms, g_pc98_start);
269 if (gp == NULL)
270 return (NULL);
271 g_topology_unlock();
272 gp->dumpconf = g_pc98_dumpconf;
190}
191
192static void
193g_pc98_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
194 struct g_consumer *cp __unused, struct g_provider *pp)
195{
196 struct g_pc98_softc *mp;
197 struct g_slicer *gsp;

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

234 if (flags == G_TF_NORMAL &&
235 !strcmp(pp->geom->class->name, PC98_CLASS_NAME))
236 return (NULL);
237 gp = g_slice_new(mp, NDOSPART, pp, &cp, &ms, sizeof *ms, g_pc98_start);
238 if (gp == NULL)
239 return (NULL);
240 g_topology_unlock();
241 gp->dumpconf = g_pc98_dumpconf;
242 gp->ioctl = g_pc98_ioctl;
273 do {
274 if (gp->rank != 2 && flags == G_TF_NORMAL)
275 break;
276 error = g_getattr("GEOM::fwsectors", cp, &fwsectors);
277 if (error || fwsectors == 0) {
278 fwsectors = 17;
279 if (bootverbose)
280 printf("g_pc98_taste: guessing %d sectors\n",

--- 39 unchanged lines hidden ---
243 do {
244 if (gp->rank != 2 && flags == G_TF_NORMAL)
245 break;
246 error = g_getattr("GEOM::fwsectors", cp, &fwsectors);
247 if (error || fwsectors == 0) {
248 fwsectors = 17;
249 if (bootverbose)
250 printf("g_pc98_taste: guessing %d sectors\n",

--- 39 unchanged lines hidden ---