Module Name: src
Committed By: riz
Date: Fri Jan 7 06:33:45 UTC 2011
Modified Files:
src/sys/kern [netbsd-5]: subr_disk.c
src/sys/sys [netbsd-5]: device.h
Log Message:
Pull up following revision(s) (requested by mrg in ticket #1520):
sys/sys/device.h: revision 1.133
sys/kern/subr_disk.c: patch
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.93.10.2 -r1.93.10.3 src/sys/kern/subr_disk.c
cvs rdiff -u -r1.112.6.1 -r1.112.6.2 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.c
diff -u src/sys/kern/subr_disk.c:1.93.10.2 src/sys/kern/subr_disk.c:1.93.10.3
--- src/sys/kern/subr_disk.c:1.93.10.2 Sun Nov 21 21:48:28 2010
+++ src/sys/kern/subr_disk.c Fri Jan 7 06:33:45 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_disk.c,v 1.93.10.2 2010/11/21 21:48:28 riz Exp $ */
+/* $NetBSD: subr_disk.c,v 1.93.10.3 2011/01/07 06:33:45 riz Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.93.10.2 2010/11/21 21:48:28 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.93.10.3 2011/01/07 06:33:45 riz Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -77,6 +77,9 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
#include <sys/sysctl.h>
+#include <sys/fcntl.h>
+#include <sys/kauth.h>
+#include <sys/vnode_if.h>
#include <lib/libkern/libkern.h>
/*
@@ -493,3 +496,31 @@
return (error);
}
+
+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.112.6.1 src/sys/sys/device.h:1.112.6.2
--- src/sys/sys/device.h:1.112.6.1 Sun Mar 15 19:43:48 2009
+++ src/sys/sys/device.h Fri Jan 7 06:33:44 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.112.6.1 2009/03/15 19:43:48 snj Exp $ */
+/* $NetBSD: device.h,v 1.112.6.2 2011/01/07 06:33:44 riz Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -389,6 +389,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);