Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add helper function that determines the size and block s...
details: https://anonhg.NetBSD.org/src/rev/34ea2e0c52c9
branches: trunk
changeset: 751255:34ea2e0c52c9
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sat Jan 30 11:57:17 2010 +0000
description:
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)
diffstat:
sys/kern/subr_disk_open.c | 32 ++++++++++++++++++++++++++++++--
sys/sys/device.h | 3 ++-
2 files changed, 32 insertions(+), 3 deletions(-)
diffs (67 lines):
diff -r d1d48266fdb7 -r 34ea2e0c52c9 sys/kern/subr_disk_open.c
--- a/sys/kern/subr_disk_open.c Sat Jan 30 08:57:49 2010 +0000
+++ b/sys/kern/subr_disk_open.c Sat Jan 30 11:57:17 2010 +0000
@@ -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;
+}
diff -r d1d48266fdb7 -r 34ea2e0c52c9 sys/sys/device.h
--- a/sys/sys/device.h Sat Jan 30 08:57:49 2010 +0000
+++ b/sys/sys/device.h Sat Jan 30 11:57:17 2010 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index