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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
27 * This file contains the functions for generic block devices
34 #include <sys/types.h>
35 #include <sys/param.h>
38 #include "../../../library/inc/smedia.h"
39 #include "../../../library/inc/rmedia.h"
40 #include "../../../library/common/l_defines.h"
42 #define PERROR(string) my_perror(gettext(string))
45 my_perror(char *err_string
)
53 (void) fprintf(stderr
, gettext(err_string
));
54 (void) fprintf(stderr
, gettext(" : "));
62 return (SM_BLKDEV_VERSION_1
);
66 _m_device_type(ushort_t ctype
, ushort_t mtype
)
68 if (ctype
== DKC_BLKDEV
) {
77 _m_get_media_info(rmedia_handle_t
*handle
, void *ip
)
79 smmedium_prop_t
*mp
= (smmedium_prop_t
*)ip
;
81 struct dk_minfo minfo
;
82 enum dkio_state state
= DKIO_NONE
;
86 DPRINTF("Null Handle\n");
90 if (handle
->sm_signature
!= (int32_t)LIBSMEDIA_SIGNATURE
) {
91 DPRINTF2("Signature expected=0x%x, found=0x%x\n",
92 LIBSMEDIA_SIGNATURE
, handle
->sm_signature
);
97 if (ioctl(handle
->sm_fd
, DKIOCSTATE
, &state
) < 0) {
98 PERROR("DKIOCSTATE failed");
102 if (state
!= DKIO_INSERTED
) {
103 DPRINTF("No media.\n");
104 mp
->sm_media_type
= SM_NOT_PRESENT
;
105 mp
->sm_version
= SMMEDIA_PROP_V_1
;
110 ret_val
= ioctl(handle
->sm_fd
, DKIOCGMEDIAINFO
, &minfo
);
112 DPRINTF("DKIOCGMEDIAINFO ioctl failed");
115 ret_val
= ioctl(handle
->sm_fd
, DKIOCGGEOM
, &dkg
);
117 DPRINTF("DKIOCGGEOM ioctl failed");
121 mp
->sm_media_type
= SM_BLOCK
;
122 mp
->sm_blocksize
= minfo
.dki_lbsize
;
123 mp
->sm_capacity
= minfo
.dki_capacity
;
124 mp
->sm_pcyl
= dkg
.dkg_pcyl
;
125 mp
->sm_nhead
= dkg
.dkg_nhead
;
126 mp
->sm_nsect
= dkg
.dkg_nsect
;
135 _m_get_device_info(rmedia_handle_t
*handle
, void *ip
)
137 smdevice_info_t
*mp
= (smdevice_info_t
*)ip
;
138 char *vendor_name
, *product_name
, *fw_version
;
140 if (handle
== NULL
) {
141 DPRINTF("Null Handle\n");
145 if (handle
->sm_signature
!= (int32_t)LIBSMEDIA_SIGNATURE
) {
146 DPRINTF2("Signature expected=0x%x, found=0x%x\n",
147 LIBSMEDIA_SIGNATURE
, handle
->sm_signature
);
151 vendor_name
= (char *)malloc(1);
152 if (vendor_name
== NULL
) {
157 product_name
= (char *)malloc(1);
158 if (product_name
== NULL
) {
165 fw_version
= (char *)malloc(1);
166 if (fw_version
== NULL
) {
174 /* Note: we could potentially offer more here */
178 mp
->sm_interface_type
= IF_BLOCK
;
179 mp
->sm_vendor_name
= vendor_name
;
180 mp
->sm_product_name
= product_name
;
181 mp
->sm_firmware_version
= fw_version
;
186 _m_free_device_info(rmedia_handle_t
*handle
, void *ip
)
188 struct smdevice_info
*dev_info
= ip
;
190 /* Check for valid handle */
191 if (handle
== NULL
) {
192 DPRINTF("Null Handle\n");
196 if (handle
->sm_signature
!= LIBSMEDIA_SIGNATURE
) {
197 DPRINTF("Invalid signature in handle.\n");
202 free(dev_info
->sm_vendor_name
);
203 free(dev_info
->sm_product_name
);
204 free(dev_info
->sm_firmware_version
);