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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 #include <gmem_fmri.h>
34 gmem_fmri_init(fmd_hdl_t
*hdl
, gmem_fmri_t
*fmri
, nvlist_t
*nvl
,
40 gmem_vbufname(fmri
->fmri_packnm
, sizeof (fmri
->fmri_packnm
), fmt
, 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
);
58 gmem_fmri_fini(fmd_hdl_t
*hdl
, gmem_fmri_t
*fmri
, int 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
);
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
));
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",
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",
89 gmem_fmri_write(fmd_hdl_t
*hdl
, gmem_fmri_t
*fmri
)
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
,