8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / picl / plugins / sun4v / mdesc / init.c
blob5c8af51d2a010f61dd1b5b73a8eb3604655fbc10
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <alloca.h>
34 #include <sys/stat.h>
35 #include <malloc.h>
36 #include <fcntl.h>
37 #include <syslog.h>
38 #include <mdesc.h>
39 #include <string.h>
40 #include <errno.h>
42 #define MDESC_PATH "/devices/pseudo/mdesc@0:mdesc"
44 static void mdesc_free(void *bufp, size_t size);
45 uint64_t *md_bufp;
47 md_t *
48 mdesc_devinit(void)
50 int fd;
51 md_t *mdp;
52 size_t size;
55 * We haven't finished using the previous MD/PRI info.
57 if (md_bufp != NULL)
58 return (NULL);
60 do {
61 if ((fd = open(MDESC_PATH, O_RDONLY, 0)) < 0)
62 break;
64 if (ioctl(fd, MDESCIOCGSZ, &size) < 0)
65 break;
66 if ((md_bufp = (uint64_t *)malloc(size)) == NULL) {
67 (void) close(fd);
68 break;
72 * A partial read is as bad as a failed read.
74 if (read(fd, md_bufp, size) != size) {
75 free(md_bufp);
76 md_bufp = NULL;
79 (void) close(fd);
80 /*LINTED: E_CONSTANT_CONDITION */
81 } while (0);
83 if (md_bufp) {
84 mdp = md_init_intern(md_bufp, malloc, mdesc_free);
85 if (mdp == NULL) {
86 free(md_bufp);
87 md_bufp = NULL;
89 } else
90 mdp = NULL;
92 return (mdp);
95 /*ARGSUSED*/
96 void
97 mdesc_free(void *bufp, size_t size)
99 if (bufp)
100 free(bufp);
103 void
104 mdesc_devfini(md_t *mdp)
106 if (mdp)
107 (void) md_fini(mdp);
109 if (md_bufp)
110 free(md_bufp);
111 md_bufp = NULL;