static int dkwedge_discover_bsdlabel(struct disk *pdk, struct vnode *vp) { mbr_args_t a; const struct disklabel_location *dl; int rval; a.pdk = pdk; a.vp = vp; a.buf = DKW_MALLOC(DEV_BSIZE); a.error = 0; /* MBR search. */ rval = scan_mbr(&a, look_netbsd_part); if (rval != SCAN_CONTINUE) { if (rval == SCAN_FOUND) a.error = 0; /* found it, wedges installed */ goto out; } /* Known location search. */ for (dl = disklabel_locations; dl->label_sector != -1; dl++) { rval = validate_label(&a, dl->label_sector, dl->label_offset); if (rval != SCAN_CONTINUE) { if (rval == SCAN_FOUND) a.error = 0; /* found it, wedges installed */ goto out; } } /* No NetBSD disklabel found. */ a.error = ESRCH; out: DKW_FREE(a.buf); return (a.error); }
static int dkwedge_discover_apple(struct disk *pdk, struct vnode *vp) { size_t i; int error; void *buf; uint32_t blocksize, offset, rsize; struct apple_drvr_map *am; struct apple_part_map_entry *ae; struct apple_blockzeroblock ab; const char *ptype; buf = DKW_MALLOC(ASIZE); if ((error = dkwedge_read(pdk, vp, 0, buf, ASIZE)) != 0) { DPRINTF("%s: read @%u %d\n", __func__, 0, error); goto out; } am = buf; swap_apple_drvr_map(am); error = ESRCH; if (am->sbSig != APPLE_DRVR_MAP_MAGIC) { DPRINTF("%s: drvr magic %x != %x\n", __func__, am->sbSig, APPLE_DRVR_MAP_MAGIC); goto out; } blocksize = am->sbBlockSize; rsize = 1 << (ilog2(MAX(sizeof(*ae), blocksize) - 1) + 1); if (ASIZE < rsize) { DPRINTF("%s: buffer too small %u < %u\n", __func__, ASIZE, rsize); goto out; } ae = buf; for (offset = blocksize;; offset += rsize) { DPRINTF("%s: offset %x rsize %x\n", __func__, offset, rsize); if ((error = dkwedge_read(pdk, vp, offset / DEV_BSIZE, buf, rsize)) != 0) { DPRINTF("%s: read @%u %d\n", __func__, offset, error); goto out; } swap_apple_part_map_entry(ae); if (ae->pmSig != APPLE_PART_MAP_ENTRY_MAGIC) { DPRINTF("%s: part magic %x != %x\n", __func__, ae->pmSig, APPLE_PART_MAP_ENTRY_MAGIC); break; } for (i = 0; i < __arraycount(map); i++) if (strcasecmp(map[i].name, ae->pmPartType) == 0) break; DPRINTF("%s: %s/%s PH=%u/%u LG=%u/%u\n", __func__, ae->pmPartName, ae->pmPartType, ae->pmPyPartStart, ae->pmPartBlkCnt, ae->pmLgDataStart, ae->pmDataCnt); if (i == __arraycount(map)) continue; ptype = map[i].type; memcpy(&ab, ae->pmBootArgs, sizeof(ab)); swap_apple_blockzeroblock(&ab); if (ab.bzbMagic == APPLE_BZB_MAGIC) { if (ab.bzbType == APPLE_BZB_TYPESWAP) ptype = DKW_PTYPE_SWAP; } struct dkwedge_info dkw; strcpy(dkw.dkw_ptype, ptype); strcpy(dkw.dkw_parent, pdk->dk_name); dkw.dkw_offset = ae->pmPyPartStart; dkw.dkw_size = ae->pmPartBlkCnt; strlcpy(dkw.dkw_wname, ae->pmPartName, sizeof(dkw.dkw_wname)); error = dkwedge_add(&dkw); if (error == EEXIST) aprint_error("%s: wedge named '%s' already " "exists, manual intervention required\n", pdk->dk_name, dkw.dkw_wname); else if (error) aprint_error("%s: error %d adding partition " "%s type %s\n", pdk->dk_name, error, ae->pmPartType, dkw.dkw_ptype); } out: DKW_FREE(buf); DPRINTF("%s: return %d\n", __func__, error); return error; }