import less(1)
[unleashed/tickless.git] / usr / src / lib / libsmedia / library / common / l_generic.c
blob6a29f00f60da215ebe1bcb9a93a62e0236046d6a
1 /*
2 * CDDL HEADER START
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.
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]
20 * CDDL HEADER END
23 * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * l_generic.c :
31 * This file contains all defined interfaces for libsm.so
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"
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 *);
50 int32_t
51 smedia_get_device_info(smedia_handle_t handle, struct smdevice_info *dev_info)
53 int32_t ret_val;
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;
60 return (ret_val);
63 int32_t
64 smedia_free_device_info(smedia_handle_t handle, struct smdevice_info *dev_info)
66 int32_t ret_val;
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;
73 return (ret_val);
76 int32_t
77 smedia_get_medium_property(smedia_handle_t handle, smmedium_prop_t *med_info)
79 int32_t ret_val;
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;
85 return (ret_val);
88 int32_t
89 smedia_set_protection_status(smedia_handle_t handle, struct smwp_state *wp)
91 int32_t ret_val;
93 if (wp->sm_version != SMWP_STATE_V_1) {
94 errno = ENOTSUP;
95 return (-1);
97 ret_val = call_function((rmedia_handle_t *)handle,
98 wp, "_m_set_media_status");
99 return (ret_val);
102 int32_t
103 smedia_get_protection_status(smedia_handle_t handle, struct smwp_state *wp)
105 int32_t ret_val;
107 ret_val = call_function((rmedia_handle_t *)handle,
108 wp, "_m_get_media_status");
109 return (ret_val);
112 int32_t
113 smedia_format(smedia_handle_t handle, uint32_t flavor, uint32_t mode)
115 struct format_flags ffl;
116 int32_t ret_val;
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);
125 size_t
126 smedia_raw_read(smedia_handle_t handle,
127 diskaddr_t offset, caddr_t buffer, size_t size)
130 struct raw_params r_p;
131 int32_t ret_val;
133 r_p.offset = (uint32_t)offset;
134 r_p.buffer = buffer;
135 r_p.size = size;
137 ret_val = call_function((rmedia_handle_t *)handle, &r_p, "_m_raw_read");
138 return (ret_val);
141 size_t
142 smedia_raw_write(smedia_handle_t handle,
143 diskaddr_t offset, caddr_t buffer, size_t size)
146 struct raw_params r_p;
147 int32_t ret_val;
149 r_p.offset = (uint32_t)offset;
150 r_p.buffer = buffer;
151 r_p.size = (uint32_t)size;
153 ret_val = call_function((rmedia_handle_t *)handle,
154 &r_p, "_m_raw_write");
156 return (ret_val);
159 int32_t
160 smedia_check_format_status(smedia_handle_t handle)
162 int32_t ret_val;
164 ret_val = call_function((rmedia_handle_t *)handle,
165 NULL, "_m_check_format_status");
167 return (ret_val);
170 int32_t
171 smedia_reassign_block(smedia_handle_t handle, diskaddr_t block)
173 int32_t ret_val;
175 ret_val = call_function((rmedia_handle_t *)handle,
176 &block, "_m_reassign_block");
177 return (ret_val);
180 int32_t
181 smedia_eject(smedia_handle_t handle)
183 int32_t ret_val;
185 ret_val = call_function((rmedia_handle_t *)handle, NULL, "_m_eject");
186 return (ret_val);
189 int32_t
190 smedia_format_track(smedia_handle_t handle, uint32_t trackno, uint32_t head,
191 uint32_t density)
193 int32_t ret_val;
194 struct format_track ft;
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);
204 smedia_handle_t
205 smedia_get_handle(int32_t fd)
207 return (get_handle_from_fd(fd));
210 int32_t
211 smedia_release_handle(smedia_handle_t handle)
213 return (release_handle((rmedia_handle_t *)handle));
216 int32_t
217 smedia_uscsi_cmd(smedia_handle_t handle, struct uscsi_cmd *cmd)
219 int32_t ret_val;
221 ret_val = call_function((rmedia_handle_t *)handle,
222 cmd, "_m_uscsi_cmd");
223 return (ret_val);