Fri Jan 7 06:33:45 2011 UTC ()
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)


(riz)
diff -r1.93.10.2 -r1.93.10.3 src/sys/kern/subr_disk.c
diff -r1.112.6.1 -r1.112.6.2 src/sys/sys/device.h

cvs diff -r1.93.10.2 -r1.93.10.3 src/sys/kern/subr_disk.c (expand / switch to unified diff)

--- src/sys/kern/subr_disk.c 2010/11/21 21:48:28 1.93.10.2
+++ src/sys/kern/subr_disk.c 2011/01/07 06:33:45 1.93.10.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_disk.c,v 1.93.10.2 2010/11/21 21:48:28 riz Exp $ */ 1/* $NetBSD: subr_disk.c,v 1.93.10.3 2011/01/07 06:33:45 riz Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,36 +57,39 @@ @@ -57,36 +57,39 @@
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * @(#)ufs_disksubr.c 8.5 (Berkeley) 1/21/94 66 * @(#)ufs_disksubr.c 8.5 (Berkeley) 1/21/94
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.93.10.2 2010/11/21 21:48:28 riz Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.93.10.3 2011/01/07 06:33:45 riz Exp $");
71 71
72#include <sys/param.h> 72#include <sys/param.h>
73#include <sys/kernel.h> 73#include <sys/kernel.h>
74#include <sys/malloc.h> 74#include <sys/malloc.h>
75#include <sys/buf.h> 75#include <sys/buf.h>
76#include <sys/syslog.h> 76#include <sys/syslog.h>
77#include <sys/disklabel.h> 77#include <sys/disklabel.h>
78#include <sys/disk.h> 78#include <sys/disk.h>
79#include <sys/sysctl.h> 79#include <sys/sysctl.h>
 80#include <sys/fcntl.h>
 81#include <sys/kauth.h>
 82#include <sys/vnode_if.h>
80#include <lib/libkern/libkern.h> 83#include <lib/libkern/libkern.h>
81 84
82/* 85/*
83 * Compute checksum for disk label. 86 * Compute checksum for disk label.
84 */ 87 */
85u_int 88u_int
86dkcksum(struct disklabel *lp) 89dkcksum(struct disklabel *lp)
87{ 90{
88 return dkcksum_sized(lp, lp->d_npartitions); 91 return dkcksum_sized(lp, lp->d_npartitions);
89} 92}
90 93
91u_int 94u_int
92dkcksum_sized(struct disklabel *lp, size_t npartitions) 95dkcksum_sized(struct disklabel *lp, size_t npartitions)
@@ -483,13 +486,41 @@ disk_ioctl(struct disk *diskp, u_long cm @@ -483,13 +486,41 @@ disk_ioctl(struct disk *diskp, u_long cm
483 error = ENOTSUP; 486 error = ENOTSUP;
484 else 487 else
485 error = prop_dictionary_copyout_ioctl(pref, cmd, 488 error = prop_dictionary_copyout_ioctl(pref, cmd,
486 diskp->dk_info); 489 diskp->dk_info);
487 break; 490 break;
488 } 491 }
489 492
490 default: 493 default:
491 error = EPASSTHROUGH; 494 error = EPASSTHROUGH;
492 } 495 }
493 496
494 return (error); 497 return (error);
495} 498}
 499
 500int
 501getdisksize(struct vnode *vp, uint64_t *numsecp, unsigned *secsizep)
 502{
 503 struct partinfo dpart;
 504 struct dkwedge_info dkw;
 505 struct disk *pdk;
 506 int error;
 507
 508 error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED);
 509 if (error == 0) {
 510 *secsizep = dpart.disklab->d_secsize;
 511 *numsecp = dpart.part->p_size;
 512 return 0;
 513 }
 514
 515 error = VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED);
 516 if (error == 0) {
 517 pdk = disk_find(dkw.dkw_parent);
 518 if (pdk != NULL) {
 519 *secsizep = DEV_BSIZE << pdk->dk_blkshift;
 520 *numsecp = dkw.dkw_size;
 521 } else
 522 error = ENODEV;
 523 }
 524
 525 return error;
 526}

cvs diff -r1.112.6.1 -r1.112.6.2 src/sys/sys/device.h (expand / switch to unified diff)

--- src/sys/sys/device.h 2009/03/15 19:43:48 1.112.6.1
+++ src/sys/sys/device.h 2011/01/07 06:33:44 1.112.6.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: device.h,v 1.112.6.1 2009/03/15 19:43:48 snj Exp $ */ 1/* $NetBSD: device.h,v 1.112.6.2 2011/01/07 06:33:44 riz Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 2000 Christopher G. Demetriou 4 * Copyright (c) 1996, 2000 Christopher G. Demetriou
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -379,26 +379,27 @@ struct pdevinit { @@ -379,26 +379,27 @@ struct pdevinit {
379/* This allows us to wildcard a device unit. */ 379/* This allows us to wildcard a device unit. */
380#define DVUNIT_ANY -1 380#define DVUNIT_ANY -1
381 381
382#ifdef _KERNEL 382#ifdef _KERNEL
383 383
384extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */ 384extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */
385extern struct devicelist alldevs; /* list of all devices */ 385extern struct devicelist alldevs; /* list of all devices */
386extern struct cftablelist allcftables; /* list of all cfdata tables */ 386extern struct cftablelist allcftables; /* list of all cfdata tables */
387extern device_t booted_device; /* the device we booted from */ 387extern device_t booted_device; /* the device we booted from */
388extern device_t booted_wedge; /* the wedge on that device */ 388extern device_t booted_wedge; /* the wedge on that device */
389extern int booted_partition; /* or the partition on that device */ 389extern int booted_partition; /* or the partition on that device */
390 390
391struct vnode *opendisk(struct device *); 391struct vnode *opendisk(struct device *);
 392int getdisksize(struct vnode *, uint64_t *, unsigned *);
392int config_handle_wedges(struct device *, int); 393int config_handle_wedges(struct device *, int);
393 394
394void config_init(void); 395void config_init(void);
395void drvctl_init(void); 396void drvctl_init(void);
396void configure(void); 397void configure(void);
397void configure2(void); 398void configure2(void);
398 399
399int config_cfdriver_attach(struct cfdriver *); 400int config_cfdriver_attach(struct cfdriver *);
400int config_cfdriver_detach(struct cfdriver *); 401int config_cfdriver_detach(struct cfdriver *);
401 402
402int config_cfattach_attach(const char *, struct cfattach *); 403int config_cfattach_attach(const char *, struct cfattach *);
403int config_cfattach_detach(const char *, struct cfattach *); 404int config_cfattach_detach(const char *, struct cfattach *);
404 405