xref: /titanic_41/usr/src/lib/libsmedia/library/inc/smedia.h (revision e4b86885570d77af552e9cf94f142f4d744fb8c8)
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 #ifndef _SMEDIA_H_
28 #define	_SMEDIA_H_
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * smedia.h header for libsmedia library
34  */
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <sys/dkio.h>
43 #include <sys/vtoc.h>
44 #include <sys/scsi/scsi.h>
45 #include <fcntl.h>
46 #include <stdio.h>
47 #include <errno.h>
48 #include <synch.h>
49 
50 typedef struct smdevice_info {
51 	uchar_t	sm_version;
52 	int32_t	sm_interface_type;	/* Interface type */
53 	char	*sm_vendor_name;	/* Vendor name */
54 	char 	*sm_product_name;	/* Product name */
55 	char 	*sm_firmware_version;	/* Firmware version */
56 }smdevice_info_t;
57 
58 typedef	void	*smedia_handle_t;
59 
60 
61 #define	SMDEVICE_INFO_V_1	1
62 
63 /* Interface Types */
64 
65 #define	IF_SCSI		0x0
66 #define	IF_FLOPPY	0x1
67 #define	IF_PCMCIA	0x2
68 
69 
70 typedef struct smmedium_property {
71 	int32_t sm_version;
72 	int32_t sm_media_type;	/* Medium type */
73 	int32_t sm_blocksize;	/* Medium block size in bytes */
74 	int32_t sm_capacity;	/* Medium capacity in no. of blocks */
75 	int32_t sm_pcyl;	/* No. of cylinders on the medium */
76 	int32_t sm_nhead;	/* No. of heads */
77 	int32_t sm_nsect;	/* No. of sectors per cylinder */
78 }smmedium_prop_t;
79 
80 #define	SMMEDIA_PROP_V_1	1
81 
82 /*
83  * Media types not defined for DKIOCGMEDIAINFO
84  */
85 
86 #define	SM_REMOVABLE_DISK	0x20005 /* Removable disk */
87 					/* FIXED_DISK + REMOVABLE */
88 #define	SM_FLOPPY		0x10002 /* Floppy media */
89 #define	SM_SCSI_FLOPPY		0x10005 /* SCSI floppy device */
90 #define	SM_PCMCIA_MEM		0x20006 /* PCMCIA memory card */
91 #define	SM_PCMCIA_ATA		0x20007 /* PCMCIA ata card */
92 #define	SM_NOT_PRESENT		0xFFFF
93 
94 
95 #define	MAX_PASSWD_LENGTH		32
96 
97 #define	PASSWD		0x1000
98 
99 #define	SM_WRITE_PROTECT_DISABLE	(PASSWD|0x0)
100 #define	SM_WRITE_PROTECT_NOPASSWD	(PASSWD|0x2)
101 #define	SM_WRITE_PROTECT_PASSWD		(PASSWD|0x4)
102 #define	SM_READ_WRITE_PROTECT		(PASSWD|0x8)
103 #define	SM_TEMP_UNLOCK_MODE		(PASSWD|0x10)
104 #define	SM_STATUS_UNKNOWN		(PASSWD|0xFF)
105 
106 #define	SM_UNPROTECTED			SM_WRITE_PROTECT_DISABLE
107 #define	SM_WRITE_PROTECTED 		SM_WRITE_PROTECT_NOPASSWD
108 #define	SM_WRITE_PROTECTED_WP   	SM_WRITE_PROTECT_PASSWD
109 #define	SM_READ_WRITE_PROTECTED 	SM_READ_WRITE_PROTECT
110 
111 
112 typedef struct smwp_state {
113 	uchar_t sm_version;
114 	int32_t	sm_new_state;
115 	int32_t	sm_passwd_len;
116 	char	sm_passwd[MAX_PASSWD_LENGTH];
117 }smwp_state_t;
118 
119 #define	SMWP_STATE_V_1			1
120 
121 #define	FORMAT	0x2000
122 
123 #define	SM_FORMAT_LONG		(FORMAT|0x0001)
124 #define	SM_FORMAT_QUICK		(FORMAT|0x0002)
125 #define	SM_FORMAT_FORCE		(FORMAT|0x0003)
126 
127 /* Floppy specific options */
128 #define	SM_FORMAT_HD	(FORMAT|0x0011) /* Format high density (1.44MB) */
129 #define	SM_FORMAT_DD	(FORMAT|0x0012) /* Format Double density (720KB) */
130 #define	SM_FORMAT_ED	(FORMAT|0x0013) /* Format Extended density (2.88MB) */
131 #define	SM_FORMAT_MD	(FORMAT|0x0014) /* Format Medium density (1.2MB) */
132 
133 #define	SM_FORMAT_IMMEDIATE	(FORMAT|0x0021)
134 #define	SM_FORMAT_BLOCKED	(FORMAT|0x0022)
135 
136 
137 /* New Library interface prototypes */
138 
139 int smedia_get_device_info(smedia_handle_t handle, smdevice_info_t *smdevinfop);
140 int smedia_free_device_info(smedia_handle_t handle,
141 		smdevice_info_t *smdevinfop);
142 int smedia_get_medium_property(smedia_handle_t handle,
143 		smmedium_prop_t *smpropp);
144 int smedia_get_protection_status(smedia_handle_t handle,
145 		smwp_state_t *wpstatep);
146 int smedia_set_protection_status(smedia_handle_t handle,
147 		smwp_state_t *wpstatep);
148 size_t smedia_raw_read(smedia_handle_t handle, diskaddr_t blockno,
149 		caddr_t buffer,
150 							size_t nbytes);
151 size_t smedia_raw_write(smedia_handle_t handle, diskaddr_t blockno,
152 		caddr_t buffer,
153 							size_t nbytes);
154 int smedia_format(smedia_handle_t handle, uint_t flavor, uint_t mode);
155 int smedia_check_format_status(smedia_handle_t handle);
156 int smedia_format_track(smedia_handle_t handle, uint_t trackno, uint_t head,
157 							uint_t density);
158 int smedia_eject(smedia_handle_t handle);
159 int smedia_reassign_block(smedia_handle_t handle, diskaddr_t blockno);
160 smedia_handle_t smedia_get_handle(int32_t);
161 int smedia_release_handle(smedia_handle_t handle);
162 int smedia_uscsi_cmd(smedia_handle_t handle, struct uscsi_cmd *cmd);
163 
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* _SMEDIA_H_ */
170