1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * l_generic.c :
29  *      This file contains all defined interfaces for libsm.so
30  */
31 
32 
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <stdlib.h>
37 #include <sys/smedia.h>
38 #include "../inc/rmedia.h"
39 #include "l_defines.h"
40 
41 extern int32_t call_function(
42 			rmedia_handle_t *handle,  void *ip, char *func_name);
43 extern smedia_handle_t get_handle(int fd);
44 extern smedia_handle_t get_handle_from_path(const char *, int32_t, int32_t);
45 extern smedia_handle_t get_handle_from_fd(int32_t fd);
46 extern int32_t release_handle(rmedia_handle_t *);
47 
48 int32_t
smedia_get_device_info(smedia_handle_t handle,struct smdevice_info * dev_info)49 smedia_get_device_info(smedia_handle_t handle, struct smdevice_info *dev_info)
50 {
51 	int32_t ret_val;
52 
53 	ret_val = call_function((rmedia_handle_t *)handle,
54 		dev_info, "_m_get_device_info");
55 	DPRINTF1("1....%s\n", dev_info->sm_product_name);
56 	dev_info->sm_version = SMDEVICE_INFO_V_1;
57 
58 	return (ret_val);
59 }
60 
61 int32_t
smedia_free_device_info(smedia_handle_t handle,struct smdevice_info * dev_info)62 smedia_free_device_info(smedia_handle_t handle, struct smdevice_info *dev_info)
63 {
64 	int32_t ret_val;
65 
66 	ret_val = call_function((rmedia_handle_t *)handle,
67 		dev_info, "_m_free_device_info");
68 	DPRINTF1("1....%s\n", dev_info->sm_product_name);
69 	dev_info->sm_version = SMDEVICE_INFO_V_1;
70 
71 	return (ret_val);
72 }
73 
74 int32_t
smedia_get_medium_property(smedia_handle_t handle,smmedium_prop_t * med_info)75 smedia_get_medium_property(smedia_handle_t handle, smmedium_prop_t *med_info)
76 {
77 	int32_t ret_val;
78 
79 	ret_val = call_function((rmedia_handle_t *)handle,
80 		med_info, "_m_get_media_info");
81 	med_info->sm_version = SMMEDIA_PROP_V_1;
82 
83 	return (ret_val);
84 }
85 
86 int32_t
smedia_set_protection_status(smedia_handle_t handle,struct smwp_state * wp)87 smedia_set_protection_status(smedia_handle_t handle, struct smwp_state *wp)
88 {
89 	int32_t ret_val;
90 
91 	if (wp->sm_version != SMWP_STATE_V_1) {
92 		errno = ENOTSUP;
93 		return (-1);
94 	}
95 	ret_val = call_function((rmedia_handle_t *)handle,
96 		wp, "_m_set_media_status");
97 	return (ret_val);
98 }
99 
100 int32_t
smedia_get_protection_status(smedia_handle_t handle,struct smwp_state * wp)101 smedia_get_protection_status(smedia_handle_t handle, struct smwp_state *wp)
102 {
103 	int32_t ret_val;
104 
105 	ret_val = call_function((rmedia_handle_t *)handle,
106 		wp, "_m_get_media_status");
107 	return (ret_val);
108 }
109 
110 int32_t
smedia_format(smedia_handle_t handle,uint32_t flavor,uint32_t mode)111 smedia_format(smedia_handle_t handle, uint32_t flavor, uint32_t mode)
112 {
113 	struct format_flags ffl;
114 	int32_t ret_val;
115 
116 	ffl.flavor = flavor;
117 	ffl.mode   = mode;
118 	ret_val = call_function((rmedia_handle_t *)handle,
119 		&ffl, "_m_media_format");
120 	return (ret_val);
121 }
122 
123 size_t
smedia_raw_read(smedia_handle_t handle,diskaddr_t offset,caddr_t buffer,size_t size)124 smedia_raw_read(smedia_handle_t handle,
125 		diskaddr_t offset, caddr_t buffer, size_t size)
126 {
127 
128 	struct raw_params r_p;
129 	int32_t ret_val;
130 
131 	r_p.offset = (uint32_t)offset;
132 	r_p.buffer = buffer;
133 	r_p.size = size;
134 
135 	ret_val = call_function((rmedia_handle_t *)handle, &r_p, "_m_raw_read");
136 	return (ret_val);
137 }
138 
139 size_t
smedia_raw_write(smedia_handle_t handle,diskaddr_t offset,caddr_t buffer,size_t size)140 smedia_raw_write(smedia_handle_t handle,
141 		diskaddr_t offset, caddr_t buffer, size_t size)
142 {
143 
144 	struct raw_params r_p;
145 	int32_t ret_val;
146 
147 	r_p.offset = (uint32_t)offset;
148 	r_p.buffer = buffer;
149 	r_p.size = (uint32_t)size;
150 
151 	ret_val = call_function((rmedia_handle_t *)handle,
152 		&r_p, "_m_raw_write");
153 
154 	return (ret_val);
155 }
156 
157 int32_t
smedia_check_format_status(smedia_handle_t handle)158 smedia_check_format_status(smedia_handle_t handle)
159 {
160 	int32_t ret_val;
161 
162 	ret_val = call_function((rmedia_handle_t *)handle,
163 		NULL, "_m_check_format_status");
164 
165 	return (ret_val);
166 }
167 
168 int32_t
smedia_reassign_block(smedia_handle_t handle,diskaddr_t block)169 smedia_reassign_block(smedia_handle_t handle, diskaddr_t block)
170 {
171 	int32_t ret_val;
172 
173 	ret_val = call_function((rmedia_handle_t *)handle,
174 		&block, "_m_reassign_block");
175 	return (ret_val);
176 }
177 
178 int32_t
smedia_eject(smedia_handle_t handle)179 smedia_eject(smedia_handle_t handle)
180 {
181 	int32_t ret_val;
182 
183 	ret_val = call_function((rmedia_handle_t *)handle, NULL, "_m_eject");
184 	return (ret_val);
185 }
186 
187 int32_t
smedia_format_track(smedia_handle_t handle,uint32_t trackno,uint32_t head,uint32_t density)188 smedia_format_track(smedia_handle_t handle, uint32_t trackno, uint32_t head,
189 						uint32_t density)
190 {
191 	int32_t ret_val;
192 	struct format_track ft;
193 
194 	ft.track_no = (int32_t)trackno;
195 	ft.head = (int32_t)head;
196 	ft.flag = density;
197 	ret_val = call_function((rmedia_handle_t *)handle,
198 		&ft, "_m_media_format_track");
199 	return (ret_val);
200 }
201 
202 smedia_handle_t
smedia_get_handle(int32_t fd)203 smedia_get_handle(int32_t fd)
204 {
205 	return (get_handle_from_fd(fd));
206 }
207 
208 int32_t
smedia_release_handle(smedia_handle_t handle)209 smedia_release_handle(smedia_handle_t handle)
210 {
211 	return (release_handle((rmedia_handle_t *)handle));
212 }
213 
214 int32_t
smedia_uscsi_cmd(smedia_handle_t handle,struct uscsi_cmd * cmd)215 smedia_uscsi_cmd(smedia_handle_t handle, struct uscsi_cmd *cmd)
216 {
217 	int32_t ret_val;
218 
219 	ret_val = call_function((rmedia_handle_t *)handle,
220 			cmd, "_m_uscsi_cmd");
221 	return (ret_val);
222 }
223