Deleted Added
full compact
devicename.c (206376) devicename.c (264095)
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/i386/efi/devicename.c 206376 2010-04-07 18:16:05Z rpaulo $");
29__FBSDID("$FreeBSD: head/sys/boot/amd64/efi/devicename.c 264095 2014-04-04 00:16:46Z emaste $");
30
31#include <stand.h>
32#include <string.h>
33#include <sys/disklabel.h>
34#include "bootstrap.h"
35
36#include <efi.h>
37#include <efilib.h>
38
30
31#include <stand.h>
32#include <string.h>
33#include <sys/disklabel.h>
34#include "bootstrap.h"
35
36#include <efi.h>
37#include <efilib.h>
38
39static int i386_parsedev(struct devdesc **, const char *, const char **);
39static int x86_efi_parsedev(struct devdesc **, const char *, const char **);
40
41/*
42 * Point (dev) at an allocated device specifier for the device matching the
43 * path in (devspec). If it contains an explicit device specification,
44 * use that. If not, use the default device.
45 */
46int
40
41/*
42 * Point (dev) at an allocated device specifier for the device matching the
43 * path in (devspec). If it contains an explicit device specification,
44 * use that. If not, use the default device.
45 */
46int
47i386_getdev(void **vdev, const char *devspec, const char **path)
47x86_efi_getdev(void **vdev, const char *devspec, const char **path)
48{
49 struct devdesc **dev = (struct devdesc **)vdev;
50 int rv;
51
52 /*
53 * If it looks like this is just a path and no device, then
54 * use the current device instead.
55 */
56 if (devspec == NULL || *devspec == '/' || !strchr(devspec, ':')) {
48{
49 struct devdesc **dev = (struct devdesc **)vdev;
50 int rv;
51
52 /*
53 * If it looks like this is just a path and no device, then
54 * use the current device instead.
55 */
56 if (devspec == NULL || *devspec == '/' || !strchr(devspec, ':')) {
57 rv = i386_parsedev(dev, getenv("currdev"), NULL);
57 rv = x86_efi_parsedev(dev, getenv("currdev"), NULL);
58 if (rv == 0 && path != NULL)
59 *path = devspec;
60 return (rv);
61 }
62
63 /* Parse the device name off the beginning of the devspec. */
58 if (rv == 0 && path != NULL)
59 *path = devspec;
60 return (rv);
61 }
62
63 /* Parse the device name off the beginning of the devspec. */
64 return (i386_parsedev(dev, devspec, path));
64 return (x86_efi_parsedev(dev, devspec, path));
65}
66
67/*
68 * Point (dev) at an allocated device specifier matching the string version
69 * at the beginning of (devspec). Return a pointer to the remaining
70 * text in (path).
71 *
72 * In all cases, the beginning of (devspec) is compared to the names
73 * of known devices in the device switch, and then any following text
74 * is parsed according to the rules applied to the device type.
75 *
76 * For disk-type devices, the syntax is:
77 *
78 * fs<unit>:
79 */
80static int
65}
66
67/*
68 * Point (dev) at an allocated device specifier matching the string version
69 * at the beginning of (devspec). Return a pointer to the remaining
70 * text in (path).
71 *
72 * In all cases, the beginning of (devspec) is compared to the names
73 * of known devices in the device switch, and then any following text
74 * is parsed according to the rules applied to the device type.
75 *
76 * For disk-type devices, the syntax is:
77 *
78 * fs<unit>:
79 */
80static int
81i386_parsedev(struct devdesc **dev, const char *devspec, const char **path)
81x86_efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
82{
83 struct devdesc *idev;
84 struct devsw *dv;
85 char *cp;
86 const char *np;
87 int i, err;
88
89 /* minimum length check */

--- 37 unchanged lines hidden (view full) ---

127 if (dev != NULL)
128 *dev = idev;
129 else
130 free(idev);
131 return (0);
132}
133
134char *
82{
83 struct devdesc *idev;
84 struct devsw *dv;
85 char *cp;
86 const char *np;
87 int i, err;
88
89 /* minimum length check */

--- 37 unchanged lines hidden (view full) ---

127 if (dev != NULL)
128 *dev = idev;
129 else
130 free(idev);
131 return (0);
132}
133
134char *
135i386_fmtdev(void *vdev)
135x86_efi_fmtdev(void *vdev)
136{
137 struct devdesc *dev = (struct devdesc *)vdev;
138 static char buf[32]; /* XXX device length constant? */
139
140 switch(dev->d_type) {
141 case DEVT_NONE:
142 strcpy(buf, "(no device)");
143 break;

--- 5 unchanged lines hidden (view full) ---

149
150 return(buf);
151}
152
153/*
154 * Set currdev to suit the value being supplied in (value)
155 */
156int
136{
137 struct devdesc *dev = (struct devdesc *)vdev;
138 static char buf[32]; /* XXX device length constant? */
139
140 switch(dev->d_type) {
141 case DEVT_NONE:
142 strcpy(buf, "(no device)");
143 break;

--- 5 unchanged lines hidden (view full) ---

149
150 return(buf);
151}
152
153/*
154 * Set currdev to suit the value being supplied in (value)
155 */
156int
157i386_setcurrdev(struct env_var *ev, int flags, const void *value)
157x86_efi_setcurrdev(struct env_var *ev, int flags, const void *value)
158{
159 struct devdesc *ncurr;
160 int rv;
161
158{
159 struct devdesc *ncurr;
160 int rv;
161
162 rv = i386_parsedev(&ncurr, value, NULL);
162 rv = x86_efi_parsedev(&ncurr, value, NULL);
163 if (rv != 0)
164 return(rv);
165
166 free(ncurr);
167 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
168 return (0);
169}
163 if (rv != 0)
164 return(rv);
165
166 free(ncurr);
167 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
168 return (0);
169}