1*27b03b36SApple OSS Distributions /*
2*27b03b36SApple OSS Distributions * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
3*27b03b36SApple OSS Distributions *
4*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*27b03b36SApple OSS Distributions *
6*27b03b36SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*27b03b36SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*27b03b36SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*27b03b36SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*27b03b36SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*27b03b36SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*27b03b36SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*27b03b36SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*27b03b36SApple OSS Distributions *
15*27b03b36SApple OSS Distributions * Please obtain a copy of the License at
16*27b03b36SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*27b03b36SApple OSS Distributions *
18*27b03b36SApple OSS Distributions * The Original Code and all software distributed under the License are
19*27b03b36SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*27b03b36SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*27b03b36SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*27b03b36SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*27b03b36SApple OSS Distributions * Please see the License for the specific language governing rights and
24*27b03b36SApple OSS Distributions * limitations under the License.
25*27b03b36SApple OSS Distributions *
26*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*27b03b36SApple OSS Distributions */
28*27b03b36SApple OSS Distributions #include <pexpert/pexpert.h>
29*27b03b36SApple OSS Distributions #include <pexpert/device_tree.h>
30*27b03b36SApple OSS Distributions
31*27b03b36SApple OSS Distributions typedef boolean_t (*argsep_func_t) (char c);
32*27b03b36SApple OSS Distributions
33*27b03b36SApple OSS Distributions static boolean_t isargsep( char c);
34*27b03b36SApple OSS Distributions static boolean_t israngesep( char c);
35*27b03b36SApple OSS Distributions #if defined(__x86_64__)
36*27b03b36SApple OSS Distributions static int argstrcpy(char *from, char *to);
37*27b03b36SApple OSS Distributions #endif
38*27b03b36SApple OSS Distributions static int argstrcpy2(char *from, char *to, unsigned maxlen);
39*27b03b36SApple OSS Distributions static int argnumcpy(long long val, void *to, unsigned maxlen);
40*27b03b36SApple OSS Distributions static int getval(char *s, long long *val, argsep_func_t issep, boolean_t skip_equal_sign);
41*27b03b36SApple OSS Distributions boolean_t get_range_bounds(char * c, int64_t * lower, int64_t * upper);
42*27b03b36SApple OSS Distributions
43*27b03b36SApple OSS Distributions extern int IODTGetDefault(const char *key, void *infoAddr, unsigned int infoSize);
44*27b03b36SApple OSS Distributions
45*27b03b36SApple OSS Distributions
46*27b03b36SApple OSS Distributions struct i24 {
47*27b03b36SApple OSS Distributions int32_t i24 : 24;
48*27b03b36SApple OSS Distributions int32_t _pad : 8;
49*27b03b36SApple OSS Distributions };
50*27b03b36SApple OSS Distributions
51*27b03b36SApple OSS Distributions #define NUM 0
52*27b03b36SApple OSS Distributions #define STR 1
53*27b03b36SApple OSS Distributions
54*27b03b36SApple OSS Distributions static boolean_t
PE_parse_boot_argn_internal(const char * arg_string,void * arg_ptr,int max_len,boolean_t force_string)55*27b03b36SApple OSS Distributions PE_parse_boot_argn_internal(
56*27b03b36SApple OSS Distributions const char *arg_string,
57*27b03b36SApple OSS Distributions void * arg_ptr,
58*27b03b36SApple OSS Distributions int max_len,
59*27b03b36SApple OSS Distributions boolean_t force_string)
60*27b03b36SApple OSS Distributions {
61*27b03b36SApple OSS Distributions char *args;
62*27b03b36SApple OSS Distributions char *cp, c;
63*27b03b36SApple OSS Distributions uintptr_t i;
64*27b03b36SApple OSS Distributions long long val = 0;
65*27b03b36SApple OSS Distributions boolean_t arg_boolean;
66*27b03b36SApple OSS Distributions boolean_t arg_found;
67*27b03b36SApple OSS Distributions
68*27b03b36SApple OSS Distributions args = PE_boot_args();
69*27b03b36SApple OSS Distributions if (*args == '\0') {
70*27b03b36SApple OSS Distributions return FALSE;
71*27b03b36SApple OSS Distributions }
72*27b03b36SApple OSS Distributions
73*27b03b36SApple OSS Distributions #if !defined(__x86_64__)
74*27b03b36SApple OSS Distributions if (max_len == -1) {
75*27b03b36SApple OSS Distributions return FALSE;
76*27b03b36SApple OSS Distributions }
77*27b03b36SApple OSS Distributions #endif
78*27b03b36SApple OSS Distributions
79*27b03b36SApple OSS Distributions arg_found = FALSE;
80*27b03b36SApple OSS Distributions
81*27b03b36SApple OSS Distributions while (*args && isargsep(*args)) {
82*27b03b36SApple OSS Distributions args++;
83*27b03b36SApple OSS Distributions }
84*27b03b36SApple OSS Distributions
85*27b03b36SApple OSS Distributions while (*args) {
86*27b03b36SApple OSS Distributions if (*args == '-') {
87*27b03b36SApple OSS Distributions arg_boolean = TRUE;
88*27b03b36SApple OSS Distributions } else {
89*27b03b36SApple OSS Distributions arg_boolean = FALSE;
90*27b03b36SApple OSS Distributions }
91*27b03b36SApple OSS Distributions
92*27b03b36SApple OSS Distributions cp = args;
93*27b03b36SApple OSS Distributions while (!isargsep(*cp) && *cp != '=') {
94*27b03b36SApple OSS Distributions cp++;
95*27b03b36SApple OSS Distributions }
96*27b03b36SApple OSS Distributions if (*cp != '=' && !arg_boolean) {
97*27b03b36SApple OSS Distributions goto gotit;
98*27b03b36SApple OSS Distributions }
99*27b03b36SApple OSS Distributions
100*27b03b36SApple OSS Distributions c = *cp;
101*27b03b36SApple OSS Distributions
102*27b03b36SApple OSS Distributions i = cp - args;
103*27b03b36SApple OSS Distributions if (strncmp(args, arg_string, i) ||
104*27b03b36SApple OSS Distributions (i != strlen(arg_string))) {
105*27b03b36SApple OSS Distributions goto gotit;
106*27b03b36SApple OSS Distributions }
107*27b03b36SApple OSS Distributions
108*27b03b36SApple OSS Distributions if (arg_boolean) {
109*27b03b36SApple OSS Distributions if (!force_string) {
110*27b03b36SApple OSS Distributions if (max_len > 0) {
111*27b03b36SApple OSS Distributions argnumcpy(1, arg_ptr, max_len);/* max_len of 0 performs no copy at all*/
112*27b03b36SApple OSS Distributions arg_found = TRUE;
113*27b03b36SApple OSS Distributions } else if (max_len == 0) {
114*27b03b36SApple OSS Distributions arg_found = TRUE;
115*27b03b36SApple OSS Distributions }
116*27b03b36SApple OSS Distributions }
117*27b03b36SApple OSS Distributions break;
118*27b03b36SApple OSS Distributions } else {
119*27b03b36SApple OSS Distributions while (*cp && isargsep(*cp)) {
120*27b03b36SApple OSS Distributions cp++;
121*27b03b36SApple OSS Distributions }
122*27b03b36SApple OSS Distributions if (*cp == '=' && c != '=') {
123*27b03b36SApple OSS Distributions args = cp + 1;
124*27b03b36SApple OSS Distributions goto gotit;
125*27b03b36SApple OSS Distributions }
126*27b03b36SApple OSS Distributions if ('_' == *arg_string) { /* Force a string copy if the argument name begins with an underscore */
127*27b03b36SApple OSS Distributions if (max_len > 0) {
128*27b03b36SApple OSS Distributions int hacklen = 17 > max_len ? 17 : max_len;
129*27b03b36SApple OSS Distributions argstrcpy2(++cp, (char *)arg_ptr, hacklen - 1); /* Hack - terminate after 16 characters */
130*27b03b36SApple OSS Distributions arg_found = TRUE;
131*27b03b36SApple OSS Distributions } else if (max_len == 0) {
132*27b03b36SApple OSS Distributions arg_found = TRUE;
133*27b03b36SApple OSS Distributions }
134*27b03b36SApple OSS Distributions break;
135*27b03b36SApple OSS Distributions }
136*27b03b36SApple OSS Distributions switch ((force_string && *cp == '=') ? STR : getval(cp, &val, isargsep, FALSE)) {
137*27b03b36SApple OSS Distributions case NUM:
138*27b03b36SApple OSS Distributions if (max_len > 0) {
139*27b03b36SApple OSS Distributions argnumcpy(val, arg_ptr, max_len);
140*27b03b36SApple OSS Distributions arg_found = TRUE;
141*27b03b36SApple OSS Distributions } else if (max_len == 0) {
142*27b03b36SApple OSS Distributions arg_found = TRUE;
143*27b03b36SApple OSS Distributions }
144*27b03b36SApple OSS Distributions break;
145*27b03b36SApple OSS Distributions case STR:
146*27b03b36SApple OSS Distributions if (max_len > 0) {
147*27b03b36SApple OSS Distributions argstrcpy2(++cp, (char *)arg_ptr, max_len - 1); /*max_len of 0 performs no copy at all*/
148*27b03b36SApple OSS Distributions arg_found = TRUE;
149*27b03b36SApple OSS Distributions } else if (max_len == 0) {
150*27b03b36SApple OSS Distributions arg_found = TRUE;
151*27b03b36SApple OSS Distributions }
152*27b03b36SApple OSS Distributions #if defined(__x86_64__)
153*27b03b36SApple OSS Distributions else if (max_len == -1) { /* unreachable on embedded */
154*27b03b36SApple OSS Distributions argstrcpy(++cp, (char *)arg_ptr);
155*27b03b36SApple OSS Distributions arg_found = TRUE;
156*27b03b36SApple OSS Distributions }
157*27b03b36SApple OSS Distributions #endif
158*27b03b36SApple OSS Distributions break;
159*27b03b36SApple OSS Distributions }
160*27b03b36SApple OSS Distributions goto gotit;
161*27b03b36SApple OSS Distributions }
162*27b03b36SApple OSS Distributions gotit:
163*27b03b36SApple OSS Distributions /* Skip over current arg */
164*27b03b36SApple OSS Distributions while (!isargsep(*args)) {
165*27b03b36SApple OSS Distributions args++;
166*27b03b36SApple OSS Distributions }
167*27b03b36SApple OSS Distributions
168*27b03b36SApple OSS Distributions /* Skip leading white space (catch end of args) */
169*27b03b36SApple OSS Distributions while (*args && isargsep(*args)) {
170*27b03b36SApple OSS Distributions args++;
171*27b03b36SApple OSS Distributions }
172*27b03b36SApple OSS Distributions }
173*27b03b36SApple OSS Distributions
174*27b03b36SApple OSS Distributions return arg_found;
175*27b03b36SApple OSS Distributions }
176*27b03b36SApple OSS Distributions
177*27b03b36SApple OSS Distributions boolean_t
PE_parse_boot_argn(const char * arg_string,void * arg_ptr,int max_len)178*27b03b36SApple OSS Distributions PE_parse_boot_argn(
179*27b03b36SApple OSS Distributions const char *arg_string,
180*27b03b36SApple OSS Distributions void *arg_ptr,
181*27b03b36SApple OSS Distributions int max_len)
182*27b03b36SApple OSS Distributions {
183*27b03b36SApple OSS Distributions return PE_parse_boot_argn_internal(arg_string, arg_ptr, max_len, FALSE);
184*27b03b36SApple OSS Distributions }
185*27b03b36SApple OSS Distributions
186*27b03b36SApple OSS Distributions boolean_t
PE_parse_boot_arg_str(const char * arg_string,char * arg_ptr,int strlen)187*27b03b36SApple OSS Distributions PE_parse_boot_arg_str(
188*27b03b36SApple OSS Distributions const char *arg_string,
189*27b03b36SApple OSS Distributions char *arg_ptr,
190*27b03b36SApple OSS Distributions int strlen)
191*27b03b36SApple OSS Distributions {
192*27b03b36SApple OSS Distributions return PE_parse_boot_argn_internal(arg_string, arg_ptr, strlen, TRUE);
193*27b03b36SApple OSS Distributions }
194*27b03b36SApple OSS Distributions
195*27b03b36SApple OSS Distributions static boolean_t
isargsep(char c)196*27b03b36SApple OSS Distributions isargsep(char c)
197*27b03b36SApple OSS Distributions {
198*27b03b36SApple OSS Distributions if (c == ' ' || c == '\0' || c == '\t') {
199*27b03b36SApple OSS Distributions return TRUE;
200*27b03b36SApple OSS Distributions } else {
201*27b03b36SApple OSS Distributions return FALSE;
202*27b03b36SApple OSS Distributions }
203*27b03b36SApple OSS Distributions }
204*27b03b36SApple OSS Distributions
205*27b03b36SApple OSS Distributions static boolean_t
israngesep(char c)206*27b03b36SApple OSS Distributions israngesep(char c)
207*27b03b36SApple OSS Distributions {
208*27b03b36SApple OSS Distributions if (isargsep(c) || c == '_' || c == ',') {
209*27b03b36SApple OSS Distributions return TRUE;
210*27b03b36SApple OSS Distributions } else {
211*27b03b36SApple OSS Distributions return FALSE;
212*27b03b36SApple OSS Distributions }
213*27b03b36SApple OSS Distributions }
214*27b03b36SApple OSS Distributions
215*27b03b36SApple OSS Distributions #if defined(__x86_64__)
216*27b03b36SApple OSS Distributions static int
argstrcpy(char * from,char * to)217*27b03b36SApple OSS Distributions argstrcpy(
218*27b03b36SApple OSS Distributions char *from,
219*27b03b36SApple OSS Distributions char *to)
220*27b03b36SApple OSS Distributions {
221*27b03b36SApple OSS Distributions int i = 0;
222*27b03b36SApple OSS Distributions
223*27b03b36SApple OSS Distributions while (!isargsep(*from)) {
224*27b03b36SApple OSS Distributions i++;
225*27b03b36SApple OSS Distributions *to++ = *from++;
226*27b03b36SApple OSS Distributions }
227*27b03b36SApple OSS Distributions *to = 0;
228*27b03b36SApple OSS Distributions return i;
229*27b03b36SApple OSS Distributions }
230*27b03b36SApple OSS Distributions #endif
231*27b03b36SApple OSS Distributions
232*27b03b36SApple OSS Distributions static int
argstrcpy2(char * from,char * to,unsigned maxlen)233*27b03b36SApple OSS Distributions argstrcpy2(
234*27b03b36SApple OSS Distributions char *from,
235*27b03b36SApple OSS Distributions char *to,
236*27b03b36SApple OSS Distributions unsigned maxlen)
237*27b03b36SApple OSS Distributions {
238*27b03b36SApple OSS Distributions unsigned int i = 0;
239*27b03b36SApple OSS Distributions
240*27b03b36SApple OSS Distributions while (!isargsep(*from) && i < maxlen) {
241*27b03b36SApple OSS Distributions i++;
242*27b03b36SApple OSS Distributions *to++ = *from++;
243*27b03b36SApple OSS Distributions }
244*27b03b36SApple OSS Distributions *to = 0;
245*27b03b36SApple OSS Distributions return i;
246*27b03b36SApple OSS Distributions }
247*27b03b36SApple OSS Distributions
248*27b03b36SApple OSS Distributions static int
argnumcpy(long long val,void * to,unsigned maxlen)249*27b03b36SApple OSS Distributions argnumcpy(long long val, void *to, unsigned maxlen)
250*27b03b36SApple OSS Distributions {
251*27b03b36SApple OSS Distributions switch (maxlen) {
252*27b03b36SApple OSS Distributions case 0:
253*27b03b36SApple OSS Distributions /* No write-back, caller just wants to know if arg was found */
254*27b03b36SApple OSS Distributions break;
255*27b03b36SApple OSS Distributions case 1:
256*27b03b36SApple OSS Distributions *(int8_t *)to = (int8_t)val;
257*27b03b36SApple OSS Distributions break;
258*27b03b36SApple OSS Distributions case 2:
259*27b03b36SApple OSS Distributions *(int16_t *)to = (int16_t)val;
260*27b03b36SApple OSS Distributions break;
261*27b03b36SApple OSS Distributions case 3:
262*27b03b36SApple OSS Distributions /* Unlikely in practice */
263*27b03b36SApple OSS Distributions ((struct i24 *)to)->i24 = (int32_t)val;
264*27b03b36SApple OSS Distributions break;
265*27b03b36SApple OSS Distributions case 4:
266*27b03b36SApple OSS Distributions *(int32_t *)to = (int32_t)val;
267*27b03b36SApple OSS Distributions break;
268*27b03b36SApple OSS Distributions case 8:
269*27b03b36SApple OSS Distributions *(int64_t *)to = (int64_t)val;
270*27b03b36SApple OSS Distributions break;
271*27b03b36SApple OSS Distributions default:
272*27b03b36SApple OSS Distributions *(int32_t *)to = (int32_t)val;
273*27b03b36SApple OSS Distributions maxlen = 4;
274*27b03b36SApple OSS Distributions break;
275*27b03b36SApple OSS Distributions }
276*27b03b36SApple OSS Distributions
277*27b03b36SApple OSS Distributions return (int)maxlen;
278*27b03b36SApple OSS Distributions }
279*27b03b36SApple OSS Distributions
280*27b03b36SApple OSS Distributions static int
getval(char * s,long long * val,argsep_func_t issep,boolean_t skip_equal_sign)281*27b03b36SApple OSS Distributions getval(
282*27b03b36SApple OSS Distributions char *s,
283*27b03b36SApple OSS Distributions long long *val,
284*27b03b36SApple OSS Distributions argsep_func_t issep,
285*27b03b36SApple OSS Distributions boolean_t skip_equal_sign )
286*27b03b36SApple OSS Distributions {
287*27b03b36SApple OSS Distributions unsigned long long radix, intval;
288*27b03b36SApple OSS Distributions unsigned char c;
289*27b03b36SApple OSS Distributions int sign = 1;
290*27b03b36SApple OSS Distributions boolean_t has_value = FALSE;
291*27b03b36SApple OSS Distributions
292*27b03b36SApple OSS Distributions if (*s == '=') {
293*27b03b36SApple OSS Distributions s++;
294*27b03b36SApple OSS Distributions has_value = TRUE;
295*27b03b36SApple OSS Distributions }
296*27b03b36SApple OSS Distributions
297*27b03b36SApple OSS Distributions if (has_value || skip_equal_sign) {
298*27b03b36SApple OSS Distributions if (*s == '-') {
299*27b03b36SApple OSS Distributions sign = -1;
300*27b03b36SApple OSS Distributions s++;
301*27b03b36SApple OSS Distributions }
302*27b03b36SApple OSS Distributions intval = *s++ - '0';
303*27b03b36SApple OSS Distributions radix = 10;
304*27b03b36SApple OSS Distributions if (intval == 0) {
305*27b03b36SApple OSS Distributions switch (*s) {
306*27b03b36SApple OSS Distributions case 'x':
307*27b03b36SApple OSS Distributions radix = 16;
308*27b03b36SApple OSS Distributions s++;
309*27b03b36SApple OSS Distributions break;
310*27b03b36SApple OSS Distributions
311*27b03b36SApple OSS Distributions case 'b':
312*27b03b36SApple OSS Distributions radix = 2;
313*27b03b36SApple OSS Distributions s++;
314*27b03b36SApple OSS Distributions break;
315*27b03b36SApple OSS Distributions
316*27b03b36SApple OSS Distributions case '0': case '1': case '2': case '3':
317*27b03b36SApple OSS Distributions case '4': case '5': case '6': case '7':
318*27b03b36SApple OSS Distributions intval = *s - '0';
319*27b03b36SApple OSS Distributions s++;
320*27b03b36SApple OSS Distributions radix = 8;
321*27b03b36SApple OSS Distributions break;
322*27b03b36SApple OSS Distributions
323*27b03b36SApple OSS Distributions default:
324*27b03b36SApple OSS Distributions if (!issep(*s)) {
325*27b03b36SApple OSS Distributions return STR;
326*27b03b36SApple OSS Distributions }
327*27b03b36SApple OSS Distributions }
328*27b03b36SApple OSS Distributions } else if (intval >= radix) {
329*27b03b36SApple OSS Distributions return STR;
330*27b03b36SApple OSS Distributions }
331*27b03b36SApple OSS Distributions for (;;) {
332*27b03b36SApple OSS Distributions c = *s++;
333*27b03b36SApple OSS Distributions if (issep(c)) {
334*27b03b36SApple OSS Distributions break;
335*27b03b36SApple OSS Distributions }
336*27b03b36SApple OSS Distributions if ((radix <= 10) &&
337*27b03b36SApple OSS Distributions ((c >= '0') && (c <= ('9' - (10 - radix))))) {
338*27b03b36SApple OSS Distributions c -= '0';
339*27b03b36SApple OSS Distributions } else if ((radix == 16) &&
340*27b03b36SApple OSS Distributions ((c >= '0') && (c <= '9'))) {
341*27b03b36SApple OSS Distributions c -= '0';
342*27b03b36SApple OSS Distributions } else if ((radix == 16) &&
343*27b03b36SApple OSS Distributions ((c >= 'a') && (c <= 'f'))) {
344*27b03b36SApple OSS Distributions c -= 'a' - 10;
345*27b03b36SApple OSS Distributions } else if ((radix == 16) &&
346*27b03b36SApple OSS Distributions ((c >= 'A') && (c <= 'F'))) {
347*27b03b36SApple OSS Distributions c -= 'A' - 10;
348*27b03b36SApple OSS Distributions } else if (c == 'k' || c == 'K') {
349*27b03b36SApple OSS Distributions sign *= 1024;
350*27b03b36SApple OSS Distributions break;
351*27b03b36SApple OSS Distributions } else if (c == 'm' || c == 'M') {
352*27b03b36SApple OSS Distributions sign *= 1024 * 1024;
353*27b03b36SApple OSS Distributions break;
354*27b03b36SApple OSS Distributions } else if (c == 'g' || c == 'G') {
355*27b03b36SApple OSS Distributions sign *= 1024 * 1024 * 1024;
356*27b03b36SApple OSS Distributions break;
357*27b03b36SApple OSS Distributions } else {
358*27b03b36SApple OSS Distributions return STR;
359*27b03b36SApple OSS Distributions }
360*27b03b36SApple OSS Distributions if (c >= radix) {
361*27b03b36SApple OSS Distributions return STR;
362*27b03b36SApple OSS Distributions }
363*27b03b36SApple OSS Distributions intval *= radix;
364*27b03b36SApple OSS Distributions intval += c;
365*27b03b36SApple OSS Distributions }
366*27b03b36SApple OSS Distributions if (!issep(c) && !issep(*s)) {
367*27b03b36SApple OSS Distributions return STR;
368*27b03b36SApple OSS Distributions }
369*27b03b36SApple OSS Distributions *val = intval * sign;
370*27b03b36SApple OSS Distributions return NUM;
371*27b03b36SApple OSS Distributions }
372*27b03b36SApple OSS Distributions *val = 1;
373*27b03b36SApple OSS Distributions return NUM;
374*27b03b36SApple OSS Distributions }
375*27b03b36SApple OSS Distributions
376*27b03b36SApple OSS Distributions boolean_t
PE_imgsrc_mount_supported()377*27b03b36SApple OSS Distributions PE_imgsrc_mount_supported()
378*27b03b36SApple OSS Distributions {
379*27b03b36SApple OSS Distributions return TRUE;
380*27b03b36SApple OSS Distributions }
381*27b03b36SApple OSS Distributions
382*27b03b36SApple OSS Distributions boolean_t
PE_get_default(const char * property_name,void * property_ptr,unsigned int max_property)383*27b03b36SApple OSS Distributions PE_get_default(
384*27b03b36SApple OSS Distributions const char *property_name,
385*27b03b36SApple OSS Distributions void *property_ptr,
386*27b03b36SApple OSS Distributions unsigned int max_property)
387*27b03b36SApple OSS Distributions {
388*27b03b36SApple OSS Distributions DTEntry dte;
389*27b03b36SApple OSS Distributions void const *property_data;
390*27b03b36SApple OSS Distributions unsigned int property_size;
391*27b03b36SApple OSS Distributions
392*27b03b36SApple OSS Distributions /*
393*27b03b36SApple OSS Distributions * Look for the property using the PE DT support.
394*27b03b36SApple OSS Distributions */
395*27b03b36SApple OSS Distributions if (kSuccess == SecureDTLookupEntry(NULL, "/defaults", &dte)) {
396*27b03b36SApple OSS Distributions /*
397*27b03b36SApple OSS Distributions * We have a /defaults node, look for the named property.
398*27b03b36SApple OSS Distributions */
399*27b03b36SApple OSS Distributions if (kSuccess != SecureDTGetProperty(dte, property_name, &property_data, &property_size)) {
400*27b03b36SApple OSS Distributions return FALSE;
401*27b03b36SApple OSS Distributions }
402*27b03b36SApple OSS Distributions
403*27b03b36SApple OSS Distributions /*
404*27b03b36SApple OSS Distributions * This would be a fine place to do smart argument size management for 32/64
405*27b03b36SApple OSS Distributions * translation, but for now we'll insist that callers know how big their
406*27b03b36SApple OSS Distributions * default values are.
407*27b03b36SApple OSS Distributions */
408*27b03b36SApple OSS Distributions if (property_size > max_property) {
409*27b03b36SApple OSS Distributions return FALSE;
410*27b03b36SApple OSS Distributions }
411*27b03b36SApple OSS Distributions
412*27b03b36SApple OSS Distributions /*
413*27b03b36SApple OSS Distributions * Copy back the precisely-sized result.
414*27b03b36SApple OSS Distributions */
415*27b03b36SApple OSS Distributions memcpy(property_ptr, property_data, property_size);
416*27b03b36SApple OSS Distributions return TRUE;
417*27b03b36SApple OSS Distributions }
418*27b03b36SApple OSS Distributions
419*27b03b36SApple OSS Distributions /*
420*27b03b36SApple OSS Distributions * Look for the property using I/O Kit's DT support.
421*27b03b36SApple OSS Distributions */
422*27b03b36SApple OSS Distributions return IODTGetDefault(property_name, property_ptr, max_property) ? FALSE : TRUE;
423*27b03b36SApple OSS Distributions }
424*27b03b36SApple OSS Distributions
425*27b03b36SApple OSS Distributions /* function: get_range_bounds
426*27b03b36SApple OSS Distributions * Parse a range string like "1_3,5_20" and return 1,3 as lower and upper.
427*27b03b36SApple OSS Distributions * Note: '_' is separator for bounds integer delimiter and
428*27b03b36SApple OSS Distributions * ',' is considered as separator for range pair.
429*27b03b36SApple OSS Distributions * returns TRUE when both range values are found
430*27b03b36SApple OSS Distributions */
431*27b03b36SApple OSS Distributions boolean_t
get_range_bounds(char * c,int64_t * lower,int64_t * upper)432*27b03b36SApple OSS Distributions get_range_bounds(char *c, int64_t *lower, int64_t *upper)
433*27b03b36SApple OSS Distributions {
434*27b03b36SApple OSS Distributions if (c == NULL || lower == NULL || upper == NULL) {
435*27b03b36SApple OSS Distributions return FALSE;
436*27b03b36SApple OSS Distributions }
437*27b03b36SApple OSS Distributions
438*27b03b36SApple OSS Distributions if (NUM != getval(c, lower, israngesep, TRUE)) {
439*27b03b36SApple OSS Distributions return FALSE;
440*27b03b36SApple OSS Distributions }
441*27b03b36SApple OSS Distributions
442*27b03b36SApple OSS Distributions while (*c != '\0') {
443*27b03b36SApple OSS Distributions if (*c == '_') {
444*27b03b36SApple OSS Distributions break;
445*27b03b36SApple OSS Distributions }
446*27b03b36SApple OSS Distributions c++;
447*27b03b36SApple OSS Distributions }
448*27b03b36SApple OSS Distributions
449*27b03b36SApple OSS Distributions if (*c == '_') {
450*27b03b36SApple OSS Distributions c++;
451*27b03b36SApple OSS Distributions if (NUM != getval(c, upper, israngesep, TRUE)) {
452*27b03b36SApple OSS Distributions return FALSE;
453*27b03b36SApple OSS Distributions }
454*27b03b36SApple OSS Distributions } else {
455*27b03b36SApple OSS Distributions return FALSE;
456*27b03b36SApple OSS Distributions }
457*27b03b36SApple OSS Distributions return TRUE;
458*27b03b36SApple OSS Distributions }
459