8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fm / modules / sun4v / generic-mem / gmem_fmri.c
blobd3924da501dd323c3f372326adf1b099e0228352
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
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <errno.h>
28 #include <strings.h>
30 #include <gmem_fmri.h>
31 #include <gmem.h>
33 void
34 gmem_fmri_init(fmd_hdl_t *hdl, gmem_fmri_t *fmri, nvlist_t *nvl,
35 const char *fmt, ...)
37 va_list ap;
39 va_start(ap, fmt);
40 gmem_vbufname(fmri->fmri_packnm, sizeof (fmri->fmri_packnm), fmt, ap);
41 va_end(ap);
43 if ((errno = nvlist_dup(nvl, &fmri->fmri_nvl, 0)) != 0 ||
44 (errno = nvlist_size(nvl, &fmri->fmri_packsz,
45 NV_ENCODE_NATIVE)) != 0)
46 fmd_hdl_abort(hdl, "failed to copy fmri for fmri create");
48 fmri->fmri_packbuf = fmd_hdl_alloc(hdl, fmri->fmri_packsz, FMD_SLEEP);
50 if ((errno = nvlist_pack(nvl, &fmri->fmri_packbuf, &fmri->fmri_packsz,
51 NV_ENCODE_NATIVE, 0)) != 0)
52 fmd_hdl_abort(hdl, "failed to pack fmri for fmri create");
54 gmem_fmri_write(hdl, fmri);
57 void
58 gmem_fmri_fini(fmd_hdl_t *hdl, gmem_fmri_t *fmri, int destroy)
60 if (destroy)
61 fmd_buf_destroy(hdl, NULL, fmri->fmri_packnm);
63 fmd_hdl_free(hdl, fmri->fmri_packbuf, fmri->fmri_packsz);
64 nvlist_free(fmri->fmri_nvl);
67 void
68 gmem_fmri_restore(fmd_hdl_t *hdl, gmem_fmri_t *fmri)
70 if (fmd_buf_size(hdl, NULL, fmri->fmri_packnm) == 0) {
71 bzero(fmri, sizeof (gmem_fmri_t));
72 return;
75 if ((fmri->fmri_packbuf = gmem_buf_read(hdl, NULL, fmri->fmri_packnm,
76 fmri->fmri_packsz)) == NULL) {
77 fmd_hdl_abort(hdl, "failed to read fmri buffer %s",
78 fmri->fmri_packnm);
81 if (nvlist_unpack(fmri->fmri_packbuf, fmri->fmri_packsz,
82 &fmri->fmri_nvl, 0) != 0) {
83 fmd_hdl_abort(hdl, "failed to unpack fmri buffer %s\n",
84 fmri->fmri_packnm);
88 void
89 gmem_fmri_write(fmd_hdl_t *hdl, gmem_fmri_t *fmri)
91 size_t sz;
93 if ((sz = fmd_buf_size(hdl, NULL, fmri->fmri_packnm)) !=
94 fmri->fmri_packsz && sz != 0)
95 fmd_buf_destroy(hdl, NULL, fmri->fmri_packnm);
97 fmd_buf_write(hdl, NULL, fmri->fmri_packnm, fmri->fmri_packbuf,
98 fmri->fmri_packsz);