void vdsp_open(void *arg1, void *arg2) { struct vdsp_softc *sc = arg1; struct proc *p = curproc; struct vd_attr_info ai; if (sc->sc_vp == NULL) { struct nameidata nd; struct vattr va; const char *name; int error; name = mdesc_get_prop_str(sc->sc_idx, "vds-block-device"); if (name == NULL) return; NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p); error = vn_open(&nd, FREAD | FWRITE, 0); if (error) { printf("VOP_OPEN: %s, %d\n", name, error); return; } error = VOP_GETATTR(nd.ni_vp, &va, p->p_ucred, p); if (error) printf("VOP_GETATTR: %s, %d\n", name, error); sc->sc_vdisk_block_size = DEV_BSIZE; sc->sc_vdisk_size = va.va_size / DEV_BSIZE; VOP_UNLOCK(nd.ni_vp, 0, p); sc->sc_vp = nd.ni_vp; vdsp_readlabel(sc); } bzero(&ai, sizeof(ai)); ai.tag.type = VIO_TYPE_CTRL; ai.tag.stype = VIO_SUBTYPE_ACK; ai.tag.stype_env = VIO_ATTR_INFO; ai.tag.sid = sc->sc_local_sid; ai.xfer_mode = sc->sc_xfer_mode; ai.vd_type = VD_DISK_TYPE_DISK; if (sc->sc_major > 1 || sc->sc_minor >= 1) { if (vdsp_is_iso(sc)) ai.vd_mtype = VD_MEDIA_TYPE_CD; else ai.vd_mtype = VD_MEDIA_TYPE_FIXED; } ai.vdisk_block_size = sc->sc_vdisk_block_size; ai.operations = VD_OP_MASK; ai.vdisk_size = sc->sc_vdisk_size; ai.max_xfer_sz = MAXPHYS / sc->sc_vdisk_block_size; vdsp_sendmsg(sc, &ai, sizeof(ai), 1); }
void vdsp_get_vtoc(void *arg1, void *arg2) { struct vdsp_softc *sc = arg1; struct ldc_conn *lc = &sc->sc_lc; struct vd_desc *vd = arg2; struct sun_vtoc_preamble *sl; struct vd_vtoc *vt; vaddr_t va; paddr_t pa; uint64_t size, off; psize_t nbytes; int err, i; vt = malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO); if (sc->sc_label == NULL) vdsp_readlabel(sc); if (sc->sc_label && sc->sc_label->sl_magic == SUN_DKMAGIC) { sl = (struct sun_vtoc_preamble *)sc->sc_label; memcpy(vt->ascii_label, sl->sl_text, sizeof(sl->sl_text)); memcpy(vt->volume_name, sl->sl_volume, sizeof(sl->sl_volume)); vt->sector_size = DEV_BSIZE; vt->num_partitions = sl->sl_nparts; for (i = 0; i < vt->num_partitions; i++) { vt->partition[i].id_tag = sl->sl_part[i].spi_tag; vt->partition[i].perm = sl->sl_part[i].spi_flag; vt->partition[i].start = sc->sc_label->sl_part[i].sdkp_cyloffset * sc->sc_label->sl_ntracks * sc->sc_label->sl_nsectors; vt->partition[i].nblocks = sc->sc_label->sl_part[i].sdkp_nsectors; } } else { uint64_t disk_size; int unit; /* Human-readable disk size. */ disk_size = sc->sc_vdisk_size * sc->sc_vdisk_block_size; disk_size >>= 10; unit = 'K'; if (disk_size > (2 << 10)) { disk_size >>= 10; unit = 'M'; } if (disk_size > (2 << 10)) { disk_size >>= 10; unit = 'G'; }