summaryrefslogtreecommitdiff
path: root/usr/src/cmd/picl/plugins/sun4v/mdesc/init.c
diff options
context:
space:
mode:
authorvenki <none@none>2007-03-31 18:24:05 -0700
committervenki <none@none>2007-03-31 18:24:05 -0700
commit0d63ce2b32a9e1cc8ed71d4d92536c44d66a530a (patch)
tree44032a0316e273c5597b6257f3510bd4dcb77e1f /usr/src/cmd/picl/plugins/sun4v/mdesc/init.c
parent1c02caff5ab8a73df8274cf66e0444b24cf4af10 (diff)
downloadillumos-joyent-0d63ce2b32a9e1cc8ed71d4d92536c44d66a530a.tar.gz
FWARC/2007/133 SNMP Domain Service
FWARC/2007/138 Updates to PRI structures 6438074 customer requests ability to query power/fan status info from OS 6526169 prtdiag output doesn't have Memory Configuration Information 6531453 sun4v picl needs device labels in the devtree 6534449 Unable to send a domain services message larger than 4K
Diffstat (limited to 'usr/src/cmd/picl/plugins/sun4v/mdesc/init.c')
-rw-r--r--usr/src/cmd/picl/plugins/sun4v/mdesc/init.c82
1 files changed, 31 insertions, 51 deletions
diff --git a/usr/src/cmd/picl/plugins/sun4v/mdesc/init.c b/usr/src/cmd/picl/plugins/sun4v/mdesc/init.c
index d9e52a293f..5c8af51d2a 100644
--- a/usr/src/cmd/picl/plugins/sun4v/mdesc/init.c
+++ b/usr/src/cmd/picl/plugins/sun4v/mdesc/init.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -40,74 +40,54 @@
#include <errno.h>
#define MDESC_PATH "/devices/pseudo/mdesc@0:mdesc"
-#define SIZE 8192
static void mdesc_free(void *bufp, size_t size);
-uint8_t *md_bufp;
+uint64_t *md_bufp;
md_t *
mdesc_devinit(void)
{
- int fh;
- int res;
- int size;
- int offset;
+ int fd;
md_t *mdp;
+ size_t size;
+ /*
+ * We haven't finished using the previous MD/PRI info.
+ */
if (md_bufp != NULL)
return (NULL);
- fh = open(MDESC_PATH, O_RDONLY, 0);
- if (fh < 0) {
- return (NULL);
- }
-
- size = SIZE; /* initial size */
- offset = 0;
-
- md_bufp = malloc(size);
- if (NULL == md_bufp) {
- return (NULL);
- }
-
- /* OK read until we get a EOF */
-
do {
- int len;
-
- len = size - offset;
-
- while (len < SIZE) {
- size += SIZE;
- md_bufp = realloc(md_bufp, size);
- if (NULL == md_bufp)
- return (NULL);
- len = size - offset;
+ if ((fd = open(MDESC_PATH, O_RDONLY, 0)) < 0)
+ break;
+
+ if (ioctl(fd, MDESCIOCGSZ, &size) < 0)
+ break;
+ if ((md_bufp = (uint64_t *)malloc(size)) == NULL) {
+ (void) close(fd);
+ break;
}
- do {
- res = read(fh, md_bufp + offset, len);
- } while ((res < 0) && (errno == EAGAIN));
-
- if (res < 0) {
+ /*
+ * A partial read is as bad as a failed read.
+ */
+ if (read(fd, md_bufp, size) != size) {
free(md_bufp);
- return (NULL);
+ md_bufp = NULL;
}
- offset += res;
- } while (res > 0);
-
- (void) close(fh);
-
- md_bufp = realloc(md_bufp, offset);
- if (NULL == md_bufp)
- return (NULL);
+ (void) close(fd);
+ /*LINTED: E_CONSTANT_CONDITION */
+ } while (0);
- mdp = md_init_intern((uint64_t *)md_bufp, malloc, mdesc_free);
- if (NULL == mdp) {
- free(md_bufp);
- return (NULL);
- }
+ if (md_bufp) {
+ mdp = md_init_intern(md_bufp, malloc, mdesc_free);
+ if (mdp == NULL) {
+ free(md_bufp);
+ md_bufp = NULL;
+ }
+ } else
+ mdp = NULL;
return (mdp);
}