geom_mbr.c (118150) | geom_mbr.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_mbr.c 118150 2003-07-29 10:09:13Z phk $"); | 34__FBSDID("$FreeBSD: head/sys/geom/geom_mbr.c 119660 2003-09-01 20:45:32Z 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 | 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) | 155static int 156g_mbr_ioctl(struct g_provider *pp, u_long cmd, void *data, struct thread *td) |
157{ | 157{ |
158 struct bio *bp; | |
159 struct g_geom *gp; | 158 struct g_geom *gp; |
160 struct g_slicer *gsp; | |
161 struct g_mbr_softc *ms; | 159 struct g_mbr_softc *ms; |
162 struct g_ioctl *gio; | 160 struct g_slicer *gsp; |
163 struct g_consumer *cp; | 161 struct g_consumer *cp; |
164 u_char *sec0; | |
165 int error; 166 | 162 int error; 163 |
167 bp = arg; 168 if (flag == EV_CANCEL) { 169 g_io_deliver(bp, ENXIO); 170 return; 171 } 172 gp = bp->bio_to->geom; | 164 gp = pp->geom; |
173 gsp = gp->softc; 174 ms = gsp->softc; | 165 gsp = gp->softc; 166 ms = gsp->softc; |
175 gio = (struct g_ioctl *)bp->bio_data; | |
176 | 167 |
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; | 168 switch(cmd) { 169 case DIOCSMBR: { 170 DROP_GIANT(); 171 g_topology_lock(); 172 /* Validate and modify our slicer instance to match. */ 173 error = g_mbr_modify(gp, ms, data); 174 cp = LIST_FIRST(&gp->consumer); 175 error = g_write_data(cp, 0, data, 512); 176 g_topology_unlock(); 177 PICKUP_GIANT(); 178 return(error); |
184 } | 179 } |
185 cp = LIST_FIRST(&gp->consumer); 186 error = g_write_data(cp, 0, sec0, 512); 187 g_io_deliver(bp, error); | 180 default: 181 return (ENOIOCTL); 182 } |
188} 189 | 183} 184 |
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; | 185static int 186g_mbr_start(struct bio *bp) 187{ 188 struct g_provider *pp; 189 struct g_geom *gp; 190 struct g_mbr_softc *mp; 191 struct g_slicer *gsp; |
198 struct g_ioctl *gio; 199 int idx, error; | 192 int idx; |
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 | 193 194 pp = bp->bio_to; 195 idx = pp->index; 196 gp = pp->geom; 197 gsp = gp->softc; 198 mp = gsp->softc; 199 if (bp->bio_cmd == BIO_GETATTR) { 200 if (g_handleattr_int(bp, "MBR::type", mp->type[idx])) 201 return (1); 202 if (g_handleattr_off_t(bp, "MBR::offset", 203 gsp->slices[idx].offset)) 204 return (1); 205 } 206 |
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 } | 207 return (0); |
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; | 208} 209 210static void 211g_mbr_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp) 212{ 213 struct g_mbr_softc *mp; 214 struct g_slicer *gsp; 215 --- 21 unchanged lines hidden (view full) --- 237 238 g_trace(G_T_TOPOLOGY, "mbr_taste(%s,%s)", mp->name, pp->name); 239 g_topology_assert(); 240 gp = g_slice_new(mp, NDOSPART, pp, &cp, &ms, sizeof *ms, g_mbr_start); 241 if (gp == NULL) 242 return (NULL); 243 g_topology_unlock(); 244 gp->dumpconf = g_mbr_dumpconf; |
245 gp->ioctl = g_mbr_ioctl; |
|
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 --- | 246 do { 247 if (gp->rank != 2 && insist == 0) 248 break; 249 error = g_getattr("GEOM::fwsectors", cp, &fwsectors); 250 if (error) 251 fwsectors = 17; 252 sectorsize = cp->provider->sectorsize; 253 if (sectorsize < 512) --- 167 unchanged lines hidden --- |