geom_mbr.c (93776) | geom_mbr.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 --- 18 unchanged lines hidden (view full) --- 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 --- 18 unchanged lines hidden (view full) --- 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_mbr.c 93776 2002-04-04 09:54:13Z phk $ | 35 * $FreeBSD: head/sys/geom/geom_mbr.c 94287 2002-04-09 15:43:32Z phk $ |
36 */ 37 38#include <sys/param.h> 39#ifndef _KERNEL 40#include <stdio.h> 41#include <string.h> 42#include <signal.h> 43#include <sys/param.h> --- 120 unchanged lines hidden (view full) --- 164} 165 166static struct g_geom * 167g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist) 168{ 169 struct g_geom *gp; 170 struct g_consumer *cp; 171 struct g_provider *pp2; | 36 */ 37 38#include <sys/param.h> 39#ifndef _KERNEL 40#include <stdio.h> 41#include <string.h> 42#include <signal.h> 43#include <sys/param.h> --- 120 unchanged lines hidden (view full) --- 164} 165 166static struct g_geom * 167g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist) 168{ 169 struct g_geom *gp; 170 struct g_consumer *cp; 171 struct g_provider *pp2; |
172 int error, i, j, npart; | 172 int error, i, npart; |
173 struct dos_partition dp[NDOSPART]; 174 struct g_mbr_softc *ms; | 173 struct dos_partition dp[NDOSPART]; 174 struct g_mbr_softc *ms; |
175 struct g_slicer *gsp; 176 u_int fwsectors, sectorsize; |
|
175 u_char *buf; 176 | 177 u_char *buf; 178 |
177 if (sizeof(struct dos_partition) != 16) { 178 printf("WARNING: struct dos_partition compiles to %d bytes, should be 16.\n", 179 (int)sizeof(struct dos_partition)); 180 return (NULL); 181 } | |
182 g_trace(G_T_TOPOLOGY, "mbr_taste(%s,%s)", mp->name, pp->name); 183 g_topology_assert(); 184 gp = g_slice_new(mp, NDOSPART, pp, &cp, &ms, sizeof *ms, g_mbr_start); 185 if (gp == NULL) 186 return (NULL); | 179 g_trace(G_T_TOPOLOGY, "mbr_taste(%s,%s)", mp->name, pp->name); 180 g_topology_assert(); 181 gp = g_slice_new(mp, NDOSPART, pp, &cp, &ms, sizeof *ms, g_mbr_start); 182 if (gp == NULL) 183 return (NULL); |
184 gsp = gp->softc; |
|
187 g_topology_unlock(); 188 gp->dumpconf = g_mbr_dumpconf; 189 npart = 0; 190 while (1) { /* a trick to allow us to use break */ 191 if (gp->rank != 2 && insist == 0) 192 break; | 185 g_topology_unlock(); 186 gp->dumpconf = g_mbr_dumpconf; 187 npart = 0; 188 while (1) { /* a trick to allow us to use break */ 189 if (gp->rank != 2 && insist == 0) 190 break; |
193 j = sizeof i; 194 /* For now we only support 512 bytes sectors */ 195 error = g_io_getattr("GEOM::sectorsize", cp, &j, &i); 196 if (!error && i != 512) | 191 error = g_getattr("GEOM::fwsectors", cp, &fwsectors); 192 if (error) 193 fwsectors = 17; 194 error = g_getattr("GEOM::sectorsize", cp, §orsize); 195 if (error) |
197 break; | 196 break; |
198 buf = g_read_data(cp, 0, 512, &error); | 197 if (!error && sectorsize != 512) 198 break; 199 gsp->frontstuff = sectorsize * fwsectors; 200 buf = g_read_data(cp, 0, sectorsize, &error); |
199 if (buf == NULL || error != 0) 200 break; 201 if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa) { 202 g_free(buf); 203 break; 204 } 205 for (i = 0; i < NDOSPART; i++) 206 g_dec_dos_partition( --- 95 unchanged lines hidden (view full) --- 302} 303 304static struct g_geom * 305g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) 306{ 307 struct g_geom *gp; 308 struct g_consumer *cp; 309 struct g_provider *pp2; | 201 if (buf == NULL || error != 0) 202 break; 203 if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa) { 204 g_free(buf); 205 break; 206 } 207 for (i = 0; i < NDOSPART; i++) 208 g_dec_dos_partition( --- 95 unchanged lines hidden (view full) --- 304} 305 306static struct g_geom * 307g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) 308{ 309 struct g_geom *gp; 310 struct g_consumer *cp; 311 struct g_provider *pp2; |
310 int error, i, j, slice; | 312 int error, i, slice; |
311 struct g_mbrext_softc *ms; 312 off_t off; 313 u_char *buf; 314 struct dos_partition dp[4]; | 313 struct g_mbrext_softc *ms; 314 off_t off; 315 u_char *buf; 316 struct dos_partition dp[4]; |
317 u_int fwsectors, sectorsize; 318 struct g_slicer *gsp; |
|
315 316 g_trace(G_T_TOPOLOGY, "g_mbrext_taste(%s,%s)", mp->name, pp->name); 317 g_topology_assert(); 318 if (strcmp(pp->geom->class->name, MBR_CLASS_NAME)) 319 return (NULL); 320 gp = g_slice_new(mp, NDOSEXTPART, pp, &cp, &ms, sizeof *ms, g_mbrext_start); 321 if (gp == NULL) 322 return (NULL); | 319 320 g_trace(G_T_TOPOLOGY, "g_mbrext_taste(%s,%s)", mp->name, pp->name); 321 g_topology_assert(); 322 if (strcmp(pp->geom->class->name, MBR_CLASS_NAME)) 323 return (NULL); 324 gp = g_slice_new(mp, NDOSEXTPART, pp, &cp, &ms, sizeof *ms, g_mbrext_start); 325 if (gp == NULL) 326 return (NULL); |
327 gsp = gp->softc; |
|
323 g_topology_unlock(); 324 gp->dumpconf = g_mbrext_dumpconf; 325 off = 0; 326 slice = 0; 327 while (1) { /* a trick to allow us to use break */ | 328 g_topology_unlock(); 329 gp->dumpconf = g_mbrext_dumpconf; 330 off = 0; 331 slice = 0; 332 while (1) { /* a trick to allow us to use break */ |
328 j = sizeof i; 329 error = g_io_getattr("MBR::type", cp, &j, &i); | 333 error = g_getattr("MBR::type", cp, &i); |
330 if (error || i != DOSPTYP_EXT) 331 break; | 334 if (error || i != DOSPTYP_EXT) 335 break; |
336 error = g_getattr("GEOM::fwsectors", cp, &fwsectors); 337 if (error) 338 fwsectors = 17; 339 error = g_getattr("GEOM::sectorsize", cp, §orsize); 340 if (error) 341 break; 342 if (!error && sectorsize != 512) 343 break; 344 gsp->frontstuff = sectorsize * fwsectors; |
|
332 for (;;) { | 345 for (;;) { |
333 buf = g_read_data(cp, off, DEV_BSIZE, &error); | 346 buf = g_read_data(cp, off, sectorsize, &error); |
334 if (buf == NULL || error != 0) 335 break; 336 if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa) 337 break; 338 for (i = 0; i < NDOSPART; i++) 339 g_dec_dos_partition( 340 buf + DOSPARTOFF + i * sizeof(struct dos_partition), 341 dp + i); --- 46 unchanged lines hidden --- | 347 if (buf == NULL || error != 0) 348 break; 349 if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa) 350 break; 351 for (i = 0; i < NDOSPART; i++) 352 g_dec_dos_partition( 353 buf + DOSPARTOFF + i * sizeof(struct dos_partition), 354 dp + i); --- 46 unchanged lines hidden --- |