xref: /titanic_51/usr/src/lib/libsmedia/library/inc/smedia.h (revision dd51520e127b452179a2ce4ea3bd8dee949f9afe)
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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _SMEDIA_H_
26 #define	_SMEDIA_H_
27 
28 /*
29  * smedia.h header for libsmedia library
30  */
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <sys/dkio.h>
39 #include <sys/vtoc.h>
40 #include <sys/scsi/scsi.h>
41 #include <fcntl.h>
42 #include <stdio.h>
43 #include <errno.h>
44 #include <synch.h>
45 
46 typedef struct smdevice_info {
47 	uchar_t	sm_version;
48 	int32_t	sm_interface_type;	/* Interface type */
49 	char	*sm_vendor_name;	/* Vendor name */
50 	char 	*sm_product_name;	/* Product name */
51 	char 	*sm_firmware_version;	/* Firmware version */
52 }smdevice_info_t;
53 
54 typedef	void	*smedia_handle_t;
55 
56 
57 #define	SMDEVICE_INFO_V_1	1
58 
59 /* Interface Types */
60 
61 #define	IF_SCSI		0x0
62 #define	IF_FLOPPY	0x1
63 #define	IF_PCMCIA	0x2
64 #define	IF_BLOCK	0x3
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_BLOCK		0x20008	/* Generic block device */
90 #define	SM_NOT_PRESENT		0xFFFF
91 
92 
93 #define	MAX_PASSWD_LENGTH		32
94 
95 #define	PASSWD		0x1000
96 
97 #define	SM_WRITE_PROTECT_DISABLE	(PASSWD|0x0)
98 #define	SM_WRITE_PROTECT_NOPASSWD	(PASSWD|0x2)
99 #define	SM_WRITE_PROTECT_PASSWD		(PASSWD|0x4)
100 #define	SM_READ_WRITE_PROTECT		(PASSWD|0x8)
101 #define	SM_TEMP_UNLOCK_MODE		(PASSWD|0x10)
102 #define	SM_STATUS_UNKNOWN		(PASSWD|0xFF)
103 
104 #define	SM_UNPROTECTED			SM_WRITE_PROTECT_DISABLE
105 #define	SM_WRITE_PROTECTED 		SM_WRITE_PROTECT_NOPASSWD
106 #define	SM_WRITE_PROTECTED_WP   	SM_WRITE_PROTECT_PASSWD
107 #define	SM_READ_WRITE_PROTECTED 	SM_READ_WRITE_PROTECT
108 
109 
110 typedef struct smwp_state {
111 	uchar_t sm_version;
112 	int32_t	sm_new_state;
113 	int32_t	sm_passwd_len;
114 	char	sm_passwd[MAX_PASSWD_LENGTH];
115 }smwp_state_t;
116 
117 #define	SMWP_STATE_V_1			1
118 
119 #define	FORMAT	0x2000
120 
121 #define	SM_FORMAT_LONG		(FORMAT|0x0001)
122 #define	SM_FORMAT_QUICK		(FORMAT|0x0002)
123 #define	SM_FORMAT_FORCE		(FORMAT|0x0003)
124 
125 /* Floppy specific options */
126 #define	SM_FORMAT_HD	(FORMAT|0x0011) /* Format high density (1.44MB) */
127 #define	SM_FORMAT_DD	(FORMAT|0x0012) /* Format Double density (720KB) */
128 #define	SM_FORMAT_ED	(FORMAT|0x0013) /* Format Extended density (2.88MB) */
129 #define	SM_FORMAT_MD	(FORMAT|0x0014) /* Format Medium density (1.2MB) */
130 
131 #define	SM_FORMAT_IMMEDIATE	(FORMAT|0x0021)
132 #define	SM_FORMAT_BLOCKED	(FORMAT|0x0022)
133 
134 
135 /* New Library interface prototypes */
136 
137 int smedia_get_device_info(smedia_handle_t handle, smdevice_info_t *smdevinfop);
138 int smedia_free_device_info(smedia_handle_t handle,
139 		smdevice_info_t *smdevinfop);
140 int smedia_get_medium_property(smedia_handle_t handle,
141 		smmedium_prop_t *smpropp);
142 int smedia_get_protection_status(smedia_handle_t handle,
143 		smwp_state_t *wpstatep);
144 int smedia_set_protection_status(smedia_handle_t handle,
145 		smwp_state_t *wpstatep);
146 size_t smedia_raw_read(smedia_handle_t handle, diskaddr_t blockno,
147 		caddr_t buffer,
148 							size_t nbytes);
149 size_t smedia_raw_write(smedia_handle_t handle, diskaddr_t blockno,
150 		caddr_t buffer,
151 							size_t nbytes);
152 int smedia_format(smedia_handle_t handle, uint_t flavor, uint_t mode);
153 int smedia_check_format_status(smedia_handle_t handle);
154 int smedia_format_track(smedia_handle_t handle, uint_t trackno, uint_t head,
155 							uint_t density);
156 int smedia_eject(smedia_handle_t handle);
157 int smedia_reassign_block(smedia_handle_t handle, diskaddr_t blockno);
158 smedia_handle_t smedia_get_handle(int32_t);
159 int smedia_release_handle(smedia_handle_t handle);
160 int smedia_uscsi_cmd(smedia_handle_t handle, struct uscsi_cmd *cmd);
161 
162 
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 #endif /* _SMEDIA_H_ */
168