use a bounded copy. NFCIdiff -r1.93 -r1.94 src/sys/dev/dkwedge/dk.c
(maya)
--- src/sys/dev/dkwedge/dk.c 2016/12/24 16:39:55 1.93
+++ src/sys/dev/dkwedge/dk.c 2017/01/19 00:44:40 1.94
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: dk.c,v 1.93 2016/12/24 16:39:55 mlelstv Exp $ */ | 1 | /* $NetBSD: dk.c,v 1.94 2017/01/19 00:44:40 maya Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2004, 2005, 2006, 2007 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. | 8 | * by Jason R. Thorpe. | |
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. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
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 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.93 2016/12/24 16:39:55 mlelstv Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.94 2017/01/19 00:44:40 maya Exp $"); | |
34 | 34 | |||
35 | #ifdef _KERNEL_OPT | 35 | #ifdef _KERNEL_OPT | |
36 | #include "opt_dkwedge.h" | 36 | #include "opt_dkwedge.h" | |
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/systm.h> | 40 | #include <sys/systm.h> | |
41 | #include <sys/proc.h> | 41 | #include <sys/proc.h> | |
42 | #include <sys/errno.h> | 42 | #include <sys/errno.h> | |
43 | #include <sys/pool.h> | 43 | #include <sys/pool.h> | |
44 | #include <sys/ioctl.h> | 44 | #include <sys/ioctl.h> | |
45 | #include <sys/disklabel.h> | 45 | #include <sys/disklabel.h> | |
46 | #include <sys/disk.h> | 46 | #include <sys/disk.h> | |
@@ -676,27 +676,27 @@ dkwedge_delall1(struct disk *pdk, bool i | @@ -676,27 +676,27 @@ dkwedge_delall1(struct disk *pdk, bool i | |||
676 | if (!idleonly) flags |= DETACH_FORCE; | 676 | if (!idleonly) flags |= DETACH_FORCE; | |
677 | 677 | |||
678 | for (;;) { | 678 | for (;;) { | |
679 | mutex_enter(&pdk->dk_openlock); | 679 | mutex_enter(&pdk->dk_openlock); | |
680 | LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) { | 680 | LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) { | |
681 | if (!idleonly || sc->sc_dk.dk_openmask == 0) | 681 | if (!idleonly || sc->sc_dk.dk_openmask == 0) | |
682 | break; | 682 | break; | |
683 | } | 683 | } | |
684 | if (sc == NULL) { | 684 | if (sc == NULL) { | |
685 | KASSERT(idleonly || pdk->dk_nwedges == 0); | 685 | KASSERT(idleonly || pdk->dk_nwedges == 0); | |
686 | mutex_exit(&pdk->dk_openlock); | 686 | mutex_exit(&pdk->dk_openlock); | |
687 | return; | 687 | return; | |
688 | } | 688 | } | |
689 | strcpy(dkw.dkw_parent, pdk->dk_name); | 689 | strlcpy(dkw.dkw_parent, pdk->dk_name, sizeof(dkw.dkw_parent)); | |
690 | strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev), | 690 | strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev), | |
691 | sizeof(dkw.dkw_devname)); | 691 | sizeof(dkw.dkw_devname)); | |
692 | mutex_exit(&pdk->dk_openlock); | 692 | mutex_exit(&pdk->dk_openlock); | |
693 | (void) dkwedge_del1(&dkw, flags); | 693 | (void) dkwedge_del1(&dkw, flags); | |
694 | } | 694 | } | |
695 | } | 695 | } | |
696 | 696 | |||
697 | /* | 697 | /* | |
698 | * dkwedge_list: [exported function] | 698 | * dkwedge_list: [exported function] | |
699 | * | 699 | * | |
700 | * List all of the wedges on a particular disk. | 700 | * List all of the wedges on a particular disk. | |
701 | */ | 701 | */ | |
702 | int | 702 | int | |
@@ -723,30 +723,31 @@ dkwedge_list(struct disk *pdk, struct dk | @@ -723,30 +723,31 @@ dkwedge_list(struct disk *pdk, struct dk | |||
723 | 723 | |||
724 | mutex_enter(&pdk->dk_openlock); | 724 | mutex_enter(&pdk->dk_openlock); | |
725 | LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) { | 725 | LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) { | |
726 | if (uio.uio_resid < sizeof(dkw)) | 726 | if (uio.uio_resid < sizeof(dkw)) | |
727 | break; | 727 | break; | |
728 | 728 | |||
729 | if (sc->sc_state != DKW_STATE_RUNNING) | 729 | if (sc->sc_state != DKW_STATE_RUNNING) | |
730 | continue; | 730 | continue; | |
731 | 731 | |||
732 | strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev), | 732 | strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev), | |
733 | sizeof(dkw.dkw_devname)); | 733 | sizeof(dkw.dkw_devname)); | |
734 | memcpy(dkw.dkw_wname, sc->sc_wname, sizeof(dkw.dkw_wname)); | 734 | memcpy(dkw.dkw_wname, sc->sc_wname, sizeof(dkw.dkw_wname)); | |
735 | dkw.dkw_wname[sizeof(dkw.dkw_wname) - 1] = '\0'; | 735 | dkw.dkw_wname[sizeof(dkw.dkw_wname) - 1] = '\0'; | |
736 | strcpy(dkw.dkw_parent, sc->sc_parent->dk_name); | 736 | strlcpy(dkw.dkw_parent, sc->sc_parent->dk_name, | |
737 | sizeof(dkw.dkw_parent)); | |||
737 | dkw.dkw_offset = sc->sc_offset; | 738 | dkw.dkw_offset = sc->sc_offset; | |
738 | dkw.dkw_size = sc->sc_size; | 739 | dkw.dkw_size = sc->sc_size; | |
739 | strcpy(dkw.dkw_ptype, sc->sc_ptype); | 740 | strlcpy(dkw.dkw_ptype, sc->sc_ptype, sizeof(dkw.dkw_ptype)); | |
740 | 741 | |||
741 | error = uiomove(&dkw, sizeof(dkw), &uio); | 742 | error = uiomove(&dkw, sizeof(dkw), &uio); | |
742 | if (error) | 743 | if (error) | |
743 | break; | 744 | break; | |
744 | dkwl->dkwl_ncopied++; | 745 | dkwl->dkwl_ncopied++; | |
745 | } | 746 | } | |
746 | dkwl->dkwl_nwedges = pdk->dk_nwedges; | 747 | dkwl->dkwl_nwedges = pdk->dk_nwedges; | |
747 | mutex_exit(&pdk->dk_openlock); | 748 | mutex_exit(&pdk->dk_openlock); | |
748 | 749 | |||
749 | return (error); | 750 | return (error); | |
750 | } | 751 | } | |
751 | 752 | |||
752 | device_t | 753 | device_t | |
@@ -1487,30 +1488,31 @@ dkioctl(dev_t dev, u_long cmd, void *dat | @@ -1487,30 +1488,31 @@ dkioctl(dev_t dev, u_long cmd, void *dat | |||
1487 | else | 1488 | else | |
1488 | error = VOP_IOCTL(sc->sc_parent->dk_rawvp, | 1489 | error = VOP_IOCTL(sc->sc_parent->dk_rawvp, | |
1489 | cmd, data, flag, | 1490 | cmd, data, flag, | |
1490 | l != NULL ? l->l_cred : NOCRED); | 1491 | l != NULL ? l->l_cred : NOCRED); | |
1491 | break; | 1492 | break; | |
1492 | case DIOCGWEDGEINFO: | 1493 | case DIOCGWEDGEINFO: | |
1493 | { | 1494 | { | |
1494 | struct dkwedge_info *dkw = (void *) data; | 1495 | struct dkwedge_info *dkw = (void *) data; | |
1495 | 1496 | |||
1496 | strlcpy(dkw->dkw_devname, device_xname(sc->sc_dev), | 1497 | strlcpy(dkw->dkw_devname, device_xname(sc->sc_dev), | |
1497 | sizeof(dkw->dkw_devname)); | 1498 | sizeof(dkw->dkw_devname)); | |
1498 | memcpy(dkw->dkw_wname, sc->sc_wname, sizeof(dkw->dkw_wname)); | 1499 | memcpy(dkw->dkw_wname, sc->sc_wname, sizeof(dkw->dkw_wname)); | |
1499 | dkw->dkw_wname[sizeof(dkw->dkw_wname) - 1] = '\0'; | 1500 | dkw->dkw_wname[sizeof(dkw->dkw_wname) - 1] = '\0'; | |
1500 | strcpy(dkw->dkw_parent, sc->sc_parent->dk_name); | 1501 | strlcpy(dkw->dkw_parent, sc->sc_parent->dk_name, | |
1502 | sizeof(dkw->dkw_parent)); | |||
1501 | dkw->dkw_offset = sc->sc_offset; | 1503 | dkw->dkw_offset = sc->sc_offset; | |
1502 | dkw->dkw_size = sc->sc_size; | 1504 | dkw->dkw_size = sc->sc_size; | |
1503 | strcpy(dkw->dkw_ptype, sc->sc_ptype); | 1505 | strlcpy(dkw->dkw_ptype, sc->sc_ptype, sizeof(dkw->dkw_ptype)); | |
1504 | 1506 | |||
1505 | break; | 1507 | break; | |
1506 | } | 1508 | } | |
1507 | 1509 | |||
1508 | default: | 1510 | default: | |
1509 | error = ENOTTY; | 1511 | error = ENOTTY; | |
1510 | } | 1512 | } | |
1511 | 1513 | |||
1512 | return (error); | 1514 | return (error); | |
1513 | } | 1515 | } | |
1514 | 1516 | |||
1515 | /* | 1517 | /* | |
1516 | * dkdiscard: [devsw entry point] | 1518 | * dkdiscard: [devsw entry point] |
--- src/sys/dev/dkwedge/dkwedge_apple.c 2015/01/24 02:58:56 1.2
+++ src/sys/dev/dkwedge/dkwedge_apple.c 2017/01/19 00:44:40 1.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: dkwedge_apple.c,v 1.2 2015/01/24 02:58:56 christos Exp $ */ | 1 | /* $NetBSD: dkwedge_apple.c,v 1.3 2017/01/19 00:44:40 maya Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2012 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2012 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 Christos Zoulas. | 8 | * by Christos Zoulas. | |
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 | * Apple support for disk wedges | 33 | * Apple support for disk wedges | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | __KERNEL_RCSID(0, "$NetBSD: dkwedge_apple.c,v 1.2 2015/01/24 02:58:56 christos Exp $"); | 37 | __KERNEL_RCSID(0, "$NetBSD: dkwedge_apple.c,v 1.3 2017/01/19 00:44:40 maya Exp $"); | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #ifdef _KERNEL | 40 | #ifdef _KERNEL | |
41 | #include <sys/systm.h> | 41 | #include <sys/systm.h> | |
42 | #endif | 42 | #endif | |
43 | #include <sys/proc.h> | 43 | #include <sys/proc.h> | |
44 | #include <sys/errno.h> | 44 | #include <sys/errno.h> | |
45 | #include <sys/disk.h> | 45 | #include <sys/disk.h> | |
46 | #include <sys/vnode.h> | 46 | #include <sys/vnode.h> | |
47 | #include <sys/malloc.h> | 47 | #include <sys/malloc.h> | |
48 | #include <sys/bitops.h> | 48 | #include <sys/bitops.h> | |
49 | 49 | |||
50 | #include <sys/bootblock.h> | 50 | #include <sys/bootblock.h> | |
@@ -207,28 +207,28 @@ dkwedge_discover_apple(struct disk *pdk, | @@ -207,28 +207,28 @@ dkwedge_discover_apple(struct disk *pdk, | |||
207 | if (i == __arraycount(map)) | 207 | if (i == __arraycount(map)) | |
208 | continue; | 208 | continue; | |
209 | 209 | |||
210 | ptype = map[i].type; | 210 | ptype = map[i].type; | |
211 | memcpy(&ab, ae->pmBootArgs, sizeof(ab)); | 211 | memcpy(&ab, ae->pmBootArgs, sizeof(ab)); | |
212 | swap_apple_blockzeroblock(&ab); | 212 | swap_apple_blockzeroblock(&ab); | |
213 | if (ab.bzbMagic == APPLE_BZB_MAGIC) { | 213 | if (ab.bzbMagic == APPLE_BZB_MAGIC) { | |
214 | if (ab.bzbType == APPLE_BZB_TYPESWAP) | 214 | if (ab.bzbType == APPLE_BZB_TYPESWAP) | |
215 | ptype = DKW_PTYPE_SWAP; | 215 | ptype = DKW_PTYPE_SWAP; | |
216 | } | 216 | } | |
217 | 217 | |||
218 | struct dkwedge_info dkw; | 218 | struct dkwedge_info dkw; | |
219 | 219 | |||
220 | strcpy(dkw.dkw_ptype, ptype); | 220 | strlcpy(dkw.dkw_ptype, ptype, sizeof(dkw.dkw_ptype)); | |
221 | strcpy(dkw.dkw_parent, pdk->dk_name); | 221 | strlcpy(dkw.dkw_parent, pdk->dk_name, sizeof(dkw.dkw_parent)); | |
222 | dkw.dkw_offset = ae->pmPyPartStart; | 222 | dkw.dkw_offset = ae->pmPyPartStart; | |
223 | dkw.dkw_size = ae->pmPartBlkCnt; | 223 | dkw.dkw_size = ae->pmPartBlkCnt; | |
224 | strlcpy(dkw.dkw_wname, ae->pmPartName, sizeof(dkw.dkw_wname)); | 224 | strlcpy(dkw.dkw_wname, ae->pmPartName, sizeof(dkw.dkw_wname)); | |
225 | error = dkwedge_add(&dkw); | 225 | error = dkwedge_add(&dkw); | |
226 | if (error == EEXIST) | 226 | if (error == EEXIST) | |
227 | aprint_error("%s: wedge named '%s' already " | 227 | aprint_error("%s: wedge named '%s' already " | |
228 | "exists, manual intervention required\n", | 228 | "exists, manual intervention required\n", | |
229 | pdk->dk_name, dkw.dkw_wname); | 229 | pdk->dk_name, dkw.dkw_wname); | |
230 | else if (error) | 230 | else if (error) | |
231 | aprint_error("%s: error %d adding partition " | 231 | aprint_error("%s: error %d adding partition " | |
232 | "%s type %s\n", pdk->dk_name, error, | 232 | "%s type %s\n", pdk->dk_name, error, | |
233 | ae->pmPartType, dkw.dkw_ptype); | 233 | ae->pmPartType, dkw.dkw_ptype); | |
234 | } | 234 | } |
--- src/sys/dev/dkwedge/dkwedge_gpt.c 2016/04/28 00:35:24 1.17
+++ src/sys/dev/dkwedge/dkwedge_gpt.c 2017/01/19 00:44:40 1.18
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: dkwedge_gpt.c,v 1.17 2016/04/28 00:35:24 christos Exp $ */ | 1 | /* $NetBSD: dkwedge_gpt.c,v 1.18 2017/01/19 00:44:40 maya Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2004 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2004 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. | 8 | * by Jason R. Thorpe. | |
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 | * EFI GUID Partition Table support for disk wedges | 33 | * EFI GUID Partition Table support for disk wedges | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | __KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.17 2016/04/28 00:35:24 christos Exp $"); | 37 | __KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.18 2017/01/19 00:44:40 maya Exp $"); | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/systm.h> | 40 | #include <sys/systm.h> | |
41 | #include <sys/proc.h> | 41 | #include <sys/proc.h> | |
42 | #include <sys/errno.h> | 42 | #include <sys/errno.h> | |
43 | #include <sys/disk.h> | 43 | #include <sys/disk.h> | |
44 | #include <sys/vnode.h> | 44 | #include <sys/vnode.h> | |
45 | #include <sys/malloc.h> | 45 | #include <sys/malloc.h> | |
46 | 46 | |||
47 | #include <sys/disklabel_gpt.h> | 47 | #include <sys/disklabel_gpt.h> | |
48 | #include <sys/uuid.h> | 48 | #include <sys/uuid.h> | |
49 | 49 | |||
50 | /* UTF-8 encoding stuff */ | 50 | /* UTF-8 encoding stuff */ | |
@@ -229,57 +229,57 @@ dkwedge_discover_gpt(struct disk *pdk, s | @@ -229,57 +229,57 @@ dkwedge_discover_gpt(struct disk *pdk, s | |||
229 | if (memcmp(&ptype_guid, &ent_type_unused, | 229 | if (memcmp(&ptype_guid, &ent_type_unused, | |
230 | sizeof(ptype_guid)) == 0) | 230 | sizeof(ptype_guid)) == 0) | |
231 | continue; | 231 | continue; | |
232 | 232 | |||
233 | uuid_dec_le(ent->ent_guid, &ent_guid); | 233 | uuid_dec_le(ent->ent_guid, &ent_guid); | |
234 | 234 | |||
235 | uuid_snprintf(ptype_guid_str, sizeof(ptype_guid_str), | 235 | uuid_snprintf(ptype_guid_str, sizeof(ptype_guid_str), | |
236 | &ptype_guid); | 236 | &ptype_guid); | |
237 | uuid_snprintf(ent_guid_str, sizeof(ent_guid_str), | 237 | uuid_snprintf(ent_guid_str, sizeof(ent_guid_str), | |
238 | &ent_guid); | 238 | &ent_guid); | |
239 | 239 | |||
240 | /* figure out the type */ | 240 | /* figure out the type */ | |
241 | ptype = gpt_ptype_guid_to_str(&ptype_guid); | 241 | ptype = gpt_ptype_guid_to_str(&ptype_guid); | |
242 | strcpy(dkw.dkw_ptype, ptype); | 242 | strlcpy(dkw.dkw_ptype, ptype, sizeof(dkw.dkw_ptype)); | |
243 | 243 | |||
244 | strcpy(dkw.dkw_parent, pdk->dk_name); | 244 | strlcpy(dkw.dkw_parent, pdk->dk_name, sizeof(dkw.dkw_parent)); | |
245 | dkw.dkw_offset = le64toh(ent->ent_lba_start); | 245 | dkw.dkw_offset = le64toh(ent->ent_lba_start); | |
246 | dkw.dkw_size = le64toh(ent->ent_lba_end) - dkw.dkw_offset + 1; | 246 | dkw.dkw_size = le64toh(ent->ent_lba_end) - dkw.dkw_offset + 1; | |
247 | 247 | |||
248 | /* XXX Make sure it falls within the disk's data area. */ | 248 | /* XXX Make sure it falls within the disk's data area. */ | |
249 | 249 | |||
250 | if (ent->ent_name[0] == 0x0000) | 250 | if (ent->ent_name[0] == 0x0000) | |
251 | strcpy(dkw.dkw_wname, ent_guid_str); | 251 | strlcpy(dkw.dkw_wname, ent_guid_str, sizeof(dkw.dkw_wname)); | |
252 | else { | 252 | else { | |
253 | c = dkw.dkw_wname; | 253 | c = dkw.dkw_wname; | |
254 | r = sizeof(dkw.dkw_wname) - 1; | 254 | r = sizeof(dkw.dkw_wname) - 1; | |
255 | for (j = 0; ent->ent_name[j] != 0x0000; j++) { | 255 | for (j = 0; ent->ent_name[j] != 0x0000; j++) { | |
256 | n = wput_utf8(c, r, le16toh(ent->ent_name[j])); | 256 | n = wput_utf8(c, r, le16toh(ent->ent_name[j])); | |
257 | if (n == 0) | 257 | if (n == 0) | |
258 | break; | 258 | break; | |
259 | c += n; r -= n; | 259 | c += n; r -= n; | |
260 | } | 260 | } | |
261 | *c = '\0'; | 261 | *c = '\0'; | |
262 | } | 262 | } | |
263 | 263 | |||
264 | /* | 264 | /* | |
265 | * Try with the partition name first. If that fails, | 265 | * Try with the partition name first. If that fails, | |
266 | * use the GUID string. If that fails, punt. | 266 | * use the GUID string. If that fails, punt. | |
267 | */ | 267 | */ | |
268 | if ((error = dkwedge_add(&dkw)) == EEXIST && | 268 | if ((error = dkwedge_add(&dkw)) == EEXIST && | |
269 | strcmp(dkw.dkw_wname, ent_guid_str) != 0) { | 269 | strcmp(dkw.dkw_wname, ent_guid_str) != 0) { | |
270 | char orig[sizeof(dkw.dkw_wname)]; | 270 | char orig[sizeof(dkw.dkw_wname)]; | |
271 | strcpy(orig, dkw.dkw_wname); | 271 | strlcpy(orig, dkw.dkw_wname, sizeof(orig)); | |
272 | strcpy(dkw.dkw_wname, ent_guid_str); | 272 | strlcpy(dkw.dkw_wname, ent_guid_str, sizeof(dkw.dkw_wname)); | |
273 | error = dkwedge_add(&dkw); | 273 | error = dkwedge_add(&dkw); | |
274 | if (!error) | 274 | if (!error) | |
275 | aprint_error("%s: wedge named '%s' already " | 275 | aprint_error("%s: wedge named '%s' already " | |
276 | "existed, using '%s'\n", pdk->dk_name, | 276 | "existed, using '%s'\n", pdk->dk_name, | |
277 | orig, ent_guid_str); | 277 | orig, ent_guid_str); | |
278 | } | 278 | } | |
279 | if (error == EEXIST) | 279 | if (error == EEXIST) | |
280 | aprint_error("%s: wedge named '%s' already exists, " | 280 | aprint_error("%s: wedge named '%s' already exists, " | |
281 | "manual intervention required\n", pdk->dk_name, | 281 | "manual intervention required\n", pdk->dk_name, | |
282 | dkw.dkw_wname); | 282 | dkw.dkw_wname); | |
283 | else if (error) | 283 | else if (error) | |
284 | aprint_error("%s: error %d adding entry %u (%s), " | 284 | aprint_error("%s: error %d adding entry %u (%s), " | |
285 | "type %s\n", pdk->dk_name, error, i, ent_guid_str, | 285 | "type %s\n", pdk->dk_name, error, i, ent_guid_str, |
--- src/sys/dev/dkwedge/dkwedge_mbr.c 2015/12/02 01:09:49 1.9
+++ src/sys/dev/dkwedge/dkwedge_mbr.c 2017/01/19 00:44:40 1.10
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: dkwedge_mbr.c,v 1.9 2015/12/02 01:09:49 christos Exp $ */ | 1 | /* $NetBSD: dkwedge_mbr.c,v 1.10 2017/01/19 00:44:40 maya Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2004 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2004 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. | 8 | * by Jason R. Thorpe. | |
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 | * Master Boot Record partition table support for disk wedges | 33 | * Master Boot Record partition table support for disk wedges | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | __KERNEL_RCSID(0, "$NetBSD: dkwedge_mbr.c,v 1.9 2015/12/02 01:09:49 christos Exp $"); | 37 | __KERNEL_RCSID(0, "$NetBSD: dkwedge_mbr.c,v 1.10 2017/01/19 00:44:40 maya Exp $"); | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/systm.h> | 40 | #include <sys/systm.h> | |
41 | #include <sys/proc.h> | 41 | #include <sys/proc.h> | |
42 | #include <sys/errno.h> | 42 | #include <sys/errno.h> | |
43 | #include <sys/disk.h> | 43 | #include <sys/disk.h> | |
44 | #include <sys/vnode.h> | 44 | #include <sys/vnode.h> | |
45 | #include <sys/malloc.h> | 45 | #include <sys/malloc.h> | |
46 | 46 | |||
47 | #include <sys/bootblock.h> | 47 | #include <sys/bootblock.h> | |
48 | #include <sys/disklabel.h> | 48 | #include <sys/disklabel.h> | |
49 | 49 | |||
50 | typedef struct mbr_args { | 50 | typedef struct mbr_args { | |
@@ -114,29 +114,29 @@ getparts(mbr_args_t *a, uint32_t off, ui | @@ -114,29 +114,29 @@ getparts(mbr_args_t *a, uint32_t off, ui | |||
114 | break; | 114 | break; | |
115 | } | 115 | } | |
116 | 116 | |||
117 | if ((ptype = mbr_ptype_to_str(dp[i].mbrp_type)) == NULL) { | 117 | if ((ptype = mbr_ptype_to_str(dp[i].mbrp_type)) == NULL) { | |
118 | /* | 118 | /* | |
119 | * XXX Should probably just add these... | 119 | * XXX Should probably just add these... | |
120 | * XXX maybe just have an empty ptype? | 120 | * XXX maybe just have an empty ptype? | |
121 | */ | 121 | */ | |
122 | aprint_verbose("%s: skipping partition %d, " | 122 | aprint_verbose("%s: skipping partition %d, " | |
123 | "type 0x%02x\n", a->pdk->dk_name, i, | 123 | "type 0x%02x\n", a->pdk->dk_name, i, | |
124 | dp[i].mbrp_type); | 124 | dp[i].mbrp_type); | |
125 | continue; | 125 | continue; | |
126 | } | 126 | } | |
127 | strcpy(dkw.dkw_ptype, ptype); | 127 | strlcpy(dkw.dkw_ptype, ptype, sizeof(dkw.dkw_ptype)); | |
128 | 128 | |||
129 | strcpy(dkw.dkw_parent, a->pdk->dk_name); | 129 | strlcpy(dkw.dkw_parent, a->pdk->dk_name, sizeof(dkw.dkw_parent)); | |
130 | dkw.dkw_offset = le32toh(dp[i].mbrp_start); | 130 | dkw.dkw_offset = le32toh(dp[i].mbrp_start); | |
131 | dkw.dkw_size = le32toh(dp[i].mbrp_size); | 131 | dkw.dkw_size = le32toh(dp[i].mbrp_size); | |
132 | 132 | |||
133 | /* | 133 | /* | |
134 | * These get historical disk naming style | 134 | * These get historical disk naming style | |
135 | * wedge names. We start at 'e', and reserve | 135 | * wedge names. We start at 'e', and reserve | |
136 | * 4 slots for each MBR we parse. | 136 | * 4 slots for each MBR we parse. | |
137 | * | 137 | * | |
138 | * XXX For FAT, we should extract the FAT volume | 138 | * XXX For FAT, we should extract the FAT volume | |
139 | * XXX name. | 139 | * XXX name. | |
140 | */ | 140 | */ | |
141 | snprintf(dkw.dkw_wname, sizeof(dkw.dkw_wname), | 141 | snprintf(dkw.dkw_wname, sizeof(dkw.dkw_wname), | |
142 | "%s%c", a->pdk->dk_name, | 142 | "%s%c", a->pdk->dk_name, |