Mon Sep 20 06:54:06 2010 UTC ()
Check disk bounds, in RAW_PART.


(kiyohara)
diff -r1.67 -r1.68 src/sys/dev/ld.c
diff -r1.17 -r1.18 src/sys/dev/ldvar.h

cvs diff -r1.67 -r1.68 src/sys/dev/ld.c (expand / switch to unified diff)

--- src/sys/dev/ld.c 2010/08/19 17:59:10 1.67
+++ src/sys/dev/ld.c 2010/09/20 06:54:06 1.68
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ld.c,v 1.67 2010/08/19 17:59:10 jmcneill Exp $ */ 1/* $NetBSD: ld.c,v 1.68 2010/09/20 06:54:06 kiyohara Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2000 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 Andrew Doran and Charles M. Hannum. 8 * by Andrew Doran and Charles M. Hannum.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Disk driver for use by RAID controllers. 33 * Disk driver for use by RAID controllers.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.67 2010/08/19 17:59:10 jmcneill Exp $"); 37__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.68 2010/09/20 06:54:06 kiyohara Exp $");
38 38
39#include "rnd.h" 39#include "rnd.h"
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/device.h> 44#include <sys/device.h>
45#include <sys/queue.h> 45#include <sys/queue.h>
46#include <sys/proc.h> 46#include <sys/proc.h>
47#include <sys/buf.h> 47#include <sys/buf.h>
48#include <sys/bufq.h> 48#include <sys/bufq.h>
49#include <sys/endian.h> 49#include <sys/endian.h>
50#include <sys/disklabel.h> 50#include <sys/disklabel.h>
@@ -135,26 +135,27 @@ ldattach(struct ld_softc *sc) @@ -135,26 +135,27 @@ ldattach(struct ld_softc *sc)
135 sc->sc_ncylinders = INT_MAX; 135 sc->sc_ncylinders = INT_MAX;
136 ncyl = sc->sc_secperunit / 136 ncyl = sc->sc_secperunit /
137 (sc->sc_nheads * sc->sc_nsectors); 137 (sc->sc_nheads * sc->sc_nsectors);
138 if (ncyl < INT_MAX) 138 if (ncyl < INT_MAX)
139 sc->sc_ncylinders = (int)ncyl; 139 sc->sc_ncylinders = (int)ncyl;
140 } 140 }
141 141
142 format_bytes(tbuf, sizeof(tbuf), sc->sc_secperunit * 142 format_bytes(tbuf, sizeof(tbuf), sc->sc_secperunit *
143 sc->sc_secsize); 143 sc->sc_secsize);
144 aprint_normal_dev(sc->sc_dv, "%s, %d cyl, %d head, %d sec, " 144 aprint_normal_dev(sc->sc_dv, "%s, %d cyl, %d head, %d sec, "
145 "%d bytes/sect x %"PRIu64" sectors\n", 145 "%d bytes/sect x %"PRIu64" sectors\n",
146 tbuf, sc->sc_ncylinders, sc->sc_nheads, 146 tbuf, sc->sc_ncylinders, sc->sc_nheads,
147 sc->sc_nsectors, sc->sc_secsize, sc->sc_secperunit); 147 sc->sc_nsectors, sc->sc_secsize, sc->sc_secperunit);
 148 sc->sc_disksize512 = sc->sc_secperunit * sc->sc_secsize / DEV_BSIZE;
148 149
149 ld_set_properties(sc); 150 ld_set_properties(sc);
150 151
151#if NRND > 0 152#if NRND > 0
152 /* Attach the device into the rnd source list. */ 153 /* Attach the device into the rnd source list. */
153 rnd_attach_source(&sc->sc_rnd_source, device_xname(sc->sc_dv), 154 rnd_attach_source(&sc->sc_rnd_source, device_xname(sc->sc_dv),
154 RND_TYPE_DISK, 0); 155 RND_TYPE_DISK, 0);
155#endif 156#endif
156 157
157 /* Register with PMF */ 158 /* Register with PMF */
158 if (!pmf_device_register1(sc->sc_dv, ld_suspend, NULL, ld_shutdown)) 159 if (!pmf_device_register1(sc->sc_dv, ld_suspend, NULL, ld_shutdown))
159 aprint_error_dev(sc->sc_dv, 160 aprint_error_dev(sc->sc_dv,
160 "couldn't establish power handler\n"); 161 "couldn't establish power handler\n");
@@ -616,30 +617,34 @@ ldstrategy(struct buf *bp) @@ -616,30 +617,34 @@ ldstrategy(struct buf *bp)
616 if ((bp->b_bcount % lp->d_secsize) != 0 || bp->b_blkno < 0) { 617 if ((bp->b_bcount % lp->d_secsize) != 0 || bp->b_blkno < 0) {
617 bp->b_error = EINVAL; 618 bp->b_error = EINVAL;
618 goto done; 619 goto done;
619 } 620 }
620 621
621 /* If it's a null transfer, return immediately. */ 622 /* If it's a null transfer, return immediately. */
622 if (bp->b_bcount == 0) 623 if (bp->b_bcount == 0)
623 goto done; 624 goto done;
624 625
625 /* 626 /*
626 * Do bounds checking and adjust the transfer. If error, process. 627 * Do bounds checking and adjust the transfer. If error, process.
627 * If past the end of partition, just return. 628 * If past the end of partition, just return.
628 */ 629 */
629 if (part != RAW_PART && 630 if (part == RAW_PART) {
630 bounds_check_with_label(&sc->sc_dk, bp, 631 if (bounds_check_with_mediasize(bp, DEV_BSIZE,
631 (sc->sc_flags & (LDF_WLABEL | LDF_LABELLING)) != 0) <= 0) { 632 sc->sc_disksize512) <= 0)
632 goto done; 633 goto done;
 634 } else {
 635 if (bounds_check_with_label(&sc->sc_dk, bp,
 636 (sc->sc_flags & (LDF_WLABEL | LDF_LABELLING)) != 0) <= 0)
 637 goto done;
633 } 638 }
634 639
635 /* 640 /*
636 * Convert the block number to absolute and put it in terms 641 * Convert the block number to absolute and put it in terms
637 * of the device's logical block size. 642 * of the device's logical block size.
638 */ 643 */
639 if (lp->d_secsize == DEV_BSIZE) 644 if (lp->d_secsize == DEV_BSIZE)
640 blkno = bp->b_blkno; 645 blkno = bp->b_blkno;
641 else if (lp->d_secsize > DEV_BSIZE) 646 else if (lp->d_secsize > DEV_BSIZE)
642 blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE); 647 blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
643 else 648 else
644 blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize); 649 blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
645 650

cvs diff -r1.17 -r1.18 src/sys/dev/ldvar.h (expand / switch to unified diff)

--- src/sys/dev/ldvar.h 2009/12/18 00:40:24 1.17
+++ src/sys/dev/ldvar.h 2010/09/20 06:54:06 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ldvar.h,v 1.17 2009/12/18 00:40:24 jakllsch Exp $ */ 1/* $NetBSD: ldvar.h,v 1.18 2010/09/20 06:54:06 kiyohara Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 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 Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -42,26 +42,27 @@ @@ -42,26 +42,27 @@
42 42
43struct ld_softc { 43struct ld_softc {
44 device_t sc_dv; 44 device_t sc_dv;
45 struct disk sc_dk; 45 struct disk sc_dk;
46 struct bufq_state *sc_bufq; 46 struct bufq_state *sc_bufq;
47 kmutex_t sc_mutex; 47 kmutex_t sc_mutex;
48#if NRND > 0 48#if NRND > 0
49 rndsource_element_t sc_rnd_source; 49 rndsource_element_t sc_rnd_source;
50#endif 50#endif
51 int sc_queuecnt; /* current h/w queue depth */ 51 int sc_queuecnt; /* current h/w queue depth */
52 int sc_ncylinders; /* # cylinders */ 52 int sc_ncylinders; /* # cylinders */
53 int sc_nheads; /* # heads */ 53 int sc_nheads; /* # heads */
54 int sc_nsectors; /* # sectors per track */ 54 int sc_nsectors; /* # sectors per track */
 55 int sc_disksize512;
55 56
56 /* 57 /*
57 * The following are filled by hardware specific attachment code. 58 * The following are filled by hardware specific attachment code.
58 */ 59 */
59 int sc_flags; /* control flags */ 60 int sc_flags; /* control flags */
60 uint64_t sc_secperunit; /* # sectors in total */ 61 uint64_t sc_secperunit; /* # sectors in total */
61 int sc_secsize; /* sector size in bytes */ 62 int sc_secsize; /* sector size in bytes */
62 int sc_maxxfer; /* max xfer size in bytes */ 63 int sc_maxxfer; /* max xfer size in bytes */
63 int sc_maxqueuecnt; /* maximum h/w queue depth */ 64 int sc_maxqueuecnt; /* maximum h/w queue depth */
64 65
65 int (*sc_dump)(struct ld_softc *, void *, int, int); 66 int (*sc_dump)(struct ld_softc *, void *, int, int);
66 int (*sc_flush)(struct ld_softc *, int); 67 int (*sc_flush)(struct ld_softc *, int);
67 int (*sc_start)(struct ld_softc *, struct buf *); 68 int (*sc_start)(struct ld_softc *, struct buf *);