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.
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.
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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
37 #include <bsm/audit.h>
41 #define MAX_CDB_LEN 32
43 #define smedia_service "/var/run/smedia_svc"
44 #define DEFAULT_SMEDIAD_DEVDIR "/usr/lib/smedia"
46 #define INIT_NOT_DONE 0
48 #define INIT_IN_PROGRESS 2
50 /* SCSI FORMAT UNIT cdb[1] #defines */
54 /* Defect list header data[1] #defines */
65 #define DEFERRED_ERROR 0x71
68 #define MODE_SENSE_PARAM_HDR_LEN 4
69 #define MODE_PARAM_BLOCK_LEN 8
70 #define AWRE_OFFSET (MODE_SENSE_PARAM_HDR_LEN + MODE_PARAM_BLOCK_LEN + 2)
71 #define BLOCK_LEN_OFFSET (MODE_SENSE_PARAM_HDR_LEN + 5)
72 #define SKSV_FIELD 0x80
73 #define SKSV_OFFSET 15
74 #define FORMAT_PROGRESS_INDICATOR_OFFSET_0 16
75 #define FORMAT_PROGRESS_INDICATOR_OFFSET_1 17
77 /* #defines for protect medode field */
79 #define UNLOCK_MODE 0x0
80 #define WRITE_PROTECT_MODE 0x2
81 #define PASSWD_WRITE_PROTECT_MODE 0x3
82 #define READ_WRITE_PROTECT_MODE 0x5
83 #define TEMP_UNLOCK_MODE 0x8
85 /* #defines for CARTRIDGE STATUS PAGE */
87 #define CARTRIDGE_STATUS_PAGE 2
88 #define NON_SENSE_HDR_LEN 0x2
89 #define PROTECT_MODE_OFFSET 19
90 #define DISK_STATUS_OFFSET 1
93 /* error reporting mechanism */
94 void fatal(const char *, ...);
95 void info(const char *, ...);
96 void warning(const char *, ...);
97 void debug(uint_t
, const char *, ...);
98 void setlog(const char *);
100 void quit(const char *, ...);
101 void noise(const char *, ...);
103 typedef struct server_data
{
105 mutex_t sd_init_lock
;
112 SMEDIA_SUCCESS
= 0x0,
113 SMEDIA_FAILURE
/* general failure */
116 typedef struct door_data
{
117 mutex_t dd_lock
; /* lock to protect entire structure */
118 mutex_t dd_threadlock
; /* lock to protect dd_thread field */
119 sigset_t dd_newset
; /* signal set handled by the server */
120 cond_t dd_cv
; /* client_door_descriptor cv */
121 cond_t dd_cv_bind
; /* client door descriptor bind cv */
122 int32_t dd_id
; /* for future use. To store unique id */
123 door_desc_t dd_desc
[2]; /* [0] : Client Door descriptor */
124 /* [1] : Death Door decriptor */
125 thread_t dd_thread
; /* thread bound to the client door */
126 door_cred_t dd_cred
; /* credentials of client */
127 int32_t dd_fd
; /* device file descriptor */
128 void *dd_buf
; /* mmapped buffer of client */
129 int32_t dd_buf_len
; /* size of the mmapped buffer */
130 int32_t dd_buffd
; /* mmapped file descriptor */
131 int32_t dd_sector_size
; /* sector size of the device */
132 struct stat dd_stat
; /* stat of the dd_fd */
133 struct dk_cinfo dd_dkinfo
;
135 au_id_t audit_auid
; /* auid of user writing audit record */
136 uid_t audit_uid
; /* uid of user writing audit record */
137 uid_t audit_euid
; /* euid of user writing audit record */
138 gid_t audit_gid
; /* gid of user writing audit record */
139 gid_t audit_egid
; /* euid of user writing audit record */
140 pid_t audit_pid
; /* pid of user writing audit record */
141 au_tid_addr_t audit_tid
; /* tid of user writing audit record */
142 int audit_na
; /* 0 if event is attributable */
143 au_mask_t audit_namask
; /* not attributable flags */
144 au_event_t audit_event
; /* id of event being audited */
145 int audit_sorf
; /* success or failure of audit_event */
146 char *audit_user
; /* text version of audit_uid */
147 au_asid_t audit_asid
; /* asid of process writing record */
148 char *audit_path
; /* path token */
149 uint32_t audit_policy
; /* kernel audit policy */
150 struct auditpinfo_addr audit_ap
;
151 char audit_text
[128];
152 char audit_text1
[128];
155 /* Symbols to simplify access of door_data_t */
156 #define dd_cdoor dd_desc[0] /* Client Door descriptor */
157 #define dd_ddoor dd_desc[1] /* Death Door descriptor */
158 #define dd_cdoor_descriptor dd_cdoor.d_data.d_desc.d_descriptor
159 #define dd_ddoor_descriptor dd_ddoor.d_data.d_desc.d_descriptor
162 SMEDIA_CNUM_OPEN_FD
= 0x1,
163 SMEDIA_CNUM_GET_DEVICE_INFO
,
164 SMEDIA_CNUM_GET_MEDIUM_PROPERTY
,
165 SMEDIA_CNUM_GET_PROTECTION_STATUS
,
166 SMEDIA_CNUM_SET_PROTECTION_STATUS
,
167 SMEDIA_CNUM_RAW_READ
,
168 SMEDIA_CNUM_RAW_WRITE
,
170 SMEDIA_CNUM_CHECK_FORMAT_STATUS
,
172 SMEDIA_CNUM_REASSIGN_BLOCK
,
175 SMEDIA_CNUM_SET_SHFD
,
177 SMEDIA_CNUM_USCSI_CMD
178 } smedia_callnumber_t
;
181 smedia_callnumber_t cnum
; /* service call number */
182 char buf
[1]; /* buffer containing input arguments */
186 smedia_callnumber_t cnum
; /* service call number */
187 char buf
[1]; /* buffer containing the results */
190 typedef struct smedia_reqping
{
191 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_PING */
194 typedef struct smedia_retping
{
195 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_PING */
201 typedef struct smedia_reqopen
{
202 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_OPEN */
207 typedef struct smedia_retopen
{
208 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_OPEN */
211 typedef struct smedia_requscsi_cmd
{
212 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_USCSI_CMD */
215 char uscsi_cdb
[MAX_CDB_LEN
];
216 int32_t uscsi_buflen
;
217 uchar_t uscsi_cdblen
;
219 } smedia_requscsi_cmd_t
;
221 typedef struct smedia_retuscsi_cmd
{
222 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_USCSI_CMD */
223 int32_t uscsi_retval
;
227 uchar_t uscsi_rqstatus
;
228 uchar_t uscsi_rqresid
;
229 char uscsi_rqbuf
[MAX_RQ_LEN
];
230 } smedia_retuscsi_cmd_t
;
232 typedef struct smedia_reqget_device_info
{
233 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_GET_DEVICE_INFO */
234 } smedia_reqget_device_info_t
;
236 typedef struct smedia_reqset_shfd
{
237 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_SET_SHFD */
239 } smedia_reqset_shfd_t
;
241 typedef struct smedia_retget_device_info
{
242 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_GET_DEVICE_INFO */
243 smdevice_info_t smdevinfo
;
245 int32_t sm_interface_type
;
246 char sm_vendor_name
[32];
247 char sm_product_name
[32];
248 char sm_firmware_version
[32];
249 } smedia_retget_device_info_t
;
251 typedef struct smedia_reqget_medium_property
{
252 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_GET_MEDIUM_PROPERTY */
253 } smedia_reqget_medium_property_t
;
255 typedef struct smedia_retget_medium_property
{
256 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_GET_MEDIUM_PROPERTY */
257 smmedium_prop_t smprop
;
258 } smedia_retget_medium_property_t
;
260 typedef struct smedia_reqget_protection_status
{
261 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_GET_PROTECTION_STATUS */
262 } smedia_reqget_protection_status_t
;
264 typedef struct smedia_retget_protection_status
{
265 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_GET_PROTECTION_STATUS */
266 smwp_state_t prot_state
;
267 } smedia_retget_protection_status_t
;
269 typedef struct smedia_reqset_protection_status
{
270 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_SET_PROTECTION_STATUS */
271 smwp_state_t prot_state
;
272 } smedia_reqset_protection_status_t
;
274 typedef struct smedia_retset_protection_status
{
275 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_SET_PROTECTION_STATUS */
276 } smedia_retset_protection_status_t
;
278 typedef struct smedia_reqraw_read
{
279 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_RAW_READ */
282 } smedia_reqraw_read_t
;
284 typedef struct smedia_retraw_read
{
285 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_RAW_READ */
286 int32_t nbytes
; /* bytes read */
287 char buf
[1]; /* buffer size is nbytes long */
288 } smedia_retraw_read_t
;
290 typedef struct smedia_reqraw_write
{
291 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_RAW_WRITE */
294 char buf
[1]; /* buffer size is nbytes long */
295 } smedia_reqraw_write_t
;
297 typedef struct smedia_retraw_write
{
298 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_RAW_WRITE */
299 int32_t nbytes
; /* bytes written */
300 } smedia_retraw_write_t
;
302 typedef struct smedia_reqformat
{
303 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_FORMAT */
306 } smedia_reqformat_t
;
308 typedef struct smedia_retformat
{
309 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_FORMAT */
310 } smedia_retformat_t
;
312 typedef struct smedia_reqcheck_format_status
{
313 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_CHECK_FORMAT_STATUS */
314 } smedia_reqcheck_format_status_t
;
316 typedef struct smedia_retcheck_format_status
{
317 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_CHECK_FORMAT_STATUS */
318 int percent_complete
;
319 } smedia_retcheck_format_status_t
;
321 typedef struct smedia_reqreassign_block
{
322 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_REASSIGN_BLOCK */
324 } smedia_reqreassign_block_t
;
326 typedef struct smedia_retreassign_block
{
327 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_REASSIGN_BLOCK */
328 } smedia_retreassign_block_t
;
331 smedia_callnumber_t cnum
; /* SMEDIA_CNUM_ERROR */
332 smedia_callnumber_t in_cnum
; /* requested service number */
333 smedia_errno_t errnum
;
337 smedia_req_t in
; /* req arguments */
338 smedia_ret_t out
; /* out results */
339 smedia_reqping_t reqping
;
340 smedia_retping_t retping
;
341 smedia_reqopen_t reqopen
;
342 smedia_retopen_t retopen
;
343 smedia_reqget_device_info_t reqget_device_info
;
344 smedia_retget_device_info_t retget_device_info
;
345 smedia_reqget_medium_property_t reqget_medium_property
;
346 smedia_retget_medium_property_t retget_medium_property
;
347 smedia_reqget_protection_status_t reqget_protection_status
;
348 smedia_retget_protection_status_t retget_protection_status
;
349 smedia_reqset_protection_status_t reqset_protection_status
;
350 smedia_retset_protection_status_t retset_protection_status
;
351 smedia_reqraw_read_t reqraw_read
;
352 smedia_retraw_read_t retraw_read
;
353 smedia_reqraw_write_t reqraw_write
;
354 smedia_retraw_write_t retraw_write
;
355 smedia_reqformat_t reqformat
;
356 smedia_retformat_t retformat
;
357 smedia_reqcheck_format_status_t reqcheck_format_status
;
358 smedia_retcheck_format_status_t retcheck_format_status
;
359 smedia_reqreassign_block_t reqreassign_block
;
360 smedia_retreassign_block_t retreassign_block
;
361 smedia_reterror_t reterror
;
362 smedia_reqset_shfd_t reqset_shfd
;
363 smedia_requscsi_cmd_t requscsi_cmd
;
364 smedia_retuscsi_cmd_t retuscsi_cmd
;
367 #define SCSI_GENERIC 1
368 #define SCSI_IOMEGA 2
369 #define SCSI_FLOPPY 3
372 * Crude algorithm for calculating format timeout.
373 * 30min + 5min/100MB =>
374 * 35min for 100MB ZIP
375 * 42.5 min for 250MB ZIP
376 * 127 min for 2GB Jaz
377 * It is OK for now as this is just an upper limit by which the
378 * format should complete.
381 #define FORMAT_TIMEOUT(n) (1800 + ((n)/682))
383 #define WA_BIT 0x10 /* The word align bit for ATAPI devices */
385 * Non sense data length for catridge status page.
386 * Should be 63, but IDE driver panics with a non-aligned
393 * Vendor specific commands from Iomega
396 #define IOMEGA_NONSENSE_CMD 0x6
397 #define IOMEGA_CATRIDGE_PROTECT 0xC
403 #endif /* _SMSERVER_H_ */