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 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 |
155static int 156g_mbr_ioctl(struct g_provider *pp, u_long cmd, void *data, struct thread *td) |
157{ |
158 struct g_geom *gp; |
159 struct g_mbr_softc *ms; |
160 struct g_slicer *gsp; |
161 struct g_consumer *cp; |
162 int error; 163 |
164 gp = pp->geom; |
165 gsp = gp->softc; 166 ms = gsp->softc; |
167 |
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); |
179 } |
180 default: 181 return (ENOIOCTL); 182 } |
183} 184 |
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; |
192 int idx; |
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 |
207 return (0); |
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; |
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 --- |