Source-Changes-HG archive

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

[src/trunk]: src/lib/librumpuser Support query of the partition size in case ...



details:   https://anonhg.NetBSD.org/src/rev/6a8ad1ae0991
branches:  trunk
changeset: 761749:6a8ad1ae0991
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Feb 06 21:05:53 2011 +0000

description:
Support query of the partition size in case underlying device is
a wedge.  This still lacks the proplibistic query of the sector
size and just assumes 512.  It's good that we make asking a file's
size as simple as requiring one stat(), one open() and three (3)
different ioctls plus some proplist mumbojumbo.  I'm surprised it's
available at all by means other than #wish.

code mostly from Taylor R Campbell, rant from me.

diffstat:

 lib/librumpuser/rumpuser.c |  29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)

diffs (68 lines):

diff -r d2899908cb12 -r 6a8ad1ae0991 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Sun Feb 06 19:38:48 2011 +0000
+++ b/lib/librumpuser/rumpuser.c        Sun Feb 06 21:05:53 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.14 2011/01/22 14:22:10 pooka Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.15 2011/02/06 21:05:53 pooka Exp $      */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.14 2011/01/22 14:22:10 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.15 2011/02/06 21:05:53 pooka Exp $");
 #endif /* !lint */
 
 /* thank the maker for this */
@@ -45,7 +45,9 @@
 #include <sys/uio.h>
 
 #ifdef __NetBSD__
+#include <sys/disk.h>
 #include <sys/disklabel.h>
+#include <sys/dkio.h>
 #include <sys/sysctl.h>
 #endif
 
@@ -147,6 +149,7 @@
 #else
                struct disklabel lab;
                struct partition *parta;
+               struct dkwedge_info dkw;
 
                fd = open(path, O_RDONLY);
                if (fd == -1) {
@@ -155,14 +158,26 @@
                        goto out;
                }
 
-               if (ioctl(fd, DIOCGDINFO, &lab) == -1) {
-                       seterror(errno);
-                       rv = -1;
+               if (ioctl(fd, DIOCGDINFO, &lab) == 0) {
+                       parta = &lab.d_partitions[DISKPART(sb.st_rdev)];
+                       size = (uint64_t)lab.d_secsize * parta->p_size;
                        goto out;
                }
 
-               parta = &lab.d_partitions[DISKPART(sb.st_rdev)];
-               size = (uint64_t)lab.d_secsize * parta->p_size;
+               if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == 0) {
+                       /*
+                        * XXX: should use DIOCGDISKINFO to query
+                        * sector size, but that requires proplib,
+                        * so just don't bother for now.  it's nice
+                        * that something as difficult as figuring out
+                        * a partition's size has been made so easy.
+                        */
+                       size = dkw.dkw_size << DEV_BSHIFT;
+                       goto out;
+               }
+
+               seterror(errno);
+               rv = -1;
 #endif /* __NetBSD__ */
        }
 



Home | Main Index | Thread Index | Old Index