xref: /titanic_52/usr/src/lib/libsmedia/library/inc/smedia.h (revision ac88567a7a5bb7f01cf22cf366bc9d6203e24d7a)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SMEDIA_H_
27 #define	_SMEDIA_H_
28 
29 /*
30  * smedia.h header for libsmedia library
31  */
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/dkio.h>
40 #include <sys/vtoc.h>
41 #include <sys/scsi/scsi.h>
42 #include <fcntl.h>
43 #include <stdio.h>
44 #include <errno.h>
45 #include <synch.h>
46 
47 typedef struct smdevice_info {
48 	uchar_t	sm_version;
49 	int32_t	sm_interface_type;	/* Interface type */
50 	char	*sm_vendor_name;	/* Vendor name */
51 	char 	*sm_product_name;	/* Product name */
52 	char 	*sm_firmware_version;	/* Firmware version */
53 }smdevice_info_t;
54 
55 typedef	void	*smedia_handle_t;
56 
57 
58 #define	SMDEVICE_INFO_V_1	1
59 
60 /* Interface Types */
61 
62 #define	IF_SCSI		0x0
63 #define	IF_FLOPPY	0x1
64 #define	IF_PCMCIA	0x2
65 
66 
67 typedef struct smmedium_property {
68 	int32_t sm_version;
69 	int32_t sm_media_type;	/* Medium type */
70 	int32_t sm_blocksize;	/* Medium block size in bytes */
71 	int32_t sm_capacity;	/* Medium capacity in no. of blocks */
72 	int32_t sm_pcyl;	/* No. of cylinders on the medium */
73 	int32_t sm_nhead;	/* No. of heads */
74 	int32_t sm_nsect;	/* No. of sectors per cylinder */
75 }smmedium_prop_t;
76 
77 #define	SMMEDIA_PROP_V_1	1
78 
79 /*
80  * Media types not defined for DKIOCGMEDIAINFO
81  */
82 
83 #define	SM_REMOVABLE_DISK	0x20005 /* Removable disk */
84 					/* FIXED_DISK + REMOVABLE */
85 #define	SM_FLOPPY		0x10002 /* Floppy media */
86 #define	SM_SCSI_FLOPPY		0x10005 /* SCSI floppy device */
87 #define	SM_PCMCIA_MEM		0x20006 /* PCMCIA memory card (Obsolete) */
88 #define	SM_PCMCIA_ATA		0x20007 /* PCMCIA ata card */
89 #define	SM_NOT_PRESENT		0xFFFF
90 
91 
92 #define	MAX_PASSWD_LENGTH		32
93 
94 #define	PASSWD		0x1000
95 
96 #define	SM_WRITE_PROTECT_DISABLE	(PASSWD|0x0)
97 #define	SM_WRITE_PROTECT_NOPASSWD	(PASSWD|0x2)
98 #define	SM_WRITE_PROTECT_PASSWD		(PASSWD|0x4)
99 #define	SM_READ_WRITE_PROTECT		(PASSWD|0x8)
100 #define	SM_TEMP_UNLOCK_MODE		(PASSWD|0x10)
101 #define	SM_STATUS_UNKNOWN		(PASSWD|0xFF)
102 
103 #define	SM_UNPROTECTED			SM_WRITE_PROTECT_DISABLE
104 #define	SM_WRITE_PROTECTED 		SM_WRITE_PROTECT_NOPASSWD
105 #define	SM_WRITE_PROTECTED_WP   	SM_WRITE_PROTECT_PASSWD
106 #define	SM_READ_WRITE_PROTECTED 	SM_READ_WRITE_PROTECT
107 
108 
109 typedef struct smwp_state {
110 	uchar_t sm_version;
111 	int32_t	sm_new_state;
112 	int32_t	sm_passwd_len;
113 	char	sm_passwd[MAX_PASSWD_LENGTH];
114 }smwp_state_t;
115 
116 #define	SMWP_STATE_V_1			1
117 
118 #define	FORMAT	0x2000
119 
120 #define	SM_FORMAT_LONG		(FORMAT|0x0001)
121 #define	SM_FORMAT_QUICK		(FORMAT|0x0002)
122 #define	SM_FORMAT_FORCE		(FORMAT|0x0003)
123 
124 /* Floppy specific options */
125 #define	SM_FORMAT_HD	(FORMAT|0x0011) /* Format high density (1.44MB) */
126 #define	SM_FORMAT_DD	(FORMAT|0x0012) /* Format Double density (720KB) */
127 #define	SM_FORMAT_ED	(FORMAT|0x0013) /* Format Extended density (2.88MB) */
128 #define	SM_FORMAT_MD	(FORMAT|0x0014) /* Format Medium density (1.2MB) */
129 
130 #define	SM_FORMAT_IMMEDIATE	(FORMAT|0x0021)
131 #define	SM_FORMAT_BLOCKED	(FORMAT|0x0022)
132 
133 
134 /* New Library interface prototypes */
135 
136 int smedia_get_device_info(smedia_handle_t handle, smdevice_info_t *smdevinfop);
137 int smedia_free_device_info(smedia_handle_t handle,
138 		smdevice_info_t *smdevinfop);
139 int smedia_get_medium_property(smedia_handle_t handle,
140 		smmedium_prop_t *smpropp);
141 int smedia_get_protection_status(smedia_handle_t handle,
142 		smwp_state_t *wpstatep);
143 int smedia_set_protection_status(smedia_handle_t handle,
144 		smwp_state_t *wpstatep);
145 size_t smedia_raw_read(smedia_handle_t handle, diskaddr_t blockno,
146 		caddr_t buffer,
147 							size_t nbytes);
148 size_t smedia_raw_write(smedia_handle_t handle, diskaddr_t blockno,
149 		caddr_t buffer,
150 							size_t nbytes);
151 int smedia_format(smedia_handle_t handle, uint_t flavor, uint_t mode);
152 int smedia_check_format_status(smedia_handle_t handle);
153 int smedia_format_track(smedia_handle_t handle, uint_t trackno, uint_t head,
154 							uint_t density);
155 int smedia_eject(smedia_handle_t handle);
156 int smedia_reassign_block(smedia_handle_t handle, diskaddr_t blockno);
157 smedia_handle_t smedia_get_handle(int32_t);
158 int smedia_release_handle(smedia_handle_t handle);
159 int smedia_uscsi_cmd(smedia_handle_t handle, struct uscsi_cmd *cmd);
160 
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* _SMEDIA_H_ */
167