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