dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / fm / modules / sun4 / cpumem-diagnosis / cmd_fmri.c
blobe4e53f5c2beee893cdfb2daed64ed77f08316c2d
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <errno.h>
30 #include <strings.h>
32 #include <cmd_fmri.h>
33 #include <cmd.h>
35 void
36 cmd_fmri_init(fmd_hdl_t *hdl, cmd_fmri_t *fmri, nvlist_t *nvl,
37 const char *fmt, ...)
39 va_list ap;
41 va_start(ap, fmt);
42 cmd_vbufname(fmri->fmri_packnm, sizeof (fmri->fmri_packnm), fmt, ap);
43 va_end(ap);
45 if ((errno = nvlist_dup(nvl, &fmri->fmri_nvl, 0)) != 0 ||
46 (errno = nvlist_size(nvl, &fmri->fmri_packsz,
47 NV_ENCODE_NATIVE)) != 0)
48 fmd_hdl_abort(hdl, "failed to copy fmri for fmri create");
50 fmri->fmri_packbuf = fmd_hdl_alloc(hdl, fmri->fmri_packsz, FMD_SLEEP);
52 if ((errno = nvlist_pack(nvl, &fmri->fmri_packbuf, &fmri->fmri_packsz,
53 NV_ENCODE_NATIVE, 0)) != 0)
54 fmd_hdl_abort(hdl, "failed to pack fmri for fmri create");
56 cmd_fmri_write(hdl, fmri);
59 void
60 cmd_fmri_fini(fmd_hdl_t *hdl, cmd_fmri_t *fmri, int destroy)
62 if (destroy)
63 fmd_buf_destroy(hdl, NULL, fmri->fmri_packnm);
65 fmd_hdl_free(hdl, fmri->fmri_packbuf, fmri->fmri_packsz);
66 nvlist_free(fmri->fmri_nvl);
69 void
70 cmd_fmri_restore(fmd_hdl_t *hdl, cmd_fmri_t *fmri)
72 if (fmd_buf_size(hdl, NULL, fmri->fmri_packnm) == 0) {
73 bzero(fmri, sizeof (cmd_fmri_t));
74 return;
77 if ((fmri->fmri_packbuf = cmd_buf_read(hdl, NULL, fmri->fmri_packnm,
78 fmri->fmri_packsz)) == NULL) {
79 fmd_hdl_abort(hdl, "failed to read fmri buffer %s",
80 fmri->fmri_packnm);
83 if (nvlist_unpack(fmri->fmri_packbuf, fmri->fmri_packsz,
84 &fmri->fmri_nvl, 0) != 0) {
85 fmd_hdl_abort(hdl, "failed to unpack fmri buffer %s\n",
86 fmri->fmri_packnm);
90 void
91 cmd_fmri_write(fmd_hdl_t *hdl, cmd_fmri_t *fmri)
93 size_t sz;
95 if ((sz = fmd_buf_size(hdl, NULL, fmri->fmri_packnm)) !=
96 fmri->fmri_packsz && sz != 0)
97 fmd_buf_destroy(hdl, NULL, fmri->fmri_packnm);
99 fmd_buf_write(hdl, NULL, fmri->fmri_packnm, fmri->fmri_packbuf,
100 fmri->fmri_packsz);