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
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]
23 * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 * This file contains all the functionalities except format of
32 * floppy plug-in for libsm.so.
35 #include <sys/types.h>
38 #include <sys/smedia.h>
39 #include "../../../library/inc/rmedia.h"
40 #include "f_defines.h"
44 my_perror(char *err_string
)
52 (void) fprintf(stderr
, gettext(err_string
));
53 (void) fprintf(stderr
, gettext(" : "));
59 _m_device_type(ushort_t ctype
, ushort_t mtype
)
61 if ((ctype
== DKC_INTEL82077
) || (ctype
== DKC_UNKNOWN
)) {
71 return (SM_FD_VERSION_1
);
75 _m_get_media_info(rmedia_handle_t
*handle
, void *ip
)
77 smmedium_prop_t
*med_info
= (smmedium_prop_t
*)ip
;
78 struct fd_char fdchar
;
80 /* Check for valid handle */
82 DPRINTF("Null Handle\n");
86 if (handle
->sm_signature
!= (int32_t)LIBSMEDIA_SIGNATURE
) {
87 DPRINTF("Invalid signature in handle.\n");
89 "Signature expected=0x%x found=0x%x\n",
91 handle
->sm_signature
);
95 if (handle
->sm_fd
< 0) {
96 DPRINTF("Invalid file handle.\n");
100 if (ioctl(handle
->sm_fd
, FDIOGCHAR
, &fdchar
) < 0) {
101 PERROR("Ioctl failed :");
105 med_info
->sm_media_type
= SM_FLOPPY
;
106 med_info
->sm_blocksize
= fdchar
.fdc_sec_size
;
107 med_info
->sm_capacity
= fdchar
.fdc_ncyl
* fdchar
.fdc_nhead
108 * fdchar
.fdc_secptrack
;
109 med_info
->sm_pcyl
= fdchar
.fdc_ncyl
;
110 med_info
->sm_nhead
= fdchar
.fdc_nhead
;
111 med_info
->sm_nsect
= fdchar
.fdc_secptrack
;
117 _m_get_device_info(rmedia_handle_t
*handle
, void *ip
)
119 smdevice_info_t
*dev_info
= (smdevice_info_t
*)ip
;
120 char *vendor_name
, *product_name
, *fw_version
;
122 /* Check for valid handle */
123 if (handle
== NULL
) {
124 DPRINTF("Null Handle\n");
128 if (handle
->sm_signature
!= (int32_t)LIBSMEDIA_SIGNATURE
) {
129 DPRINTF("Invalid signature in handle.\n");
131 "Signature expected=0x%x found=0x%x\n",
133 handle
->sm_signature
);
137 if (handle
->sm_fd
< 0) {
138 DPRINTF("Invalid file handle.\n");
142 vendor_name
= (char *)malloc(1);
143 if (vendor_name
== NULL
) {
148 product_name
= (char *)malloc(1);
149 if (product_name
== NULL
) {
156 fw_version
= (char *)malloc(1);
157 if (fw_version
== NULL
) {
169 dev_info
->sm_interface_type
= IF_FLOPPY
;
170 dev_info
->sm_vendor_name
= vendor_name
;
171 dev_info
->sm_product_name
= product_name
;
172 dev_info
->sm_firmware_version
= fw_version
;
178 _m_free_device_info(rmedia_handle_t
*handle
, void *ip
)
180 struct smdevice_info
*dev_info
= ip
;
182 /* Check for valid handle */
183 if (handle
== NULL
) {
184 DPRINTF("Null Handle\n");
188 if (handle
->sm_signature
!= LIBSMEDIA_SIGNATURE
) {
189 DPRINTF("Invalid signature in handle.\n");
194 free(dev_info
->sm_vendor_name
);
195 free(dev_info
->sm_product_name
);
196 free(dev_info
->sm_firmware_version
);
202 _m_get_media_status(rmedia_handle_t
*handle
, void *ip
)
204 smwp_state_t
*wp
= ip
;
207 if (ioctl(handle
->sm_fd
, FDGETCHANGE
, &j
)) {
210 if (j
& FDGC_CURWPROT
)
211 wp
->sm_new_state
= SM_WRITE_PROTECT_NOPASSWD
;
213 wp
->sm_new_state
= SM_WRITE_PROTECT_DISABLE
;
218 _m_raw_read(rmedia_handle_t
*handle
, void *ip
)
220 struct raw_params
*r_p
= (struct raw_params
*)ip
;
225 struct fd_char fdchar
;
226 int32_t cyl
, rem
, head
, start_sector
;
229 /* Check for valid handle */
230 if (handle
== NULL
) {
231 DPRINTF("Null Handle\n");
235 if (handle
->sm_signature
!= (int32_t)LIBSMEDIA_SIGNATURE
) {
236 DPRINTF("Invalid signature in handle.\n");
238 "Signature expected=0x%x found=0x%x\n",
240 handle
->sm_signature
);
244 if (handle
->sm_fd
< 0) {
245 DPRINTF("Invalid file handle.\n");
249 if (ioctl(handle
->sm_fd
, FDIOGCHAR
, &fdchar
) < 0) {
250 PERROR("Ioctl failed :");
254 sector_size
= fdchar
.fdc_sec_size
;
256 if ((!r_p
->size
) || (r_p
->size
% sector_size
)) {
261 cyl
= r_p
->offset
/(fdchar
.fdc_nhead
* fdchar
.fdc_secptrack
);
262 rem
= r_p
->offset
%(fdchar
.fdc_nhead
* fdchar
.fdc_secptrack
);
263 head
= rem
/fdchar
.fdc_secptrack
;
264 start_sector
= rem
%fdchar
.fdc_secptrack
+ 1;
266 fdraw
.fdr_nbytes
= r_p
->size
;
267 fdraw
.fdr_addr
= r_p
->buffer
;
270 fdraw
.fdr_cmd
[0] = (uint8_t)0xE0 | FDRAW_RDCMD
; /* command */
271 /* MFM | MT | SK| FDRAW_RDCMD */
272 fdraw
.fdr_cmd
[1] = (head
<< 2); /* using head 1 */
273 fdraw
.fdr_cmd
[2] = cyl
; /* track number */
274 fdraw
.fdr_cmd
[3] = head
; /* drive head number */
275 fdraw
.fdr_cmd
[4] = start_sector
; /* start sector number */
276 fdraw
.fdr_cmd
[5] = (sector_size
== 512) ? 2 : 3;
277 fdraw
.fdr_cmd
[6] = fdchar
.fdc_secptrack
;
278 fdraw
.fdr_cmd
[7] = 0x1B; /* GPLN, GAP length */
279 fdraw
.fdr_cmd
[8] = (uchar_t
)0xFF; /* SSSDTL, data length */
280 fdraw
.fdr_cnum
= 0x9; /* NCBRW, no. cmd bytes defined in fdreg.h */
283 ret_val
= ioctl(handle
->sm_fd
, FDRAW
, &fdraw
);
285 PERROR("RAW READ failed:");
289 return (fdraw
.fdr_nbytes
);
292 _m_raw_write(rmedia_handle_t
*handle
, void *ip
)
294 struct raw_params
*r_p
= (struct raw_params
*)ip
;
299 struct fd_char fdchar
;
300 int32_t cyl
, rem
, head
, start_sector
;
303 /* Check for valid handle */
304 if (handle
== NULL
) {
305 DPRINTF("Null Handle\n");
309 if (handle
->sm_signature
!= (int32_t)LIBSMEDIA_SIGNATURE
) {
310 DPRINTF("Invalid signature in handle.\n");
312 "Signature expected=0x%x, found=0x%x\n",
313 LIBSMEDIA_SIGNATURE
, handle
->sm_signature
);
317 if (handle
->sm_fd
< 0) {
318 DPRINTF("Invalid file handle.\n");
322 if (ioctl(handle
->sm_fd
, FDIOGCHAR
, &fdchar
) < 0) {
323 PERROR("Ioctl failed :");
327 sector_size
= fdchar
.fdc_sec_size
;
329 if ((!r_p
->size
) || (r_p
->size
% sector_size
)) {
334 cyl
= r_p
->offset
/(fdchar
.fdc_nhead
* fdchar
.fdc_secptrack
);
335 rem
= r_p
->offset
%(fdchar
.fdc_nhead
* fdchar
.fdc_secptrack
);
336 head
= rem
/fdchar
.fdc_secptrack
;
337 start_sector
= rem
%fdchar
.fdc_secptrack
+ 1;
339 fdraw
.fdr_nbytes
= r_p
->size
;
340 fdraw
.fdr_addr
= r_p
->buffer
;
343 fdraw
.fdr_cmd
[0] = (uint8_t)0xE0| FDRAW_WRCMD
; /* command */
344 /* MFM | MT | SK| FDRAW_WRCMD; */
345 fdraw
.fdr_cmd
[1] = (head
<< 2); /* using head 1 */
346 fdraw
.fdr_cmd
[2] = cyl
; /* track number */
347 fdraw
.fdr_cmd
[3] = head
; /* drive head number */
348 fdraw
.fdr_cmd
[4] = start_sector
; /* start sector number */
349 fdraw
.fdr_cmd
[5] = (sector_size
== 512) ? 2 : 3;
350 fdraw
.fdr_cmd
[6] = fdchar
.fdc_secptrack
;
351 fdraw
.fdr_cmd
[7] = 0x1B; /* GPLN, GAP length */
352 fdraw
.fdr_cmd
[8] = (uchar_t
)0xFF; /* SSSDTL, data length */
353 fdraw
.fdr_cnum
= 0x9; /* NCBRW, no. cmd bytes defined in fdreg.h */
356 ret_val
= ioctl(handle
->sm_fd
, FDRAW
, &fdraw
);
358 PERROR("RAW READ failed:");
362 return (fdraw
.fdr_nbytes
);
367 _m_eject(rmedia_handle_t
*handle
, void *ip
)
370 /* Check for valid handle */
371 if (handle
== NULL
) {
372 DPRINTF("Null Handle\n");
376 if (handle
->sm_signature
!= (int32_t)LIBSMEDIA_SIGNATURE
) {
377 DPRINTF("Invalid signature in handle.\n");
379 "Signature expected=0x%x found=0x%x\n",
380 LIBSMEDIA_SIGNATURE
, handle
->sm_signature
);
384 if (handle
->sm_fd
< 0) {
385 DPRINTF("Invalid file handle.\n");
390 return (ioctl(handle
->sm_fd
, FDEJECT
));