1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * l_generic.c : 31*0Sstevel@tonic-gate * This file contains all defined interfaces for libsm.so 32*0Sstevel@tonic-gate */ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate #include <sys/types.h> 36*0Sstevel@tonic-gate #include <sys/stat.h> 37*0Sstevel@tonic-gate #include <fcntl.h> 38*0Sstevel@tonic-gate #include <stdlib.h> 39*0Sstevel@tonic-gate #include <sys/smedia.h> 40*0Sstevel@tonic-gate #include "../inc/rmedia.h" 41*0Sstevel@tonic-gate #include "l_defines.h" 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate extern int32_t call_function( 44*0Sstevel@tonic-gate rmedia_handle_t *handle, void *ip, char *func_name); 45*0Sstevel@tonic-gate extern smedia_handle_t get_handle(int fd); 46*0Sstevel@tonic-gate extern smedia_handle_t get_handle_from_path(const char *, int32_t, int32_t); 47*0Sstevel@tonic-gate extern smedia_handle_t get_handle_from_fd(int32_t fd); 48*0Sstevel@tonic-gate extern int32_t release_handle(rmedia_handle_t *); 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate int32_t 51*0Sstevel@tonic-gate smedia_get_device_info(smedia_handle_t handle, struct smdevice_info *dev_info) 52*0Sstevel@tonic-gate { 53*0Sstevel@tonic-gate int32_t ret_val; 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 56*0Sstevel@tonic-gate dev_info, "_m_get_device_info"); 57*0Sstevel@tonic-gate DPRINTF1("1....%s\n", dev_info->sm_product_name); 58*0Sstevel@tonic-gate dev_info->sm_version = SMDEVICE_INFO_V_1; 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate return (ret_val); 61*0Sstevel@tonic-gate } 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate int32_t 64*0Sstevel@tonic-gate smedia_free_device_info(smedia_handle_t handle, struct smdevice_info *dev_info) 65*0Sstevel@tonic-gate { 66*0Sstevel@tonic-gate int32_t ret_val; 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 69*0Sstevel@tonic-gate dev_info, "_m_free_device_info"); 70*0Sstevel@tonic-gate DPRINTF1("1....%s\n", dev_info->sm_product_name); 71*0Sstevel@tonic-gate dev_info->sm_version = SMDEVICE_INFO_V_1; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate return (ret_val); 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate int32_t 77*0Sstevel@tonic-gate smedia_get_medium_property(smedia_handle_t handle, smmedium_prop_t *med_info) 78*0Sstevel@tonic-gate { 79*0Sstevel@tonic-gate int32_t ret_val; 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 82*0Sstevel@tonic-gate med_info, "_m_get_media_info"); 83*0Sstevel@tonic-gate med_info->sm_version = SMMEDIA_PROP_V_1; 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate return (ret_val); 86*0Sstevel@tonic-gate } 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate int32_t 89*0Sstevel@tonic-gate smedia_set_protection_status(smedia_handle_t handle, struct smwp_state *wp) 90*0Sstevel@tonic-gate { 91*0Sstevel@tonic-gate int32_t ret_val; 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate if (wp->sm_version != SMWP_STATE_V_1) { 94*0Sstevel@tonic-gate errno = ENOTSUP; 95*0Sstevel@tonic-gate return (-1); 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 98*0Sstevel@tonic-gate wp, "_m_set_media_status"); 99*0Sstevel@tonic-gate return (ret_val); 100*0Sstevel@tonic-gate } 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate int32_t 103*0Sstevel@tonic-gate smedia_get_protection_status(smedia_handle_t handle, struct smwp_state *wp) 104*0Sstevel@tonic-gate { 105*0Sstevel@tonic-gate int32_t ret_val; 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 108*0Sstevel@tonic-gate wp, "_m_get_media_status"); 109*0Sstevel@tonic-gate return (ret_val); 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate int32_t 113*0Sstevel@tonic-gate smedia_format(smedia_handle_t handle, uint32_t flavor, uint32_t mode) 114*0Sstevel@tonic-gate { 115*0Sstevel@tonic-gate struct format_flags ffl; 116*0Sstevel@tonic-gate int32_t ret_val; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate ffl.flavor = flavor; 119*0Sstevel@tonic-gate ffl.mode = mode; 120*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 121*0Sstevel@tonic-gate &ffl, "_m_media_format"); 122*0Sstevel@tonic-gate return (ret_val); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate size_t 126*0Sstevel@tonic-gate smedia_raw_read(smedia_handle_t handle, 127*0Sstevel@tonic-gate diskaddr_t offset, caddr_t buffer, size_t size) 128*0Sstevel@tonic-gate { 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate struct raw_params r_p; 131*0Sstevel@tonic-gate int32_t ret_val; 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate r_p.offset = (uint32_t)offset; 134*0Sstevel@tonic-gate r_p.buffer = buffer; 135*0Sstevel@tonic-gate r_p.size = size; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, &r_p, "_m_raw_read"); 138*0Sstevel@tonic-gate return (ret_val); 139*0Sstevel@tonic-gate } 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate size_t 142*0Sstevel@tonic-gate smedia_raw_write(smedia_handle_t handle, 143*0Sstevel@tonic-gate diskaddr_t offset, caddr_t buffer, size_t size) 144*0Sstevel@tonic-gate { 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate struct raw_params r_p; 147*0Sstevel@tonic-gate int32_t ret_val; 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate r_p.offset = (uint32_t)offset; 150*0Sstevel@tonic-gate r_p.buffer = buffer; 151*0Sstevel@tonic-gate r_p.size = (uint32_t)size; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 154*0Sstevel@tonic-gate &r_p, "_m_raw_write"); 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate return (ret_val); 157*0Sstevel@tonic-gate } 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate int32_t 160*0Sstevel@tonic-gate smedia_check_format_status(smedia_handle_t handle) 161*0Sstevel@tonic-gate { 162*0Sstevel@tonic-gate int32_t ret_val; 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 165*0Sstevel@tonic-gate NULL, "_m_check_format_status"); 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate return (ret_val); 168*0Sstevel@tonic-gate } 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate int32_t 171*0Sstevel@tonic-gate smedia_reassign_block(smedia_handle_t handle, diskaddr_t block) 172*0Sstevel@tonic-gate { 173*0Sstevel@tonic-gate int32_t ret_val; 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 176*0Sstevel@tonic-gate &block, "_m_reassign_block"); 177*0Sstevel@tonic-gate return (ret_val); 178*0Sstevel@tonic-gate } 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate int32_t 181*0Sstevel@tonic-gate smedia_eject(smedia_handle_t handle) 182*0Sstevel@tonic-gate { 183*0Sstevel@tonic-gate int32_t ret_val; 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, NULL, "_m_eject"); 186*0Sstevel@tonic-gate return (ret_val); 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate int32_t 190*0Sstevel@tonic-gate smedia_format_track(smedia_handle_t handle, uint32_t trackno, uint32_t head, 191*0Sstevel@tonic-gate uint32_t density) 192*0Sstevel@tonic-gate { 193*0Sstevel@tonic-gate int32_t ret_val; 194*0Sstevel@tonic-gate struct format_track ft; 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate ft.track_no = (int32_t)trackno; 197*0Sstevel@tonic-gate ft.head = (int32_t)head; 198*0Sstevel@tonic-gate ft.flag = density; 199*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 200*0Sstevel@tonic-gate &ft, "_m_media_format_track"); 201*0Sstevel@tonic-gate return (ret_val); 202*0Sstevel@tonic-gate } 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate smedia_handle_t 205*0Sstevel@tonic-gate smedia_get_handle(int32_t fd) 206*0Sstevel@tonic-gate { 207*0Sstevel@tonic-gate return (get_handle_from_fd(fd)); 208*0Sstevel@tonic-gate } 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate int32_t 211*0Sstevel@tonic-gate smedia_release_handle(smedia_handle_t handle) 212*0Sstevel@tonic-gate { 213*0Sstevel@tonic-gate return (release_handle((rmedia_handle_t *)handle)); 214*0Sstevel@tonic-gate } 215*0Sstevel@tonic-gate 216*0Sstevel@tonic-gate int32_t 217*0Sstevel@tonic-gate smedia_uscsi_cmd(smedia_handle_t handle, struct uscsi_cmd *cmd) 218*0Sstevel@tonic-gate { 219*0Sstevel@tonic-gate int32_t ret_val; 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate ret_val = call_function((rmedia_handle_t *)handle, 222*0Sstevel@tonic-gate cmd, "_m_uscsi_cmd"); 223*0Sstevel@tonic-gate return (ret_val); 224*0Sstevel@tonic-gate } 225