本文整理汇总了C++中DISKPART函数的典型用法代码示例。如果您正苦于以下问题:C++ DISKPART函数的具体用法?C++ DISKPART怎么用?C++ DISKPART使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DISKPART函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dk_translate
static int
dk_translate(struct dk_softc *dksc, struct buf *bp)
{
int part;
int wlabel;
daddr_t blkno;
struct disklabel *lp;
struct disk *dk;
uint64_t numsecs;
unsigned secsize;
lp = dksc->sc_dkdev.dk_label;
dk = &dksc->sc_dkdev;
part = DISKPART(bp->b_dev);
numsecs = dk->dk_geom.dg_secperunit;
secsize = dk->dk_geom.dg_secsize;
/*
* The transfer must be a whole number of blocks and the offset must
* not be negative.
*/
if ((bp->b_bcount % secsize) != 0 || bp->b_blkno < 0) {
bp->b_error = EINVAL;
goto done;
}
/* If there is nothing to do, then we are done */
if (bp->b_bcount == 0)
goto done;
wlabel = dksc->sc_flags & (DKF_WLABEL|DKF_LABELLING);
if (part == RAW_PART) {
uint64_t numblocks = btodb(numsecs * secsize);
if (bounds_check_with_mediasize(bp, DEV_BSIZE, numblocks) <= 0)
goto done;
} else {
if (bounds_check_with_label(&dksc->sc_dkdev, bp, wlabel) <= 0)
goto done;
}
/*
* Convert the block number to absolute and put it in terms
* of the device's logical block size.
*/
if (secsize >= DEV_BSIZE)
blkno = bp->b_blkno / (secsize / DEV_BSIZE);
else
blkno = bp->b_blkno * (DEV_BSIZE / secsize);
if (part != RAW_PART)
blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
bp->b_rawblkno = blkno;
return -1;
done:
bp->b_resid = bp->b_bcount;
return bp->b_error;
}
示例2: ofdisk_close
int
ofdisk_close(dev_t dev, int flags, int fmt, struct lwp *l)
{
struct ofdisk_softc *of =
device_lookup_private(&ofdisk_cd, DISKUNIT(dev));
mutex_enter(&of->sc_dk.dk_openlock);
switch (fmt) {
case S_IFCHR:
of->sc_dk.dk_copenmask &= ~(1 << DISKPART(dev));
break;
case S_IFBLK:
of->sc_dk.dk_bopenmask &= ~(1 << DISKPART(dev));
break;
}
of->sc_dk.dk_openmask = of->sc_dk.dk_copenmask | of->sc_dk.dk_bopenmask;
#ifdef FIRMWORKSBUGS
/*
* This is a hack to get the firmware to flush its buffers.
*/
OF_seek(of->sc_ihandle, 0);
#endif
if (!of->sc_dk.dk_openmask) {
OF_close(of->sc_ihandle);
of->sc_ihandle = 0;
}
mutex_exit(&of->sc_dk.dk_openlock);
return 0;
}
示例3: dk_strategy
void
dk_strategy(struct dk_intf *di, struct dk_softc *dksc, struct buf *bp)
{
int s;
int wlabel;
daddr_t blkno;
DPRINTF_FOLLOW(("dk_strategy(%s, %p, %p)\n",
di->di_dkname, dksc, bp));
if (!(dksc->sc_flags & DKF_INITED)) {
DPRINTF_FOLLOW(("dk_strategy: not inited\n"));
bp->b_error = ENXIO;
biodone(bp);
return;
}
/* XXX look for some more errors, c.f. ld.c */
bp->b_resid = bp->b_bcount;
/* If there is nothing to do, then we are done */
if (bp->b_bcount == 0) {
biodone(bp);
return;
}
wlabel = dksc->sc_flags & (DKF_WLABEL|DKF_LABELLING);
if (DISKPART(bp->b_dev) != RAW_PART &&
bounds_check_with_label(&dksc->sc_dkdev, bp, wlabel) <= 0) {
biodone(bp);
return;
}
blkno = bp->b_blkno;
if (DISKPART(bp->b_dev) != RAW_PART) {
struct partition *pp;
pp =
&dksc->sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)];
blkno += pp->p_offset;
}
bp->b_rawblkno = blkno;
/*
* Start the unit by calling the start routine
* provided by the individual driver.
*/
s = splbio();
bufq_put(dksc->sc_bufq, bp);
dk_start(di, dksc);
splx(s);
return;
}
示例4: ofdisk_strategy
void
ofdisk_strategy(struct buf *bp)
{
struct ofdisk_softc *of =
device_lookup_private(&ofdisk_cd, DISKUNIT(bp->b_dev));
struct partition *p;
u_quad_t off;
int read;
int (*OF_io)(int, void *, int);
daddr_t blkno = bp->b_blkno;
bp->b_resid = 0;
if (bp->b_bcount == 0)
goto done;
OF_io = bp->b_flags & B_READ ? OF_read :
(int(*)(int, void*, int))OF_write;
if (DISKPART(bp->b_dev) != RAW_PART) {
if (bounds_check_with_label(&of->sc_dk, bp, 0) <= 0) {
bp->b_resid = bp->b_bcount;
goto done;
}
p = &of->sc_dk.dk_label->d_partitions[DISKPART(bp->b_dev)];
blkno = bp->b_blkno + p->p_offset;
}
disk_busy(&of->sc_dk);
off = (u_quad_t)blkno * DEV_BSIZE;
read = -1;
do {
if (OF_seek(of->sc_ihandle, off) < 0)
break;
read = OF_io(of->sc_ihandle, bp->b_data, bp->b_bcount);
} while (read == -2);
if (read < 0) {
bp->b_error = EIO;
bp->b_resid = bp->b_bcount;
} else
bp->b_resid = bp->b_bcount - read;
disk_unbusy(&of->sc_dk, bp->b_bcount - bp->b_resid,
(bp->b_flags & B_READ));
done:
biodone(bp);
}
示例5: rdopen
int
rdopen(dev_t dev, int flag, int fmt, struct proc *p)
{
struct rd_softc *sc;
u_int unit, part;
int error;
unit = DISKUNIT(dev);
part = DISKPART(dev);
sc = rdlookup(unit);
if (sc == NULL)
return (ENXIO);
if ((error = disk_lock(&sc->sc_dk)) != 0)
goto unref;
if (sc->sc_dk.dk_openmask == 0) {
/* Load the partition info if not already loaded. */
if ((error = rdgetdisklabel(dev, sc, sc->sc_dk.dk_label, 0))
!= 0)
goto unlock;
}
error = disk_openpart(&sc->sc_dk, part, fmt, 1);
unlock:
disk_unlock(&sc->sc_dk);
unref:
device_unref(&sc->sc_dev);
return (error);
}
示例6: vndsize
static int
vndsize(dev_t dev)
{
struct vnd_softc *sc;
struct disklabel *lp;
int part, unit, omask;
int size;
unit = vndunit(dev);
sc = device_lookup_private(&vnd_cd, unit);
if (sc == NULL)
return -1;
if ((sc->sc_flags & VNF_INITED) == 0)
return -1;
part = DISKPART(dev);
omask = sc->sc_dkdev.dk_openmask & (1 << part);
lp = sc->sc_dkdev.dk_label;
if (omask == 0 && vndopen(dev, 0, S_IFBLK, curlwp)) /* XXX */
return -1;
if (lp->d_partitions[part].p_fstype != FS_SWAP)
size = -1;
else
size = lp->d_partitions[part].p_size *
(lp->d_secsize / DEV_BSIZE);
if (omask == 0 && vndclose(dev, 0, S_IFBLK, curlwp)) /* XXX */
return -1;
return size;
}
示例7: ldsize
int
ldsize(dev_t dev)
{
struct ld_softc *sc;
int part, unit, omask, size;
unit = DISKUNIT(dev);
if ((sc = device_lookup(&ld_cd, unit)) == NULL)
return (ENODEV);
if ((sc->sc_flags & LDF_ENABLED) == 0)
return (ENODEV);
part = DISKPART(dev);
omask = sc->sc_dk.dk_openmask & (1 << part);
if (omask == 0 && ldopen(dev, 0, S_IFBLK, NULL) != 0)
return (-1);
else if (sc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
size = -1;
else
size = sc->sc_dk.dk_label->d_partitions[part].p_size *
(sc->sc_dk.dk_label->d_secsize / DEV_BSIZE);
if (omask == 0 && ldclose(dev, 0, S_IFBLK, NULL) != 0)
return (-1);
return (size);
}
示例8: ofdisk_size
int
ofdisk_size(dev_t dev)
{
struct ofdisk_softc *of;
struct disklabel *lp;
int size, part, omask;
of = device_lookup_private(&ofdisk_cd, DISKUNIT(dev));
if (of == NULL)
return ENXIO;
part = DISKPART(dev);
omask = of->sc_dk.dk_openmask & (1 << part);
lp = of->sc_dk.dk_label;
if (omask == 0 && ofdisk_open(dev, 0, S_IFBLK, curlwp) != 0)
return -1;
if (lp->d_partitions[part].p_fstype != FS_SWAP)
size = -1;
else
size = lp->d_partitions[part].p_size *
(lp->d_secsize / DEV_BSIZE);
if (omask == 0 && ofdisk_close(dev, 0, S_IFBLK, curlwp) != 0)
return -1;
return size;
}
示例9: dk_size
int
dk_size(struct dk_softc *dksc, dev_t dev)
{
const struct dkdriver *dkd = dksc->sc_dkdev.dk_driver;
struct disklabel *lp;
int is_open;
int part;
int size;
if ((dksc->sc_flags & DKF_INITED) == 0)
return -1;
part = DISKPART(dev);
is_open = dksc->sc_dkdev.dk_openmask & (1 << part);
if (!is_open && dkd->d_open(dev, 0, S_IFBLK, curlwp))
return -1;
lp = dksc->sc_dkdev.dk_label;
if (lp->d_partitions[part].p_fstype != FS_SWAP)
size = -1;
else
size = lp->d_partitions[part].p_size *
(lp->d_secsize / DEV_BSIZE);
if (!is_open && dkd->d_close(dev, 0, S_IFBLK, curlwp))
return -1;
return size;
}
示例10: mdopen
static int
mdopen(dev_t dev, int flag, int fmt, struct lwp *l)
{
int unit;
struct md_softc *sc;
unit = MD_UNIT(dev);
sc = device_lookup_private(&md_cd, unit);
if (sc == NULL)
return ENXIO;
/*
* The raw partition is used for ioctl to configure.
*/
if (DISKPART(dev) == RAW_PART)
return 0;
#ifdef MEMORY_DISK_HOOKS
/* Call the open hook to allow loading the device. */
md_open_hook(unit, &sc->sc_md);
#endif
/*
* This is a normal, "slave" device, so
* enforce initialized.
*/
if (sc->sc_type == MD_UNCONFIGURED)
return ENXIO;
return 0;
}
示例11: wdclose
int
wdclose(dev_t dev, int flag, int fmt, struct proc *p)
{
struct wd_softc *wd;
int part = DISKPART(dev);
wd = wdlookup(DISKUNIT(dev));
if (wd == NULL)
return ENXIO;
WDCDEBUG_PRINT(("wdclose\n"), DEBUG_FUNCS);
disk_lock_nointr(&wd->sc_dk);
disk_closepart(&wd->sc_dk, part, fmt);
if (wd->sc_dk.dk_openmask == 0) {
wd_flushcache(wd, 0);
/* XXXX Must wait for I/O to complete! */
}
disk_unlock(&wd->sc_dk);
device_unref(&wd->sc_dev);
return (0);
}
示例12: wdsize
daddr_t
wdsize(dev_t dev)
{
struct wd_softc *wd;
struct disklabel *lp;
int part, omask;
daddr_t size;
WDCDEBUG_PRINT(("wdsize\n"), DEBUG_FUNCS);
wd = wdlookup(DISKUNIT(dev));
if (wd == NULL)
return (-1);
part = DISKPART(dev);
omask = wd->sc_dk.dk_openmask & (1 << part);
if (omask == 0 && wdopen(dev, 0, S_IFBLK, NULL) != 0) {
size = -1;
goto exit;
}
lp = wd->sc_dk.dk_label;
size = DL_SECTOBLK(lp, DL_GETPSIZE(&lp->d_partitions[part]));
if (omask == 0 && wdclose(dev, 0, S_IFBLK, NULL) != 0)
size = -1;
exit:
device_unref(&wd->sc_dev);
return (size);
}
示例13: vndclose
int
vndclose(dev_t dev, int flags, int mode, struct proc *p)
{
int unit = DISKUNIT(dev);
struct vnd_softc *sc;
int part;
DNPRINTF(VDB_FOLLOW, "vndclose(%x, %x, %x, %p)\n", dev, flags, mode, p);
if (unit >= numvnd)
return (ENXIO);
sc = &vnd_softc[unit];
disk_lock_nointr(&sc->sc_dk);
part = DISKPART(dev);
disk_closepart(&sc->sc_dk, part, mode);
#if 0
if (sc->sc_dk.dk_openmask == 0)
sc->sc_flags &= ~VNF_HAVELABEL;
#endif
disk_unlock(&sc->sc_dk);
return (0);
}
示例14: dk_open
/* ARGSUSED */
int
dk_open(struct dk_softc *dksc, dev_t dev,
int flags, int fmt, struct lwp *l)
{
struct disklabel *lp = dksc->sc_dkdev.dk_label;
int part = DISKPART(dev);
int pmask = 1 << part;
int ret = 0;
struct disk *dk = &dksc->sc_dkdev;
DPRINTF_FOLLOW(("%s(%s, %p, 0x%"PRIx64", 0x%x)\n", __func__,
dksc->sc_xname, dksc, dev, flags));
mutex_enter(&dk->dk_openlock);
/*
* If there are wedges, and this is not RAW_PART, then we
* need to fail.
*/
if (dk->dk_nwedges != 0 && part != RAW_PART) {
ret = EBUSY;
goto done;
}
/*
* If we're init'ed and there are no other open partitions then
* update the in-core disklabel.
*/
if ((dksc->sc_flags & DKF_INITED)) {
if ((dksc->sc_flags & DKF_VLABEL) == 0) {
dksc->sc_flags |= DKF_VLABEL;
dk_getdisklabel(dksc, dev);
}
}
/* Fail if we can't find the partition. */
if (part != RAW_PART &&
((dksc->sc_flags & DKF_VLABEL) == 0 ||
part >= lp->d_npartitions ||
lp->d_partitions[part].p_fstype == FS_UNUSED)) {
ret = ENXIO;
goto done;
}
/* Mark our unit as open. */
switch (fmt) {
case S_IFCHR:
dk->dk_copenmask |= pmask;
break;
case S_IFBLK:
dk->dk_bopenmask |= pmask;
break;
}
dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
done:
mutex_exit(&dk->dk_openlock);
return ret;
}
示例15: ccdclose
/* ARGSUSED */
int
ccdclose(dev_t dev, int flags, int fmt, struct proc *p)
{
int unit = ccdunit(dev);
struct ccd_softc *cs;
int error = 0, part;
CCD_DPRINTF(CCDB_FOLLOW, ("ccdclose(%x, %x)\n", dev, flags));
if (unit >= numccd)
return (ENXIO);
cs = &ccd_softc[unit];
if ((error = ccdlock(cs)) != 0)
return (error);
part = DISKPART(dev);
/* ...that much closer to allowing unconfiguration... */
switch (fmt) {
case S_IFCHR:
cs->sc_dkdev.dk_copenmask &= ~(1 << part);
break;
case S_IFBLK:
cs->sc_dkdev.dk_bopenmask &= ~(1 << part);
break;
}
cs->sc_dkdev.dk_openmask =
cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask;
ccdunlock(cs);
return (0);
}