/* * Fabricate a default disk label, and try to read the correct one. */ int wdgetdisklabel(dev_t dev, struct wd_softc *wd, struct disklabel *lp, int spoofonly) { int error; WDCDEBUG_PRINT(("wdgetdisklabel\n"), DEBUG_FUNCS); wdgetdefaultlabel(wd, lp); if (wd->drvp->state > RECAL) wd->drvp->drive_flags |= DRIVE_RESET; error = readdisklabel(DISKLABELDEV(dev), wdstrategy, lp, spoofonly); if (wd->drvp->state > RECAL) wd->drvp->drive_flags |= DRIVE_RESET; return (error); }
/* * Read disk label from the device. */ int wdgetdisklabel(struct wd_softc *wd) { struct mbr_sector *mbr; struct mbr_partition *mp; struct disklabel *lp; size_t rsize; int sector, i; char *msg; uint8_t buf[DEV_BSIZE]; wdgetdefaultlabel(wd, &wd->sc_label); /* * Find NetBSD Partition in DOS partition table. */ sector = 0; if (wdstrategy(wd, F_READ, MBR_BBSECTOR, DEV_BSIZE, buf, &rsize)) return EOFFSET; mbr = (struct mbr_sector *)buf; if (mbr->mbr_magic == htole16(MBR_MAGIC)) { /* * Lookup NetBSD slice. If there is none, go ahead * and try to read the disklabel off sector #0. */ mp = mbr->mbr_parts; for (i = 0; i < MBR_PART_COUNT; i++) { if (mp[i].mbrp_type == MBR_PTYPE_NETBSD) { sector = le32toh(mp[i].mbrp_start); break; } } } if (wdstrategy(wd, F_READ, sector + LABELSECTOR, DEV_BSIZE, buf, &rsize)) return EOFFSET; msg = getdisklabel((const char *)buf + LABELOFFSET, &wd->sc_label); if (msg) printf("ide/0/%s/0: getdisklabel: %s\n", (wd->sc_unit == 0) ? "master" : "slave", msg); lp = &wd->sc_label; /* check partition */ if ((wd->sc_part >= lp->d_npartitions) || (lp->d_partitions[wd->sc_part].p_fstype == FS_UNUSED)) { DPRINTF(("illegal partition\n")); return EPART; } DPRINTF(("label info: d_secsize %d, d_nsectors %d, d_ncylinders %d," " d_ntracks %d, d_secpercyl %d\n", wd->sc_label.d_secsize, wd->sc_label.d_nsectors, wd->sc_label.d_ncylinders, wd->sc_label.d_ntracks, wd->sc_label.d_secpercyl)); return 0; }
/* * Read disk label from the device. */ int wdgetdisklabel(struct wd_softc *wd) { char *msg; int sector; size_t rsize; struct disklabel *lp; uint8_t buf[DEV_BSIZE]; wdgetdefaultlabel(wd, &wd->sc_label); /* * Find NetBSD Partition in DOS partition table. */ sector = 0; if (wdstrategy(wd, F_READ, MBR_BBSECTOR, DEV_BSIZE, buf, &rsize)) return EOFFSET; if (*(uint16_t *)&buf[MBR_MAGIC_OFFSET] == MBR_MAGIC) { int i; struct mbr_partition *mp; /* * Lookup NetBSD slice. If there is none, go ahead * and try to read the disklabel off sector #0. */ mp = (struct mbr_partition *)&buf[MBR_PART_OFFSET]; for (i = 0; i < MBR_PART_COUNT; i++) { if (mp[i].mbrp_type == MBR_PTYPE_NETBSD) { sector = mp[i].mbrp_start; break; } } } if (wdstrategy(wd, F_READ, sector + LABELSECTOR, DEV_BSIZE, buf, &rsize)) return EOFFSET; if ((msg = getdisklabel(buf + LABELOFFSET, &wd->sc_label))) printf("wd%d: getdisklabel: %s\n", wd->sc_unit, msg); lp = &wd->sc_label; /* check partition */ if ((wd->sc_part >= lp->d_npartitions) || (lp->d_partitions[wd->sc_part].p_fstype == FS_UNUSED)) { DPRINTF(("illegal partition\n")); return EPART; } DPRINTF(("label info: d_secsize %d, d_nsectors %d, d_ncylinders %d," "d_ntracks %d, d_secpercyl %d\n", wd->sc_label.d_secsize, wd->sc_label.d_nsectors, wd->sc_label.d_ncylinders, wd->sc_label.d_ntracks, wd->sc_label.d_secpercyl)); return 0; }