devicename.c (293724) | devicename.c (294060) |
---|---|
1/*- 2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 3 * Copyright (c) 2006 Marcel Moolenaar 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 3 * Copyright (c) 2006 Marcel Moolenaar 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/boot/efi/loader/devicename.c 293724 2016-01-12 02:17:39Z smh $"); | 29__FBSDID("$FreeBSD: head/sys/boot/efi/loader/devicename.c 294060 2016-01-15 01:22:36Z smh $"); |
30 31#include <stand.h> 32#include <string.h> 33#include <sys/disklabel.h> | 30 31#include <stand.h> 32#include <string.h> 33#include <sys/disklabel.h> |
34#include <sys/param.h> |
|
34#include <bootstrap.h> 35 36#include <efi.h> 37#include <efilib.h> 38 39#include "loader_efi.h" 40 41static int efi_parsedev(struct devdesc **, const char *, const char **); --- 39 unchanged lines hidden (view full) --- 81 */ 82static int 83efi_parsedev(struct devdesc **dev, const char *devspec, const char **path) 84{ 85 struct devdesc *idev; 86 struct devsw *dv; 87 char *cp; 88 const char *np; | 35#include <bootstrap.h> 36 37#include <efi.h> 38#include <efilib.h> 39 40#include "loader_efi.h" 41 42static int efi_parsedev(struct devdesc **, const char *, const char **); --- 39 unchanged lines hidden (view full) --- 82 */ 83static int 84efi_parsedev(struct devdesc **dev, const char *devspec, const char **path) 85{ 86 struct devdesc *idev; 87 struct devsw *dv; 88 char *cp; 89 const char *np; |
89 int i, err; | 90 int i; |
90 91 /* minimum length check */ 92 if (strlen(devspec) < 2) 93 return (EINVAL); 94 95 /* look for a device that matches */ 96 for (i = 0; devsw[i] != NULL; i++) { 97 dv = devsw[i]; 98 if (!strncmp(devspec, dv->dv_name, strlen(dv->dv_name))) 99 break; 100 } 101 if (devsw[i] == NULL) 102 return (ENOENT); 103 | 91 92 /* minimum length check */ 93 if (strlen(devspec) < 2) 94 return (EINVAL); 95 96 /* look for a device that matches */ 97 for (i = 0; devsw[i] != NULL; i++) { 98 dv = devsw[i]; 99 if (!strncmp(devspec, dv->dv_name, strlen(dv->dv_name))) 100 break; 101 } 102 if (devsw[i] == NULL) 103 return (ENOENT); 104 |
104 idev = malloc(sizeof(struct devdesc)); 105 if (idev == NULL) 106 return (ENOMEM); | 105 np = devspec + strlen(dv->dv_name); |
107 | 106 |
108 idev->d_dev = dv; 109 idev->d_type = dv->dv_type; 110 idev->d_unit = -1; | 107 { 108 idev = malloc(sizeof(struct devdesc)); 109 if (idev == NULL) 110 return (ENOMEM); |
111 | 111 |
112 err = 0; 113 np = devspec + strlen(dv->dv_name); 114 if (*np != '\0' && *np != ':') { 115 idev->d_unit = strtol(np, &cp, 0); 116 if (cp == np) { 117 idev->d_unit = -1; 118 free(idev); 119 return (EUNIT); | 112 idev->d_dev = dv; 113 idev->d_type = dv->dv_type; 114 idev->d_unit = -1; 115 if (*np != '\0' && *np != ':') { 116 idev->d_unit = strtol(np, &cp, 0); 117 if (cp == np) { 118 idev->d_unit = -1; 119 free(idev); 120 return (EUNIT); 121 } |
120 } 121 } | 122 } 123 } |
124 |
|
122 if (*cp != '\0' && *cp != ':') { 123 free(idev); 124 return (EINVAL); 125 } 126 127 if (path != NULL) 128 *path = (*cp == 0) ? cp : cp + 1; 129 if (dev != NULL) 130 *dev = idev; 131 else 132 free(idev); 133 return (0); 134} 135 136char * 137efi_fmtdev(void *vdev) 138{ 139 struct devdesc *dev = (struct devdesc *)vdev; | 125 if (*cp != '\0' && *cp != ':') { 126 free(idev); 127 return (EINVAL); 128 } 129 130 if (path != NULL) 131 *path = (*cp == 0) ? cp : cp + 1; 132 if (dev != NULL) 133 *dev = idev; 134 else 135 free(idev); 136 return (0); 137} 138 139char * 140efi_fmtdev(void *vdev) 141{ 142 struct devdesc *dev = (struct devdesc *)vdev; |
140 static char buf[32]; /* XXX device length constant? */ | 143 static char buf[SPECNAMELEN + 1]; |
141 142 switch(dev->d_type) { 143 case DEVT_NONE: 144 strcpy(buf, "(no device)"); 145 break; 146 147 default: 148 sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit); --- 23 unchanged lines hidden --- | 144 145 switch(dev->d_type) { 146 case DEVT_NONE: 147 strcpy(buf, "(no device)"); 148 break; 149 150 default: 151 sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit); --- 23 unchanged lines hidden --- |