Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Add getdiskinfo() to centralize the DIOCGPART mess ...



details:   https://anonhg.NetBSD.org/src/rev/eb98914c6e26
branches:  trunk
changeset: 771194:eb98914c6e26
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Nov 13 22:54:05 2011 +0000

description:
Add getdiskinfo() to centralize the DIOCGPART mess in one place.

diffstat:

 sys/kern/subr_disk_open.c |  35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diffs (60 lines):

diff -r e3810740fc6b -r eb98914c6e26 sys/kern/subr_disk_open.c
--- a/sys/kern/subr_disk_open.c Sun Nov 13 22:25:21 2011 +0000
+++ b/sys/kern/subr_disk_open.c Sun Nov 13 22:54:05 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_disk_open.c,v 1.3 2011/07/30 12:08:36 jmcneill Exp $      */
+/*     $NetBSD: subr_disk_open.c,v 1.4 2011/11/13 22:54:05 christos 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.3 2011/07/30 12:08:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk_open.c,v 1.4 2011/11/13 22:54:05 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -37,6 +37,7 @@
 #include <sys/fcntl.h>
 #include <sys/kauth.h>
 #include <sys/vnode.h>
+#include <miscfs/specfs/specdev.h>
 
 struct vnode *
 opendisk(struct device *dv)
@@ -108,3 +109,33 @@
 
        return error;
 }
+
+int
+getdiskinfo(struct vnode *vp, struct dkwedge_info *dkw)
+{
+       struct partinfo dpart;
+       int error;
+       dev_t dev = vp->v_specnode->sn_rdev;
+
+       if (VOP_IOCTL(vp, DIOCGWEDGEINFO, dkw, FREAD, NOCRED) == 0)
+               return 0;
+       
+       if ((error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED)) != 0)
+               return error;
+
+       snprintf(dkw->dkw_devname, sizeof(dkw->dkw_devname), "%s%" PRId32 "%c",
+           devsw_blk2name(major(dev)), DISKUNIT(dev), (char)DISKPART(dev) +
+           'a');
+
+       dkw->dkw_wname[0] = '\0';
+
+       strlcpy(dkw->dkw_parent, dkw->dkw_devname, sizeof(dkw->dkw_parent));
+
+       dkw->dkw_size = dpart.part->p_size;
+       dkw->dkw_offset = dpart.part->p_offset;
+
+       strlcpy(dkw->dkw_ptype, getfstypename(dpart.part->p_fstype),
+           sizeof(dkw->dkw_ptype));
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index