Add helper function that determines the size and block size of a disk device.

For now we query
- the disk label
- the wedge info and data from disk(9)
This commit is contained in:
mlelstv 2010-01-30 11:57:17 +00:00
parent 05f103b5db
commit 49be4d025a
2 changed files with 32 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_disk_open.c,v 1.1 2009/09/06 16:18:56 pooka Exp $ */
/* $NetBSD: subr_disk_open.c,v 1.2 2010/01/30 11:57:17 mlelstv Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.1 2009/09/06 16:18:56 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.2 2010/01/30 11:57:17 mlelstv Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@ -80,3 +80,31 @@ opendisk(struct device *dv)
return tmpvn;
}
int
getdisksize(struct vnode *vp, uint64_t *numsecp, unsigned *secsizep)
{
struct partinfo dpart;
struct dkwedge_info dkw;
struct disk *pdk;
int error;
error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED);
if (error == 0) {
*secsizep = dpart.disklab->d_secsize;
*numsecp = dpart.part->p_size;
return 0;
}
error = VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED);
if (error == 0) {
pdk = disk_find(dkw.dkw_parent);
if (pdk != NULL) {
*secsizep = DEV_BSIZE << pdk->dk_blkshift;
*numsecp = dkw.dkw_size;
} else
error = ENODEV;
}
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: device.h,v 1.132 2010/01/10 20:11:50 martin Exp $ */
/* $NetBSD: device.h,v 1.133 2010/01/30 11:57:18 mlelstv Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -426,6 +426,7 @@ extern device_t booted_wedge; /* the wedge on that device */
extern int booted_partition; /* or the partition on that device */
struct vnode *opendisk(struct device *);
int getdisksize(struct vnode *, uint64_t *, unsigned *);
int config_handle_wedges(struct device *, int);
void config_init(void);