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
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
36 cmd_fmri_init(fmd_hdl_t
*hdl
, cmd_fmri_t
*fmri
, nvlist_t
*nvl
,
42 cmd_vbufname(fmri
->fmri_packnm
, sizeof (fmri
->fmri_packnm
), fmt
, 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
);
60 cmd_fmri_fini(fmd_hdl_t
*hdl
, cmd_fmri_t
*fmri
, int 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
);
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
));
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",
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",
91 cmd_fmri_write(fmd_hdl_t
*hdl
, cmd_fmri_t
*fmri
)
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
,