xref: /illumos-gate/usr/src/lib/libsmedia/library/inc/smedia.h (revision 3f7d54a6b84904c8f4d8daa4c7b577bede7df8b9)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
569ed0c8eSGarrett D'Amore  * Common Development and Distribution License (the "License").
669ed0c8eSGarrett D'Amore  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*3f7d54a6SGarrett D'Amore  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef _SMEDIA_H_
267c478bd9Sstevel@tonic-gate #define	_SMEDIA_H_
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * smedia.h header for libsmedia library
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/stat.h>
387c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
397c478bd9Sstevel@tonic-gate #include <sys/vtoc.h>
407c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi.h>
417c478bd9Sstevel@tonic-gate #include <fcntl.h>
427c478bd9Sstevel@tonic-gate #include <stdio.h>
437c478bd9Sstevel@tonic-gate #include <errno.h>
447c478bd9Sstevel@tonic-gate #include <synch.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate typedef struct smdevice_info {
477c478bd9Sstevel@tonic-gate 	uchar_t	sm_version;
487c478bd9Sstevel@tonic-gate 	int32_t	sm_interface_type;	/* Interface type */
497c478bd9Sstevel@tonic-gate 	char	*sm_vendor_name;	/* Vendor name */
507c478bd9Sstevel@tonic-gate 	char 	*sm_product_name;	/* Product name */
517c478bd9Sstevel@tonic-gate 	char 	*sm_firmware_version;	/* Firmware version */
527c478bd9Sstevel@tonic-gate }smdevice_info_t;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate typedef	void	*smedia_handle_t;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	SMDEVICE_INFO_V_1	1
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /* Interface Types */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	IF_SCSI		0x0
627c478bd9Sstevel@tonic-gate #define	IF_FLOPPY	0x1
637c478bd9Sstevel@tonic-gate #define	IF_PCMCIA	0x2
64*3f7d54a6SGarrett D'Amore #define	IF_BLOCK	0x3
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate typedef struct smmedium_property {
687c478bd9Sstevel@tonic-gate 	int32_t sm_version;
697c478bd9Sstevel@tonic-gate 	int32_t sm_media_type;	/* Medium type */
707c478bd9Sstevel@tonic-gate 	int32_t sm_blocksize;	/* Medium block size in bytes */
717c478bd9Sstevel@tonic-gate 	int32_t sm_capacity;	/* Medium capacity in no. of blocks */
727c478bd9Sstevel@tonic-gate 	int32_t sm_pcyl;	/* No. of cylinders on the medium */
737c478bd9Sstevel@tonic-gate 	int32_t sm_nhead;	/* No. of heads */
747c478bd9Sstevel@tonic-gate 	int32_t sm_nsect;	/* No. of sectors per cylinder */
757c478bd9Sstevel@tonic-gate }smmedium_prop_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #define	SMMEDIA_PROP_V_1	1
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * Media types not defined for DKIOCGMEDIAINFO
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #define	SM_REMOVABLE_DISK	0x20005 /* Removable disk */
847c478bd9Sstevel@tonic-gate 					/* FIXED_DISK + REMOVABLE */
857c478bd9Sstevel@tonic-gate #define	SM_FLOPPY		0x10002 /* Floppy media */
867c478bd9Sstevel@tonic-gate #define	SM_SCSI_FLOPPY		0x10005 /* SCSI floppy device */
8769ed0c8eSGarrett D'Amore #define	SM_PCMCIA_MEM		0x20006 /* PCMCIA memory card (Obsolete) */
887c478bd9Sstevel@tonic-gate #define	SM_PCMCIA_ATA		0x20007 /* PCMCIA ata card */
89*3f7d54a6SGarrett D'Amore #define	SM_BLOCK		0x20008	/* Generic block device */
907c478bd9Sstevel@tonic-gate #define	SM_NOT_PRESENT		0xFFFF
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	MAX_PASSWD_LENGTH		32
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	PASSWD		0x1000
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	SM_WRITE_PROTECT_DISABLE	(PASSWD|0x0)
987c478bd9Sstevel@tonic-gate #define	SM_WRITE_PROTECT_NOPASSWD	(PASSWD|0x2)
997c478bd9Sstevel@tonic-gate #define	SM_WRITE_PROTECT_PASSWD		(PASSWD|0x4)
1007c478bd9Sstevel@tonic-gate #define	SM_READ_WRITE_PROTECT		(PASSWD|0x8)
1017c478bd9Sstevel@tonic-gate #define	SM_TEMP_UNLOCK_MODE		(PASSWD|0x10)
1027c478bd9Sstevel@tonic-gate #define	SM_STATUS_UNKNOWN		(PASSWD|0xFF)
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	SM_UNPROTECTED			SM_WRITE_PROTECT_DISABLE
1057c478bd9Sstevel@tonic-gate #define	SM_WRITE_PROTECTED 		SM_WRITE_PROTECT_NOPASSWD
1067c478bd9Sstevel@tonic-gate #define	SM_WRITE_PROTECTED_WP   	SM_WRITE_PROTECT_PASSWD
1077c478bd9Sstevel@tonic-gate #define	SM_READ_WRITE_PROTECTED 	SM_READ_WRITE_PROTECT
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate typedef struct smwp_state {
1117c478bd9Sstevel@tonic-gate 	uchar_t sm_version;
1127c478bd9Sstevel@tonic-gate 	int32_t	sm_new_state;
1137c478bd9Sstevel@tonic-gate 	int32_t	sm_passwd_len;
1147c478bd9Sstevel@tonic-gate 	char	sm_passwd[MAX_PASSWD_LENGTH];
1157c478bd9Sstevel@tonic-gate }smwp_state_t;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	SMWP_STATE_V_1			1
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	FORMAT	0x2000
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	SM_FORMAT_LONG		(FORMAT|0x0001)
1227c478bd9Sstevel@tonic-gate #define	SM_FORMAT_QUICK		(FORMAT|0x0002)
1237c478bd9Sstevel@tonic-gate #define	SM_FORMAT_FORCE		(FORMAT|0x0003)
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /* Floppy specific options */
1267c478bd9Sstevel@tonic-gate #define	SM_FORMAT_HD	(FORMAT|0x0011) /* Format high density (1.44MB) */
1277c478bd9Sstevel@tonic-gate #define	SM_FORMAT_DD	(FORMAT|0x0012) /* Format Double density (720KB) */
1287c478bd9Sstevel@tonic-gate #define	SM_FORMAT_ED	(FORMAT|0x0013) /* Format Extended density (2.88MB) */
1297c478bd9Sstevel@tonic-gate #define	SM_FORMAT_MD	(FORMAT|0x0014) /* Format Medium density (1.2MB) */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #define	SM_FORMAT_IMMEDIATE	(FORMAT|0x0021)
1327c478bd9Sstevel@tonic-gate #define	SM_FORMAT_BLOCKED	(FORMAT|0x0022)
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /* New Library interface prototypes */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate int smedia_get_device_info(smedia_handle_t handle, smdevice_info_t *smdevinfop);
1387c478bd9Sstevel@tonic-gate int smedia_free_device_info(smedia_handle_t handle,
1397c478bd9Sstevel@tonic-gate 		smdevice_info_t *smdevinfop);
1407c478bd9Sstevel@tonic-gate int smedia_get_medium_property(smedia_handle_t handle,
1417c478bd9Sstevel@tonic-gate 		smmedium_prop_t *smpropp);
1427c478bd9Sstevel@tonic-gate int smedia_get_protection_status(smedia_handle_t handle,
1437c478bd9Sstevel@tonic-gate 		smwp_state_t *wpstatep);
1447c478bd9Sstevel@tonic-gate int smedia_set_protection_status(smedia_handle_t handle,
1457c478bd9Sstevel@tonic-gate 		smwp_state_t *wpstatep);
1467c478bd9Sstevel@tonic-gate size_t smedia_raw_read(smedia_handle_t handle, diskaddr_t blockno,
1477c478bd9Sstevel@tonic-gate 		caddr_t buffer,
1487c478bd9Sstevel@tonic-gate 							size_t nbytes);
1497c478bd9Sstevel@tonic-gate size_t smedia_raw_write(smedia_handle_t handle, diskaddr_t blockno,
1507c478bd9Sstevel@tonic-gate 		caddr_t buffer,
1517c478bd9Sstevel@tonic-gate 							size_t nbytes);
1527c478bd9Sstevel@tonic-gate int smedia_format(smedia_handle_t handle, uint_t flavor, uint_t mode);
1537c478bd9Sstevel@tonic-gate int smedia_check_format_status(smedia_handle_t handle);
1547c478bd9Sstevel@tonic-gate int smedia_format_track(smedia_handle_t handle, uint_t trackno, uint_t head,
1557c478bd9Sstevel@tonic-gate 							uint_t density);
1567c478bd9Sstevel@tonic-gate int smedia_eject(smedia_handle_t handle);
1577c478bd9Sstevel@tonic-gate int smedia_reassign_block(smedia_handle_t handle, diskaddr_t blockno);
1587c478bd9Sstevel@tonic-gate smedia_handle_t smedia_get_handle(int32_t);
1597c478bd9Sstevel@tonic-gate int smedia_release_handle(smedia_handle_t handle);
1607c478bd9Sstevel@tonic-gate int smedia_uscsi_cmd(smedia_handle_t handle, struct uscsi_cmd *cmd);
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate #endif
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #endif /* _SMEDIA_H_ */
168