/* * Check new disk label for sensibility * before setting it. */ int setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask, struct cpu_disklabel *osdep) { int i; struct partition *opp, *npp; if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || dkcksum(nlp) != 0) return EINVAL; while ((i = ffs(openmask)) != 0) { i--; openmask &= ~(1 << i); if (nlp->d_npartitions <= i) return EBUSY; opp = &olp->d_partitions[i]; npp = &nlp->d_partitions[i]; if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size) return EBUSY; /* * Copy internally-set partition information * if new label doesn't include it. XXX */ if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) { npp->p_fstype = opp->p_fstype; npp->p_fsize = opp->p_fsize; npp->p_frag = opp->p_frag; npp->p_cpg = opp->p_cpg; } } nlp->d_checksum = 0; nlp->d_checksum = dkcksum(nlp); *olp = *nlp; return 0; }
/* * Check new disk label for sensibility * before setting it. */ int setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask, struct cpu_disklabel *osdep) { int i; struct partition *opp, *npp; /* sanity clause */ if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 || (nlp->d_secsize % DEV_BSIZE) != 0) return(EINVAL); /* * XXX Nice thought, but it doesn't work, if the intention was to * force a reread at the next *readdisklabel call. That does not * happen. There's still some use for it though as you can pseudo- * partition the disk. * * Special case to allow disklabel to be invalidated. */ if (nlp->d_magic == 0xffffffff) { *olp = *nlp; return (0); } if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || dkcksum(nlp) != 0) return (EINVAL); /* XXX missing check if other dos partitions will be overwritten */ while (openmask != 0) { i = ffs((long)openmask) - 1; openmask &= ~(1 << i); if (nlp->d_npartitions <= i) return (EBUSY); opp = &olp->d_partitions[i]; npp = &nlp->d_partitions[i]; if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size) return (EBUSY); /* * Copy internally-set partition information * if new label doesn't include it. XXX */ if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) { npp->p_fstype = opp->p_fstype; npp->p_fsize = opp->p_fsize; npp->p_frag = opp->p_frag; npp->p_cpg = opp->p_cpg; } } nlp->d_checksum = 0; nlp->d_checksum = dkcksum(nlp); *olp = *nlp; return (0); }
/* * Check new disk label for sensibility * before setting it. */ int setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask, struct cpu_disklabel *osdep) { int i; struct partition *opp, *npp; /* sanity clause */ if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 || (nlp->d_secsize % DEV_BSIZE) != 0) return(EINVAL); /* special case to allow disklabel to be invalidated */ if (nlp->d_magic == 0xffffffff) { *olp = *nlp; return (0); } if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || dkcksum(nlp) != 0) return (EINVAL); /* XXX missing check if other dos partitions will be overwritten */ while (openmask != 0) { i = ffs(openmask) - 1; openmask &= ~(1 << i); if (nlp->d_npartitions <= i) return (EBUSY); opp = &olp->d_partitions[i]; npp = &nlp->d_partitions[i]; if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size) return (EBUSY); /* * Copy internally-set partition information * if new label doesn't include it. XXX */ if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) { npp->p_fstype = opp->p_fstype; npp->p_fsize = opp->p_fsize; npp->p_frag = opp->p_frag; npp->p_cpg = opp->p_cpg; } } nlp->d_checksum = 0; nlp->d_checksum = dkcksum(nlp); *olp = *nlp; return (0); }
void rrmakelabel(struct disklabel *dl, long type) { int n, p = 0; dl->d_bbsize = BBSIZE; dl->d_sbsize = SBLOCKSIZE; /* Create the disk name for disklabel. Phew... */ dl->d_typename[p++] = MSCP_MID_CHAR(2, type); dl->d_typename[p++] = MSCP_MID_CHAR(1, type); if (MSCP_MID_ECH(0, type)) dl->d_typename[p++] = MSCP_MID_CHAR(0, type); n = MSCP_MID_NUM(type); if (n > 99) { dl->d_typename[p++] = '1'; n -= 100; } if (n > 9) { dl->d_typename[p++] = (n / 10) + '0'; n %= 10; } dl->d_typename[p++] = n + '0'; dl->d_typename[p] = 0; dl->d_npartitions = MAXPARTITIONS; dl->d_partitions[0].p_size = dl->d_partitions[2].p_size = dl->d_secperunit; dl->d_partitions[0].p_offset = dl->d_partitions[2].p_offset = 0; dl->d_interleave = dl->d_headswitch = 1; dl->d_magic = dl->d_magic2 = DISKMAGIC; dl->d_checksum = dkcksum(dl); }
static void vndgetdefaultlabel(struct vnd_softc *sc, struct disklabel *lp) { struct vndgeom *vng = &sc->sc_geom; struct partition *pp; memset(lp, 0, sizeof(*lp)); lp->d_secperunit = sc->sc_size / (vng->vng_secsize / DEV_BSIZE); lp->d_secsize = vng->vng_secsize; lp->d_nsectors = vng->vng_nsectors; lp->d_ntracks = vng->vng_ntracks; lp->d_ncylinders = vng->vng_ncylinders; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; strncpy(lp->d_typename, "vnd", sizeof(lp->d_typename)); lp->d_type = DTYPE_VND; strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); lp->d_rpm = 3600; lp->d_interleave = 1; lp->d_flags = 0; pp = &lp->d_partitions[RAW_PART]; pp->p_offset = 0; pp->p_size = lp->d_secperunit; pp->p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
int fdgetdisklabel(dev_t dev, struct fd_softc *fd, struct disklabel *lp, int spoofonly) { bzero(lp, sizeof(struct disklabel)); lp->d_type = DTYPE_FLOPPY; lp->d_secsize = FD_BSIZE(fd); lp->d_secpercyl = fd->sc_type->seccyl; lp->d_nsectors = fd->sc_type->sectrac; lp->d_ncylinders = fd->sc_type->tracks; lp->d_ntracks = fd->sc_type->heads; /* Go figure... */ DL_SETDSIZE(lp, fd->sc_type->size); strncpy(lp->d_typename, "floppy disk", sizeof(lp->d_typename)); strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); lp->d_version = 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); /* * Call the generic disklabel extraction routine. If there's * not a label there, fake it. */ return readdisklabel(DISKLABELDEV(dev), fdstrategy, lp, spoofonly); }
static void edgetdefaultlabel(struct ed_softc *ed, struct disklabel *lp) { ATADEBUG_PRINT(("edgetdefaultlabel\n"), DEBUG_FUNCS); memset(lp, 0, sizeof(struct disklabel)); lp->d_secsize = DEV_BSIZE; lp->d_ntracks = ed->heads; lp->d_nsectors = ed->sectors; lp->d_ncylinders = ed->cyl; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; lp->d_type = DKTYPE_ESDI; strncpy(lp->d_typename, "ESDI", 16); strncpy(lp->d_packname, "fictitious", 16); lp->d_secperunit = ed->sc_capacity; lp->d_rpm = 3600; lp->d_interleave = 1; lp->d_flags = 0; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[RAW_PART].p_size = lp->d_secperunit * (lp->d_secsize / DEV_BSIZE); lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
/* * build standard adaptec ficticious geometry */ static void maru_getdefaultlabel(struct maru_softc *sc, struct disklabel *lp) { struct partition *pp; DB("maru_getdefaultlabel(%p, %p)\n", sc, lp); bzero(lp, sizeof *lp); lp->d_secsize = 512; lp->d_secperunit = sc->sc_size / lp->d_secsize; lp->d_nsectors = 32; lp->d_ntracks = 16; lp->d_ncylinders = sc->sc_size / (lp->d_nsectors * lp->d_secsize * lp->d_ntracks); lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; strncpy(lp->d_typename, "maru", sizeof(lp->d_typename)); lp->d_type = DTYPE_VND; /* XXX compat */ strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); lp->d_rpm = 3600; lp->d_interleave = 1; lp->d_flags = 0; pp = &lp->d_partitions[RAW_PART]; pp->p_offset = 0; pp->p_size = lp->d_secperunit; pp->p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
void wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp) { WDCDEBUG_PRINT(("wdgetdefaultlabel\n"), DEBUG_FUNCS); bzero(lp, sizeof(struct disklabel)); lp->d_secsize = DEV_BSIZE; DL_SETDSIZE(lp, wd->sc_capacity); lp->d_ntracks = wd->sc_params.atap_heads; lp->d_nsectors = wd->sc_params.atap_sectors; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; lp->d_ncylinders = DL_GETDSIZE(lp) / lp->d_secpercyl; if (wd->drvp->ata_vers == -1) { lp->d_type = DTYPE_ST506; strncpy(lp->d_typename, "ST506/MFM/RLL", sizeof lp->d_typename); } else { lp->d_type = DTYPE_ESDI; strncpy(lp->d_typename, "ESDI/IDE disk", sizeof lp->d_typename); } /* XXX - user viscopy() like sd.c */ strncpy(lp->d_packname, wd->sc_params.atap_model, sizeof lp->d_packname); lp->d_flags = 0; lp->d_version = 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
/* ARGSUSED */ void dk_getdefaultlabel(struct dk_softc *dksc, struct disklabel *lp) { struct disk_geom *dg = &dksc->sc_dkdev.dk_geom; memset(lp, 0, sizeof(*lp)); if (dg->dg_secperunit > UINT32_MAX) lp->d_secperunit = UINT32_MAX; else lp->d_secperunit = dg->dg_secperunit; lp->d_secsize = dg->dg_secsize; lp->d_nsectors = dg->dg_nsectors; lp->d_ntracks = dg->dg_ntracks; lp->d_ncylinders = dg->dg_ncylinders; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; strlcpy(lp->d_typename, dksc->sc_xname, sizeof(lp->d_typename)); lp->d_type = dksc->sc_dtype; strlcpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); lp->d_rpm = 3600; lp->d_interleave = 1; lp->d_flags = 0; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[RAW_PART].p_size = lp->d_secperunit; lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(dksc->sc_dkdev.dk_label); }
/* * Read the disklabel. If none is present, use a fictitious one instead. */ void presto_getdisklabel(struct presto_softc *sc) { struct disklabel *lp = sc->sc_dk.dk_label; bzero(sc->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); bzero(sc->sc_dk.dk_label, sizeof(struct disklabel)); lp->d_secsize = DEV_BSIZE; lp->d_ntracks = 1; lp->d_nsectors = 32; lp->d_secperunit = (sc->sc_memsize - PSERVE_OFFSET) >> DEV_BSHIFT; lp->d_ncylinders = lp->d_secperunit / lp->d_nsectors; lp->d_secpercyl = lp->d_nsectors; strncpy(lp->d_typename, "Prestoserve", 16); lp->d_type = DTYPE_SCSI; /* what better to put here? */ strncpy(lp->d_packname, sc->sc_model, 16); lp->d_rpm = 3600; lp->d_interleave = 1; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[RAW_PART].p_size = lp->d_secperunit; lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); readdisklabel(DISKLABELDEV(sc->sc_dev.dv_unit), prestostrategy, sc->sc_dk.dk_label, sc->sc_dk.dk_cpulabel, 0); }
/* * Load the label information on the named device */ int vndgetdisklabel(dev_t dev, struct vnd_softc *sc, struct disklabel *lp, int spoofonly) { memset(lp, 0, sizeof(struct disklabel)); lp->d_secsize = sc->sc_secsize; lp->d_nsectors = sc->sc_nsectors; lp->d_ntracks = sc->sc_ntracks; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; lp->d_ncylinders = sc->sc_size / lp->d_secpercyl; strncpy(lp->d_typename, "vnd device", sizeof(lp->d_typename)); lp->d_type = DTYPE_VND; strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); DL_SETDSIZE(lp, sc->sc_size); lp->d_flags = 0; lp->d_version = 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); /* Call the generic disklabel extraction routine */ return readdisklabel(DISKLABELDEV(dev), vndstrategy, lp, spoofonly); }
/* * Construct a ficticious label. */ static void ldgetdefaultlabel(struct ld_softc *sc, struct disklabel *lp) { memset(lp, 0, sizeof(struct disklabel)); lp->d_secsize = sc->sc_secsize; lp->d_ntracks = sc->sc_nheads; lp->d_nsectors = sc->sc_nsectors; lp->d_ncylinders = sc->sc_ncylinders; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; lp->d_type = DTYPE_LD; strcpy(lp->d_typename, "unknown"); strcpy(lp->d_packname, "fictitious"); lp->d_secperunit = sc->sc_secperunit; lp->d_rpm = 7200; lp->d_interleave = 1; lp->d_flags = 0; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[RAW_PART].p_size = lp->d_secperunit * (lp->d_secsize / DEV_BSIZE); lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
void mcdgetdefaultlabel(struct mcd_softc *sc, struct disklabel *lp) { memset(lp, 0, sizeof(struct disklabel)); lp->d_secsize = sc->blksize; lp->d_ntracks = 1; lp->d_nsectors = 100; lp->d_ncylinders = (sc->disksize / 100) + 1; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; strncpy(lp->d_typename, "Mitsumi CD-ROM", 16); lp->d_type = 0; /* XXX */ strncpy(lp->d_packname, "fictitious", 16); lp->d_secperunit = sc->disksize; lp->d_rpm = 300; lp->d_interleave = 1; lp->d_flags = D_REMOVABLE; lp->d_partitions[0].p_offset = 0; lp->d_partitions[0].p_size = lp->d_secperunit * (lp->d_secsize / DEV_BSIZE); lp->d_partitions[0].p_fstype = FS_ISO9660; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[RAW_PART].p_size = lp->d_secperunit * (lp->d_secsize / DEV_BSIZE); lp->d_partitions[RAW_PART].p_fstype = FS_ISO9660; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
static void sdgetdefaultlabel(struct sd_softc *sd, struct disklabel *lp) { memset(lp, 0, sizeof(struct disklabel)); lp->d_secsize = sd->sc_params.blksize; lp->d_ntracks = sd->sc_params.heads; lp->d_nsectors = sd->sc_params.sectors; lp->d_ncylinders = sd->sc_params.cyls; lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; lp->d_type = DTYPE_SCSI; strncpy(lp->d_packname, "fictitious", 16); lp->d_secperunit = sd->sc_params.disksize; lp->d_rpm = sd->sc_params.rot_rate; lp->d_interleave = 1; lp->d_flags = (sd->sc_flags & FLAGS_REMOVABLE) ? D_REMOVABLE : 0; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[RAW_PART].p_size = lp->d_secperunit; lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
void ofdisk_getdefaultlabel(struct ofdisk_softc *of, struct disklabel *lp) { memset(lp, 0, sizeof *lp); /* * XXX Firmware bug? Asking for block size gives a * XXX ridiculous number! So we use what the boot program * XXX uses. */ lp->d_secsize = DEV_BSIZE; lp->d_secperunit = OF_call_method_1("#blocks", of->sc_ihandle, 0); if (lp->d_secperunit == (u_int32_t)-1) lp->d_secperunit = 0x7fffffff; lp->d_secpercyl = 1; lp->d_nsectors = 1; lp->d_ntracks = 1; lp->d_ncylinders = lp->d_secperunit; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[RAW_PART].p_size = lp->d_secperunit; lp->d_npartitions = RAW_PART + 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); }
int rdgetdisklabel(dev_t dev, struct rd_softc *sc, struct disklabel *lp, int spoofonly) { bzero(lp, sizeof(struct disklabel)); lp->d_secsize = DEV_BSIZE; lp->d_ntracks = 1; lp->d_nsectors = rd_root_size >> DEV_BSHIFT; lp->d_ncylinders = 1; lp->d_secpercyl = lp->d_nsectors; if (lp->d_secpercyl == 0) { lp->d_secpercyl = 100; /* as long as it's not 0 - readdisklabel divides by it */ } strncpy(lp->d_typename, "RAM disk", sizeof(lp->d_typename)); lp->d_type = DTYPE_SCSI; strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); DL_SETDSIZE(lp, lp->d_nsectors); lp->d_version = 1; lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; lp->d_checksum = dkcksum(lp); /* Call the generic disklabel extraction routine. */ return (readdisklabel(DISKLABELDEV(dev), rdstrategy, lp, spoofonly)); }
/* ARGSUSED */ static void dk_makedisklabel(struct dk_softc *dksc) { struct disklabel *lp = dksc->sc_dkdev.dk_label; lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS; strlcpy(lp->d_packname, "default label", sizeof(lp->d_packname)); lp->d_checksum = dkcksum(lp); }
/* * Attempt to read a disk label from a device * using the indicated strategy routine. * The label must be partly set up before this: * secpercyl and anything required in the strategy routine * (e.g., sector size) must be filled in before calling us. * Returns null on success and an error string on failure. */ const char * readdisklabel(dev_t dev, void (*strat)(struct buf *bp), struct disklabel *lp, struct cpu_disklabel *osdep) { struct buf *bp; struct disklabel *dlp; const char *msg = NULL; if (lp->d_secperunit == 0) lp->d_secperunit = 0x1fffffff; lp->d_npartitions = 1; if (lp->d_partitions[0].p_size == 0) lp->d_partitions[0].p_size = 0x1fffffff; lp->d_partitions[0].p_offset = 0; bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; bp->b_blkno = LABELSECTOR; bp->b_bcount = lp->d_secsize; bp->b_flags |= B_READ; bp->b_cylinder = LABELSECTOR / lp->d_secpercyl; (*strat)(bp); if (biowait(bp)) { msg = "I/O error"; } else for (dlp = (struct disklabel *)bp->b_data; dlp <= (struct disklabel *) ((char *)bp->b_data + DEV_BSIZE - sizeof(*dlp)); dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { if (msg == NULL) msg = "no disk label"; } else if (dlp->d_npartitions > MAXPARTITIONS || dkcksum(dlp) != 0) msg = "disk label corrupted"; else { *lp = *dlp; msg = NULL; break; } } brelse(bp, 0); /* * If no NetBSD label was found, check for an Ultrix label and * construct tne incore label from the Ultrix partition information. */ if (msg != NULL) { msg = compat_label(dev, strat, lp, osdep); if (msg == NULL) { printf("WARNING: using Ultrix partition information\n"); /* set geometry? */ } } /* XXX If no NetBSD label or Ultrix label found, generate default label here */ return msg; }
/* * Attempt to read a disk label from a device * using the indicated strategy routine. * The label must be partly set up before this: * secpercyl and anything required in the strategy routine * (e.g., sector size) must be filled in before calling us. * Returns null on success and an error string on failure. */ const char * readdisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct cpu_disklabel *osdep) { struct buf *bp; struct disklabel *dlp; const char *msg = NULL; int i; if (lp->d_secsize == 0) lp->d_secsize = DEV_BSIZE; if (lp->d_secperunit == 0) lp->d_secperunit = 0x1fffffff; if (lp->d_npartitions < RAW_PART + 1) lp->d_npartitions = RAW_PART + 1; for (i = 0; i < RAW_PART; i++) { lp->d_partitions[i].p_size = 0; lp->d_partitions[i].p_offset = 0; } if (lp->d_partitions[RAW_PART].p_size == 0) lp->d_partitions[RAW_PART].p_size = lp->d_secperunit; lp->d_partitions[RAW_PART].p_offset = 0; lp->d_partitions[0].p_size = lp->d_partitions[RAW_PART].p_size; lp->d_partitions[0].p_fstype = FS_BSDFFS; bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; bp->b_blkno = LABELSECTOR; bp->b_bcount = lp->d_secsize; bp->b_flags |= B_READ; bp->b_cylinder = LABELSECTOR / lp->d_secpercyl; (*strat)(bp); if (biowait(bp)) msg = "I/O error"; else for (dlp = (struct disklabel *)bp->b_data; dlp <= (struct disklabel *)((char *)bp->b_data + DEV_BSIZE - sizeof(*dlp)); dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { if (msg == NULL) msg = "no disk label"; } else if (dlp->d_npartitions > MAXPARTITIONS || dkcksum(dlp) != 0) msg = "disk label corrupted"; else { *lp = *dlp; msg = NULL; break; } } brelse(bp, 0); return msg; }
/* Perform some checks and then copy a disk label */ scsi_ret_t setdisklabel( struct disklabel *lp, struct disklabel *nlp) { if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || (dkcksum(nlp) != 0)) return D_INVALID_OPERATION; *lp = *nlp; return D_SUCCESS; }
/* * Try to read a standard BSD disklabel at a certain sector. */ const char * readbsdlabel(struct buf *bp, void (*strat)(struct buf *), int cyl, int sec, int off, struct disklabel *lp, int spoofonly) { struct disklabel *dlp; const char *msg = NULL; uint16_t cksum; /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) return (NULL); bp->b_blkno = sec; bp->b_cylinder = cyl; bp->b_bcount = lp->d_secsize; bp->b_cflags = BC_BUSY; bp->b_flags = B_READ; bp->b_oflags = 0; (*strat)(bp); /* if successful, locate disk label within block and validate */ if (biowait(bp)) { /* XXX we return the faked label built so far */ msg = "disk label I/O error"; return (msg); } /* * If off is negative, search until the end of the sector for * the label, otherwise, just look at the specific location * we're given. */ dlp = (struct disklabel *)((char *)bp->b_data + (off >= 0 ? off : 0)); do { if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { if (msg == NULL) msg = "no disk label"; } else { cksum = dkcksum(dlp); if (dlp->d_npartitions > MAXPARTITIONS || cksum != 0) { msg = "disk label corrupted"; } else { *lp = *dlp; msg = NULL; break; } } if (off >= 0) break; dlp = (struct disklabel *)((char *)dlp + sizeof(int32_t)); } while (dlp <= (struct disklabel *)((char *)bp->b_data + lp->d_secsize - sizeof(*dlp))); return (msg); }
void targettohlabel(struct disklabel *hlp, const struct disklabel *tlp) { if (bswap32(tlp->d_magic) == DISKMAGIC) bswaplabel(hlp, tlp); else *hlp = *tlp; /* update checksum in host endian */ hlp->d_checksum = 0; hlp->d_checksum = dkcksum(hlp); }
int cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp) { int i; if (clp->magic1 != DISKMAGIC || clp->magic2 != DISKMAGIC) return (EINVAL); /* no disk label */ lp->d_magic = clp->magic1; lp->d_type = clp->type; lp->d_subtype = clp->subtype; strncpy(lp->d_typename, clp->vid_vd, sizeof lp->d_typename); strncpy(lp->d_packname, clp->packname, sizeof lp->d_packname); lp->d_secsize = clp->cfg_psm; lp->d_nsectors = clp->cfg_spt; lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */ lp->d_ntracks = clp->cfg_hds; lp->d_secpercyl = clp->secpercyl; if (DL_GETDSIZE(lp) == 0) DL_SETDSIZE(lp, clp->secperunit); lp->d_acylinders = clp->acylinders; lp->d_flags = clp->flags; for (i = 0; i < NDDATA; i++) lp->d_drivedata[i] = clp->drivedata[i]; for (i = 0; i < NSPARE; i++) lp->d_spare[i] = clp->spare[i]; lp->d_magic2 = clp->magic2; lp->d_npartitions = clp->partitions; lp->d_bbsize = clp->bbsize; lp->d_sbsize = clp->sbsize; bcopy(clp->vid_4, &lp->d_partitions[0], sizeof(struct partition) * 4); bcopy(clp->cfg_4, &lp->d_partitions[4], sizeof(struct partition) * 12); if (clp->version < 2) { struct __partitionv0 *v0pp = (struct __partitionv0 *)lp->d_partitions; struct partition *pp = lp->d_partitions; for (i = 0; i < lp->d_npartitions; i++, pp++, v0pp++) { pp->p_fragblock = DISKLABELV1_FFS_FRAGBLOCK(v0pp-> p_fsize, v0pp->p_frag); pp->p_offseth = 0; pp->p_sizeh = 0; } } lp->d_version = 1; lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); return (0); }
void rewritelabel(char *s, int fd, struct disklabel *lp) { if (unlabeled) return; lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) { warn("ioctl (WDINFO)"); fatal("%s: can't rewrite disk label", s); } }
boolean_t rz_bios_bsd_label( target_info_t *tgt, struct disklabel *label, io_req_t ior, struct bios_partition_info *ospart) { struct disklabel *dlp; int dev_bsize = tgt->block_size; int i; extern int allow_bsd_label; ior->io_count = dev_bsize; ior->io_op = IO_READ; tgt->ior = ior; scdisk_read( tgt, (ospart->offset + LBLLOC) * 512 / dev_bsize, ior); iowait(ior); dlp = (struct disklabel *)ior->io_data; if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { if (OS == BSDOS) { printf("NO BSD LABEL!!\n"); } return FALSE; } printf("BSD LABEL "); LABEL_DEBUG(2,print_bsd_label(dlp, "dk:")); /* * here's where we dump label */ if (allow_bsd_label == 0) return FALSE; i = label->d_secperunit; *label = *dlp; label->d_secperunit = i; /* * The disklabel program should insure the invariant below * when it writes a label. But it does not seem to. */ label->d_partitions[MAXPARTITIONS].p_size = -1; label->d_partitions[MAXPARTITIONS].p_offset = 0; label->d_checksum = dkcksum(label); tgt->dev_info.disk.labeloffset = 0; tgt->dev_info.disk.labelsector = (ospart->offset + LBLLOC) * 512 / dev_bsize; LABEL_DEBUG(0x20,print_bsd_label(dlp, " ")); return TRUE; }
/* * Read the disklabel from a vnd. If one is not present, create a fake one. */ static void maru_getdisklabel(struct maru_softc *sc) { struct disklabel *lp = sc->sc_dkdev.dk_label; struct cpu_disklabel *clp = sc->sc_dkdev.dk_cpulabel; int i; char *errstring; DB("maru_getdisklabel(%p)\n", sc); bzero(clp, sizeof(*clp)); maru_getdefaultlabel(sc, lp); /* * Call the generic disklabel extraction routine. */ errstring = "blah" ; /* readdisklabel(MARULABELDEV(sc->sc_dev), marustrategy, lp, clp); */ if (errstring) { /* * Lack of disklabel is common, but we print the warning * anyway, since it might contain other useful information. */ printf("maru_getdisklable(%p) %s: %s\n", sc, sc->sc_xname, errstring); /* * For historical reasons, if there's no disklabel * present, all partitions must be FS_BSDFFS and * occupy the entire disk. */ for (i = 0; i < MAXPARTITIONS; i++) { /* * Don't wipe out port specific hack (such as * dos partition hack of i386 port). */ if (lp->d_partitions[i].p_fstype != FS_UNUSED) continue; lp->d_partitions[i].p_size = lp->d_secperunit; lp->d_partitions[i].p_offset = 0; lp->d_partitions[i].p_fstype = FS_BSDFFS; } strncpy(lp->d_packname, "default label", sizeof(lp->d_packname)); lp->d_checksum = dkcksum(lp); } }
/* * Write disk label back to device after modification. */ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct cpu_disklabel *osdep) { struct buf *bp; struct disklabel *dlp; int error; #ifdef maybe /* disklabel in appropriate location? */ if (lp->d_partitions[2].p_offset != 0 && lp->d_partitions[2].p_offset != dospartoff) { error = EXDEV; goto done; } #endif /* get a buffer and initialize it */ bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; bp->b_blkno = LABELSECTOR; bp->b_cylinder = 0; bp->b_bcount = lp->d_secsize; bp->b_flags |= B_READ; (*strat)(bp); /* if successful, locate disk label within block and validate */ if ((error = biowait(bp)) != 0) goto done; for (dlp = (struct disklabel *)bp->b_data; dlp <= (struct disklabel *)((char *)bp->b_data + lp->d_secsize - sizeof(*dlp)); dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC && dkcksum(dlp) == 0) { *dlp = *lp; bp->b_cflags = BC_BUSY; bp->b_flags = B_WRITE; CLR(bp->b_oflags, BO_DONE); (*strat)(bp); error = biowait(bp); goto done; } } error = ESRCH; done: brelse(bp, 0); return (error); }
void disklabel_show(struct disklabel *lp) { int i; struct partition *pp; /* * Check for valid disklabel. */ if (lp->d_magic != DISKMAGIC || lp->d_magic2 != DISKMAGIC) { printf("No disklabel to show.\n"); return; } if (lp->d_npartitions > MAXPARTITIONS || dkcksum(lp) != 0) { printf("Corrupted disklabel.\n"); return; } printf("\ndisk type %d (%s), %s: %s%s%s\n", lp->d_type, lp->d_type < DKMAXTYPES ? dktypenames[lp->d_type] : dktypenames[0], lp->d_typename, (lp->d_flags & D_REMOVABLE) ? " removable" : "", (lp->d_flags & D_ECC) ? " ecc" : "", (lp->d_flags & D_BADSECT) ? " badsect" : ""); printf("interleave %d, rpm %d, trackskew %d, cylinderskew %d\n", lp->d_interleave, lp->d_rpm, lp->d_trackskew, lp->d_cylskew); printf("headswitch %d, track-to-track %d, drivedata: %d %d %d %d %d\n", lp->d_headswitch, lp->d_trkseek, lp->d_drivedata[0], lp->d_drivedata[1], lp->d_drivedata[2], lp->d_drivedata[3], lp->d_drivedata[4]); printf("\nbytes/sector: %d\n", lp->d_secsize); printf("sectors/track: %d\n", lp->d_nsectors); printf("tracks/cylinder: %d\n", lp->d_ntracks); printf("sectors/cylinder: %d\n", lp->d_secpercyl); printf("cylinders: %d\n", lp->d_ncylinders); printf("total sectors: %d\n", lp->d_secperunit); printf("\n%d partitions:\n", lp->d_npartitions); printf(" size offset\n"); pp = lp->d_partitions; for (i = 0; i < lp->d_npartitions; i++) { printf("%c: %d, %d\n", 'a' + i, pp[i].p_size, pp[i].p_offset); } printf("\n"); }
/* * Find a valid disklabel. */ static char * search_label(struct of_dev *devp, u_long off, char *buf, struct disklabel *lp, u_long off0) { size_t read; struct mbr_partition *p; int i; u_long poff; static int recursion; struct disklabel *dlp; struct sun_disklabel *slp; int error; /* minimal requirements for archetypal disk label */ if (lp->d_secperunit == 0) lp->d_secperunit = 0x1fffffff; lp->d_npartitions = MAXPARTITIONS; if (lp->d_partitions[0].p_size == 0) lp->d_partitions[0].p_size = 0x1fffffff; lp->d_partitions[0].p_offset = 0; if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read) || read != DEV_BSIZE) return ("Cannot read label"); /* Check for a disk label. */ dlp = (struct disklabel *) (buf + LABELOFFSET); if (dlp->d_magic == DISKMAGIC) { if (dkcksum(dlp)) return ("corrupt disk label"); *lp = *dlp; DNPRINTF(BOOT_D_OFDEV, "search_label: found disk label\n"); return (NULL); } /* Check for a Sun disk label (for PROM compatibility). */ slp = (struct sun_disklabel *)buf; if (slp->sl_magic == SUN_DKMAGIC) { if (disklabel_sun_to_bsd(slp, lp) != 0) return ("corrupt disk label"); DNPRINTF(BOOT_D_OFDEV, "search_label: found disk label\n"); return (NULL); } bzero(buf, sizeof(buf)); return ("no disk label"); }