| @@ -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 | */ |
85 | u_int | | 88 | u_int |
86 | dkcksum(struct disklabel *lp) | | 89 | dkcksum(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 | |
91 | u_int | | 94 | u_int |
92 | dkcksum_sized(struct disklabel *lp, size_t npartitions) | | 95 | dkcksum_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 | |
| | | 500 | int |
| | | 501 | getdisksize(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 | } |