Deleted Added
sdiff udiff text old ( 118150 ) new ( 119660 )
full compact
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_mbr.c 118150 2003-07-29 10:09:13Z phk $");
35
36#include <sys/param.h>
37#include <sys/errno.h>
38#include <sys/endian.h>
39#include <sys/systm.h>
40#include <sys/kernel.h>
41#include <sys/malloc.h>
42#include <sys/bio.h>

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

147 g_slice_config(gp, i, G_SLICE_CONFIG_SET,
148 (off_t)dp[i].dp_start * ms->sectorsize, l[i],
149 ms->sectorsize, "%ss%d", gp->name, 1 + i);
150 }
151 bcopy(sec0, ms->sec0, 512);
152 return (0);
153}
154
155static void
156g_mbr_ioctl(void *arg, int flag)
157{
158 struct bio *bp;
159 struct g_geom *gp;
160 struct g_slicer *gsp;
161 struct g_mbr_softc *ms;
162 struct g_ioctl *gio;
163 struct g_consumer *cp;
164 u_char *sec0;
165 int error;
166
167 bp = arg;
168 if (flag == EV_CANCEL) {
169 g_io_deliver(bp, ENXIO);
170 return;
171 }
172 gp = bp->bio_to->geom;
173 gsp = gp->softc;
174 ms = gsp->softc;
175 gio = (struct g_ioctl *)bp->bio_data;
176
177 /* The disklabel to set is the ioctl argument. */
178 sec0 = gio->data;
179
180 error = g_mbr_modify(gp, ms, sec0);
181 if (error) {
182 g_io_deliver(bp, error);
183 return;
184 }
185 cp = LIST_FIRST(&gp->consumer);
186 error = g_write_data(cp, 0, sec0, 512);
187 g_io_deliver(bp, error);
188}
189
190
191static int
192g_mbr_start(struct bio *bp)
193{
194 struct g_provider *pp;
195 struct g_geom *gp;
196 struct g_mbr_softc *mp;
197 struct g_slicer *gsp;
198 struct g_ioctl *gio;
199 int idx, error;
200
201 pp = bp->bio_to;
202 idx = pp->index;
203 gp = pp->geom;
204 gsp = gp->softc;
205 mp = gsp->softc;
206 if (bp->bio_cmd == BIO_GETATTR) {
207 if (g_handleattr_int(bp, "MBR::type", mp->type[idx]))
208 return (1);
209 if (g_handleattr_off_t(bp, "MBR::offset",
210 gsp->slices[idx].offset))
211 return (1);
212 }
213
214 /* We only handle ioctl(2) requests of the right format. */
215 if (strcmp(bp->bio_attribute, "GEOM::ioctl"))
216 return (0);
217 else if (bp->bio_length != sizeof(*gio))
218 return (0);
219
220 /* Get hold of the ioctl parameters. */
221 gio = (struct g_ioctl *)bp->bio_data;
222
223 switch (gio->cmd) {
224 case DIOCSMBR:
225 /*
226 * These we cannot do without the topology lock and some
227 * some I/O requests. Ask the event-handler to schedule
228 * us in a less restricted environment.
229 */
230 error = g_post_event(g_mbr_ioctl, bp, M_NOWAIT, gp, NULL);
231 if (error)
232 g_io_deliver(bp, error);
233 /*
234 * We must return non-zero to indicate that we will deal
235 * with this bio, even though we have not done so yet.
236 */
237 return (1);
238 default:
239 return (0);
240 }
241}
242
243static void
244g_mbr_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp)
245{
246 struct g_mbr_softc *mp;
247 struct g_slicer *gsp;
248

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

270
271 g_trace(G_T_TOPOLOGY, "mbr_taste(%s,%s)", mp->name, pp->name);
272 g_topology_assert();
273 gp = g_slice_new(mp, NDOSPART, pp, &cp, &ms, sizeof *ms, g_mbr_start);
274 if (gp == NULL)
275 return (NULL);
276 g_topology_unlock();
277 gp->dumpconf = g_mbr_dumpconf;
278 do {
279 if (gp->rank != 2 && insist == 0)
280 break;
281 error = g_getattr("GEOM::fwsectors", cp, &fwsectors);
282 if (error)
283 fwsectors = 17;
284 sectorsize = cp->provider->sectorsize;
285 if (sectorsize < 512)

--- 167 unchanged lines hidden ---