Module Name: src
Committed By: mlelstv
Date: Sat Jan 30 11:57:18 UTC 2010
Modified Files:
src/sys/kern: subr_disk_open.c
src/sys/sys: device.h
Log Message:
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)
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/kern/subr_disk_open.c
cvs rdiff -u -r1.132 -r1.133 src/sys/sys/device.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_disk_open.c
diff -u src/sys/kern/subr_disk_open.c:1.1 src/sys/kern/subr_disk_open.c:1.2
--- src/sys/kern/subr_disk_open.c:1.1 Sun Sep 6 16:18:56 2009
+++ src/sys/kern/subr_disk_open.c Sat Jan 30 11:57:17 2010
@@ -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 @@
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;
+}
Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.132 src/sys/sys/device.h:1.133
--- src/sys/sys/device.h:1.132 Sun Jan 10 20:11:50 2010
+++ src/sys/sys/device.h Sat Jan 30 11:57:18 2010
@@ -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 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);