2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Bootparams lookup - netinfo only
26 * Copyright (C) 1989 by NeXT, Inc.
29 #include <mach/mach.h>
32 #include <rpc/types.h>
34 #include <bootparams.h>
37 #include "_lu_types.h"
40 static lookup_state bp_state
= LOOKUP_CACHE
;
41 static struct bootparamsent global_bp
;
42 static int global_free
= 1;
43 static char *bp_data
= NULL
;
44 static unsigned bp_datalen
;
45 static int bp_nentries
;
46 static int bp_start
= 1;
53 if (global_free
== 1) return;
55 free(global_bp
.bp_name
);
57 for (i
= 0; global_bp
.bp_bootparams
[i
] != NULL
; i
++)
58 free(global_bp
.bp_bootparams
[i
]);
64 convert_bootparamsent(_lu_bootparams_ent
*lu_bpent
)
70 global_bp
.bp_name
= strdup(lu_bpent
->bootparams_name
);
72 len
= lu_bpent
->bootparams_keyvalues
.bootparams_keyvalues_len
;
73 global_bp
.bp_bootparams
= (char **)malloc((len
+ 1) * sizeof(char *));
75 for (i
= 0; i
< len
; i
++)
77 global_bp
.bp_bootparams
[i
] =
78 strdup(lu_bpent
->bootparams_keyvalues
.bootparams_keyvalues_val
[i
]);
81 global_bp
.bp_bootparams
[len
] = NULL
;
86 static struct bootparamsent
*
87 lu_bootparams_getbyname(const char *name
)
90 char namebuf
[_LU_MAXLUSTRLEN
+ BYTES_PER_XDR_UNIT
];
91 unit lookup_buf
[MAX_INLINE_UNITS
];
95 _lu_bootparams_ent_ptr lu_bpent
;
100 if (_lookup_link(_lu_port
, "bootparams_getbyname", &proc
)
107 xdrmem_create(&outxdr
, namebuf
, sizeof(namebuf
), XDR_ENCODE
);
108 if (!xdr__lu_string(&outxdr
, &name
))
110 xdr_destroy(&outxdr
);
114 size
= xdr_getpos(&outxdr
);
115 xdr_destroy(&outxdr
);
117 datalen
= MAX_INLINE_UNITS
;
118 if (_lookup_one(_lu_port
, proc
, (unit
*)namebuf
, size
, lookup_buf
,
119 &datalen
) != KERN_SUCCESS
)
124 datalen
*= BYTES_PER_XDR_UNIT
;
125 xdrmem_create(&inxdr
, lookup_buf
, datalen
,
128 if (!xdr__lu_bootparams_ent_ptr(&inxdr
, &lu_bpent
) || (lu_bpent
== NULL
))
136 convert_bootparamsent(lu_bpent
);
137 xdr_free(xdr__lu_bootparams_ent_ptr
, &lu_bpent
);
142 lu_bootparams_endent(void)
148 vm_deallocate(mach_task_self(), (vm_address_t
)bp_data
, bp_datalen
);
154 lu_bootparams_setent(void)
156 lu_bootparams_endent();
160 static struct bootparamsent
*
161 lu_bootparams_getent(void)
163 static int proc
= -1;
164 _lu_bootparams_ent lu_bpent
;
172 if (_lookup_link(_lu_port
, "bootparams_getent", &proc
)
175 lu_bootparams_endent();
180 if (_lookup_all(_lu_port
, proc
, NULL
, 0, &bp_data
, &bp_datalen
)
183 lu_bootparams_endent();
188 /* NOTDEF because OOL buffers are counted in bytes with untyped IPC */
189 bp_datalen
*= BYTES_PER_XDR_UNIT
;
191 xdrmem_create(&bp_xdr
, bp_data
, bp_datalen
,
193 if (!xdr_int(&bp_xdr
, &bp_nentries
))
195 xdr_destroy(&bp_xdr
);
196 lu_bootparams_endent();
201 if (bp_nentries
== 0)
203 xdr_destroy(&bp_xdr
);
204 lu_bootparams_endent();
208 bzero(&lu_bpent
, sizeof(lu_bpent
));
209 if (!xdr__lu_bootparams_ent(&bp_xdr
, &lu_bpent
))
211 xdr_destroy(&bp_xdr
);
212 lu_bootparams_endent();
217 convert_bootparamsent(&lu_bpent
);
218 xdr_free(xdr__lu_bootparams_ent
, &lu_bpent
);
222 struct bootparamsent
*
223 bootparams_getbyname(const char *name
)
225 if (_lu_running()) return (lu_bootparams_getbyname(name
));
229 struct bootparamsent
*
230 bootparams_getent(void)
232 if (_lu_running()) return (lu_bootparams_getent());
237 bootparams_setent(void)
239 if (_lu_running()) lu_bootparams_setent();
243 bootparams_endent(void)
245 if (_lu_running()) lu_bootparams_endent();