/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* XXX: This code is quite ugly. You have been warned.
* (Really! This is the only way I could get it to work!)
*/
void
of_dump(void)
{
struct ofiocdesc ofio1, ofio2;
const struct extabent *ex;
char buf1[BUFSIZE], buf2[BUFSIZE], buf3[BUFSIZE], buf4[BUFSIZE];
int fd, optnode;
if (ioctl(fd, OFIOCGETOPTNODE, (char *)&optnode) < 0)
err(1, "OFIOCGETOPTNODE");
memset(&ofio1, 0, sizeof(ofio1));
/* This will grab the first property name from OPIOCNEXTPROP. */
memset(buf1, 0, sizeof(buf1));
memset(buf2, 0, sizeof(buf2));
ofio1.of_nodeid = ofio2.of_nodeid = optnode;
ofio1.of_name = buf1;
ofio1.of_buf = buf2;
ofio2.of_name = buf3;
ofio2.of_buf = buf4;
/*
* For reference: ofio1 is for obtaining the name. Pass the
* name of the last property read in of_name, and the next one
* will be returned in of_buf. To get the first name, pass
* an empty string. There are no more properties when an
* empty string is returned.
*
* ofio2 is for obtaining the value associated with that name.
* For some crazy reason, it seems as if we need to do all
* of that gratuitious zapping and copying. *sigh*
*/
for (;;) {
ofio1.of_namelen = strlen(ofio1.of_name);
ofio1.of_buflen = sizeof(buf2);
/*
* The name of the property we wish to get the
* value for has been stored in the value field
* of ofio1. If the length of the name is 0, there
* are no more properties left.
*/
strcpy(ofio2.of_name, ofio1.of_buf); /* XXX strcpy is safe */
ofio2.of_namelen = strlen(ofio2.of_name);
if (ofio2.of_namelen == 0) {
(void)close(fd);
return;
}
/*
* Place the name of the last read value back into
* ofio1 so that we may obtain the next name.
*/
memset(ofio1.of_name, 0, sizeof(buf1));
memset(ofio1.of_buf, 0, sizeof(buf2));
strcpy(ofio1.of_name, ofio2.of_name); /* XXX strcpy is safe */
}
/* NOTREACHED */
}