Deleted Added
full compact
openfirmio.c (186347) openfirmio.c (194138)
1/* $NetBSD: openfirmio.c,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */
2
3#include <sys/cdefs.h>
1/* $NetBSD: openfirmio.c,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */
2
3#include <sys/cdefs.h>
4__FBSDID("$FreeBSD: head/sys/dev/ofw/openfirmio.c 186347 2008-12-20 00:33:10Z nwhitehorn $");
4__FBSDID("$FreeBSD: head/sys/dev/ofw/openfirmio.c 194138 2009-06-14 00:05:38Z marius $");
5
6/*-
7 * Copyright (c) 1992, 1993
8 * The Regents of the University of California. All rights reserved.
9 *
10 * This software was developed by the Computer Systems Engineering group
11 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
12 * contributed to Berkeley.

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

90}
91
92static int
93openfirm_getstr(int len, const char *user, char **cpp)
94{
95 int error;
96 char *cp;
97
5
6/*-
7 * Copyright (c) 1992, 1993
8 * The Regents of the University of California. All rights reserved.
9 *
10 * This software was developed by the Computer Systems Engineering group
11 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
12 * contributed to Berkeley.

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

90}
91
92static int
93openfirm_getstr(int len, const char *user, char **cpp)
94{
95 int error;
96 char *cp;
97
98 /* Reject obvious bogus requests */
98 /* Reject obvious bogus requests. */
99 if ((u_int)len > OFIOCMAXNAME)
100 return (ENAMETOOLONG);
101
102 *cpp = cp = malloc(len + 1, M_TEMP, M_WAITOK);
103 if (cp == NULL)
104 return (ENOMEM);
105 error = copyin(user, cp, len);
106 cp[len] = '\0';

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

136 case OFIOCGETCHILD:
137 node = *(phandle_t *)data;
138 break;
139 default:
140 return (ENOIOCTL);
141 }
142
143 if (node != 0 && node != lastnode) {
99 if ((u_int)len > OFIOCMAXNAME)
100 return (ENAMETOOLONG);
101
102 *cpp = cp = malloc(len + 1, M_TEMP, M_WAITOK);
103 if (cp == NULL)
104 return (ENOMEM);
105 error = copyin(user, cp, len);
106 cp[len] = '\0';

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

136 case OFIOCGETCHILD:
137 node = *(phandle_t *)data;
138 break;
139 default:
140 return (ENOIOCTL);
141 }
142
143 if (node != 0 && node != lastnode) {
144 /* Not an easy one, must search for it */
144 /* Not an easy one, we must search for it. */
145 ok = openfirm_checkid(OF_peer(0), node);
146 if (!ok)
147 return (EINVAL);
148 lastnode = node;
149 }
150
151 name = value = NULL;
152 error = 0;

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

164 of->of_buflen = len;
165 break;
166 }
167 if (len > of->of_buflen) {
168 error = ENOMEM;
169 break;
170 }
171 of->of_buflen = len;
145 ok = openfirm_checkid(OF_peer(0), node);
146 if (!ok)
147 return (EINVAL);
148 lastnode = node;
149 }
150
151 name = value = NULL;
152 error = 0;

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

164 of->of_buflen = len;
165 break;
166 }
167 if (len > of->of_buflen) {
168 error = ENOMEM;
169 break;
170 }
171 of->of_buflen = len;
172 /* -1 means no entry; 0 means no value */
172 /* -1 means no entry; 0 means no value. */
173 if (len <= 0)
174 break;
175 value = malloc(len, M_TEMP, M_WAITOK);
176 if (value == NULL) {
177 error = ENOMEM;
178 break;
179 }
180 len = OF_getprop(node, name, (void *)value, len);
181 error = copyout(value, of->of_buf, len);
182 break;
183
184 case OFIOCSET:
185 /*
186 * Note: Text string values for at least the /options node
187 * have to be null-terminated and the length parameter must
173 if (len <= 0)
174 break;
175 value = malloc(len, M_TEMP, M_WAITOK);
176 if (value == NULL) {
177 error = ENOMEM;
178 break;
179 }
180 len = OF_getprop(node, name, (void *)value, len);
181 error = copyout(value, of->of_buf, len);
182 break;
183
184 case OFIOCSET:
185 /*
186 * Note: Text string values for at least the /options node
187 * have to be null-terminated and the length parameter must
188 * include this terminating null. However, like OF_getprop(),
188 * include this terminating null. However, like OF_getprop(),
189 * OF_setprop() will return the actual length of the text
190 * string, i.e. omitting the terminating null.
191 */
192 if ((flags & FWRITE) == 0)
193 return (EBADF);
194 if (node == 0)
195 return (EINVAL);
196 if ((u_int)of->of_buflen > OFIOCMAXVALUE)

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

269 free(value, M_TEMP);
270
271 return (error);
272}
273
274static int
275openfirm_modevent(module_t mod, int type, void *data)
276{
189 * OF_setprop() will return the actual length of the text
190 * string, i.e. omitting the terminating null.
191 */
192 if ((flags & FWRITE) == 0)
193 return (EBADF);
194 if (node == 0)
195 return (EINVAL);
196 if ((u_int)of->of_buflen > OFIOCMAXVALUE)

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

269 free(value, M_TEMP);
270
271 return (error);
272}
273
274static int
275openfirm_modevent(module_t mod, int type, void *data)
276{
277
277 switch(type) {
278 case MOD_LOAD:
279 if (bootverbose)
280 printf("openfirm: <Open Firmware control device>\n");
281 /*
282 * Allow only root access by default; this device may allow
283 * users to peek into firmware passwords, and likely to crash
284 * the machine on some boxen due to firmware quirks.

--- 18 unchanged lines hidden ---
278 switch(type) {
279 case MOD_LOAD:
280 if (bootverbose)
281 printf("openfirm: <Open Firmware control device>\n");
282 /*
283 * Allow only root access by default; this device may allow
284 * users to peek into firmware passwords, and likely to crash
285 * the machine on some boxen due to firmware quirks.

--- 18 unchanged lines hidden ---