1 /*
2  * Copyright (c) 2000,2001
3  *	Traakan, Inc., Los Altos, CA
4  *	All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * Project:  NDMJOB
31  * Ident:    $Id: $
32  *
33  * Description:
34  *	NDMPv9, represented here, is a ficticious version
35  *	used internally and never over-the-wire. This
36  *	isolates higher-level routines from variations
37  *	between NDMP protocol version. At this time,
38  *	NDMPv2, NDMPv3 and NDMPv4 are deployed. NDMPv9 tends
39  *	to be bits and pieces of all supported protocol versions
40  *	mashed together.
41  *
42  *	While we want the higher-level routines	isolated,
43  *	for clarity we still want them to use data structures
44  *	and construct that resemble NDMP. Higher-level routines
45  *	manipulate NDMPv9 data structures. Mid-level routines
46  *	translate between NDMPv9 and the over-the-wire version
47  *	in use. Low-level routines do the over-the-wire functions.
48  *
49  *	The approach of using the latest version internally
50  *	and retrofiting earlier versions was rejected for
51  *	two reasons. First, it means a tear-up of higher-level
52  *	functions as new versions are deployed. Second,
53  *	it makes building with selected version impossible.
54  *	No matter what approach is taken, there will be
55  *	some sort of retrofit between versions. NDMPv9
56  *	is simply the internal version, and all bona-fide
57  *	versions are retrofitted. v9 was chosen because
58  *	it is unlikely the NDMP version will reach 9
59  *	within the useful life of the NDMP architecture.
60  *
61  *	NDMPv9 could be implemented in a hand-crafted header (.h)
62  *	file, yet we continue to use the ONC RPC (.x) description
63  *	for convenvience. It's easy to cut-n-paste from the other
64  *	NDMP.x files. It's important that ndmp9_xdr.c never be
65  *	generated nor compiled.
66  */
67 
68 
69 /*
70  * (from ndmp3.x)
71  * ndmp.x
72  *
73  * Description	 : NDMP protocol rpcgen file.
74  *
75  * Copyright (c) 1999 Intelliguard Software, Network Appliance.
76  * All Rights Reserved.
77  */
78 
79 /*
80  * (from ndmp2.x)
81  * Copyright (c) 1997 Network Appliance. All Rights Reserved.
82  *
83  * Network Appliance makes no representations concerning either
84  * the merchantability of this software or the suitability of this
85  * software for any particular purpose. It is provided "as is"
86  * without express or implied warranty of any kind.
87  *
88  * These notices must be retained in any copies of any part of this
89  * documentation and/or software.
90  */
91 
92 %#if __clang__
93 %#pragma clang diagnostic ignored "-Wunused-const-variable"
94 %#elif __GNUC__
95 %#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
96 %#pragma GCC diagnostic ignored "-Wunused-variable"
97 %#endif
98 %#endif
99 
100 const NDMP9VER = 9;
101 
102 
103 /*
104  * General types
105  ****************************************************************
106  */
107 
108 /*
109  * Error codes
110  */
111 enum ndmp9_error {
112 	NDMP9_NO_ERR,			/* No error */
113 	NDMP9_NOT_SUPPORTED_ERR,	/* Call is not supported */
114 	NDMP9_DEVICE_BUSY_ERR,		/* The device is in use */
115 	NDMP9_DEVICE_OPENED_ERR,	/* Another tape or scsi device
116 					 * is already open */
117 	NDMP9_NOT_AUTHORIZED_ERR,	/* connection has not been authorized*/
118 	NDMP9_PERMISSION_ERR,		/* some sort of permission problem */
119 	NDMP9_DEV_NOT_OPEN_ERR,		/* SCSI device is not open */
120 	NDMP9_IO_ERR,			/* I/O error */
121 	NDMP9_TIMEOUT_ERR,		/* command timed out */
122 	NDMP9_ILLEGAL_ARGS_ERR,		/* illegal arguments in request */
123 	NDMP9_NO_TAPE_LOADED_ERR,	/* Cannot open because there is
124 					   no tape loaded */
125 	NDMP9_WRITE_PROTECT_ERR,	/* tape cannot be open for write */
126 	NDMP9_EOF_ERR,			/* Command encountered EOF */
127 	NDMP9_EOM_ERR,			/* Command encountered EOM */
128 	NDMP9_FILE_NOT_FOUND_ERR,	/* File not found during recover */
129 	NDMP9_BAD_FILE_ERR,		/* The file descriptor is invalid */
130 	NDMP9_NO_DEVICE_ERR,		/* The device is not at that target */
131 	NDMP9_NO_BUS_ERR,		/* Invalid controller */
132 	NDMP9_XDR_DECODE_ERR,		/* Can't decode the request argument */
133 	NDMP9_ILLEGAL_STATE_ERR,	/* Call can't be done at this state */
134 	NDMP9_UNDEFINED_ERR,		/* Undefined Error */
135 	NDMP9_XDR_ENCODE_ERR,		/* Can't encode the reply argument */
136 	NDMP9_NO_MEM_ERR,		/* no memory */
137 	NDMP9_CONNECT_ERR,		/* Error connecting to another
138 					 * NDMP server */
139 	NDMP9_SEQUENCE_NUM_ERR,
140 	NDMP9_READ_IN_PROGRESS_ERR	= 25,
141 	NDMP9_PRECONDITION_ERR		= 26,
142 	NDMP9_CLASS_NOT_SUPPORTED	= 27,
143 	NDMP9_VERSION_NOT_SUPPORTED	= 28,
144 	NDMP9_EXT_DUPL_CLASSES		= 29,
145 	NDMP9_EXT_DN_ILLEGAL		= 30
146 };
147 
148 
149 /*
150  * Message codes
151  */
152 enum ndmp9_message {
153 	NDMP9_CONNECT_OPEN = 0x900,	/* CONNECT INTERFACE */
154 	NDMP9_CONNECT_CLIENT_AUTH = 0x901,
155 	NDMP9_CONNECT_CLOSE = 0x902,
156 	NDMP9_CONNECT_SERVER_AUTH = 0x903,
157 
158 	NDMP9_CONFIG_GET_HOST_INFO = 0x100, /* CONFIG INTERFACE */
159 	NDMP9_CONFIG_GET_CONNECTION_TYPE = 0x102, /* NDMP2_CONFIG_GET_MOVER_TYPE on v2*/
160 	NDMP9_CONFIG_GET_AUTH_ATTR = 0x103,
161 	NDMP9_CONFIG_GET_BUTYPE_INFO = 0x104,	/* NDMPv3 and forward */
162 	NDMP9_CONFIG_GET_FS_INFO = 0x105,	/* NDMPv3 and forward */
163 	NDMP9_CONFIG_GET_TAPE_INFO = 0x106,	/* NDMPv3 and forward */
164 	NDMP9_CONFIG_GET_SCSI_INFO = 0x107,	/* NDMPv3 and forward */
165 	NDMP9_CONFIG_GET_SERVER_INFO =0x108,	/* NDMPv3 and forward */
166 
167 	NDMP9_SCSI_OPEN = 0x200,	/* SCSI INTERFACE */
168 	NDMP9_SCSI_CLOSE = 0x201,
169 	NDMP9_SCSI_GET_STATE = 0x202,
170 	NDMP9_SCSI_SET_TARGET = 0x203,
171 	NDMP9_SCSI_RESET_DEVICE = 0x204,
172 	NDMP9_SCSI_RESET_BUS = 0x205,
173 	NDMP9_SCSI_EXECUTE_CDB = 0x206,
174 
175 	NDMP9_TAPE_OPEN = 0x300,	/* TAPE INTERFACE */
176 	NDMP9_TAPE_CLOSE = 0x301,
177 	NDMP9_TAPE_GET_STATE = 0x302,
178 	NDMP9_TAPE_MTIO = 0x303,
179 	NDMP9_TAPE_WRITE = 0x304,
180 	NDMP9_TAPE_READ = 0x305,
181 	NDMP9_TAPE_EXECUTE_CDB = 0x307,
182 
183 	NDMP9_DATA_GET_STATE = 0x400,	/* DATA INTERFACE */
184 	NDMP9_DATA_START_BACKUP = 0x401,
185 	NDMP9_DATA_START_RECOVER = 0x402,
186 	NDMP9_DATA_ABORT = 0x403,
187 	NDMP9_DATA_GET_ENV = 0x404,
188 	NDMP9_DATA_STOP = 0x407,
189 	NDMP9_DATA_LISTEN = 0x409,
190 	NDMP9_DATA_CONNECT = 0x40a,
191 	NDMP9_DATA_START_RECOVER_FILEHIST = 0x40b,
192 
193 	NDMP9_NOTIFY_DATA_HALTED =0x501,/* NOTIFY INTERFACE */
194 	NDMP9_NOTIFY_CONNECTED = 0x502,
195 	NDMP9_NOTIFY_MOVER_HALTED = 0x503,
196 	NDMP9_NOTIFY_MOVER_PAUSED = 0x504,
197 	NDMP9_NOTIFY_DATA_READ =0x505,
198 
199 	NDMP9_LOG_FILE = 0x602,		/* LOGGING INTERFACE */
200 	NDMP9_LOG_MESSAGE = 0x603,
201 
202 	NDMP9_FH_ADD_FILE = 0x703,	/* FILE HISTORY INTERFACE */
203 	NDMP9_FH_ADD_DIR = 0x704,
204 	NDMP9_FH_ADD_NODE = 0x705,
205 
206 	NDMP9_MOVER_GET_STATE = 0xa00,	/* MOVER INTERFACE */
207 	NDMP9_MOVER_LISTEN = 0xa01,
208 	NDMP9_MOVER_CONTINUE = 0xa02,
209 	NDMP9_MOVER_ABORT = 0xa03,
210 	NDMP9_MOVER_STOP = 0xa04,
211 	NDMP9_MOVER_SET_WINDOW = 0xa05,
212 	NDMP9_MOVER_READ = 0xa06,
213 	NDMP9_MOVER_CLOSE =0xa07,
214 	NDMP9_MOVER_SET_RECORD_SIZE =0xa08,
215 	NDMP9_MOVER_CONNECT =0xa09
216 };
217 
218 
219 /*
220  * Common message bodies
221  */
222 %extern bool_t xdr_ndmp9_no_arguments();
223 %#define ndmp9_no_arguments int
224 
225 struct ndmp9_just_error_reply {
226 	ndmp9_error	error;
227 };
228 
229 
230 /*
231  * 64-bit integers
232  */
233 %#define ndmp9_u_quad uint64_t
234 %extern bool_t xdr_ndmp9_u_quad(register XDR *xdrs, ndmp9_u_quad *objp);
235 
236 /*
237  * Valid values. Sometimes we have values, and sometimes we don't.
238  */
239 enum ndmp9_validity {
240 	NDMP9_VALIDITY_INVALID = 0,
241 	NDMP9_VALIDITY_VALID,
242 	NDMP9_VALIDITY_MAYBE_INVALID,
243 	NDMP9_VALIDITY_MAYBE_VALID
244 };
245 
246 %#define NDMP9_INVALID_U_LONG	0xFFFFFFFFul
247 struct ndmp9_valid_u_long {
248 	ndmp9_validity	valid;
249 	uint32_t	value;
250 };
251 
252 %#define NDMP9_INVALID_U_QUAD	0xFFFFFFFFFFFFFFFFull
253 struct ndmp9_valid_u_quad {
254 	ndmp9_validity	valid;
255 	ndmp9_u_quad	value;
256 };
257 
258 
259 /*
260  * Property values. A simple name/value pair. Used in lots of places.
261  */
262 struct ndmp9_pval {
263 	string		name<>;
264 	string		value<>;
265 };
266 
267 
268 /*
269  * Authorization data. Three authorization types each
270  * with their particular values. Authorization is done
271  * in three steps:
272  *	1) Client determines which types of authorization are available
273  *	   on the server.
274  *	2) Client may get parameters (challenge) from server.
275  *	3) Client requests authorization based on a shared
276  *	   secret (password) with parameters (challenge) applied.
277  */
278 enum ndmp9_auth_type {
279 	NDMP9_AUTH_NONE,		/* no password is required */
280 	NDMP9_AUTH_TEXT,		/* the clear text password */
281 	NDMP9_AUTH_MD5			/* md5 */
282 };
283 
284 union ndmp9_auth_attr switch (enum ndmp9_auth_type auth_type) {
285 	case NDMP9_AUTH_NONE:
286 		void;
287 	case NDMP9_AUTH_TEXT:
288 		void;
289 	case NDMP9_AUTH_MD5:
290 		opaque	challenge[64];
291 };
292 
293 struct ndmp9_auth_text {
294 	string		auth_id<>;	/* account/user name */
295 	string		auth_password<>; /* clear-text password */
296 };
297 
298 struct ndmp9_auth_md5 {
299 	string		auth_id<>;	/* account/user name */
300 	opaque		auth_digest[16]; /* MD5 "hashed" password */
301 };
302 
303 union ndmp9_auth_data switch (enum ndmp9_auth_type auth_type) {
304 	case NDMP9_AUTH_NONE:
305 		void;
306 	case NDMP9_AUTH_TEXT:
307 		struct ndmp9_auth_text	auth_text;
308 	case NDMP9_AUTH_MD5:
309 		struct ndmp9_auth_md5	auth_md5;
310 };
311 
312 
313 /*
314  * The data connection (data stream, image stream, big ol' pipe)
315  * has two endpoints, Once side instigates the connection (connects),
316  * the other side receives the connection (listen/accept).
317  * Appears in DATA and MOVER interfaces.
318  */
319 enum ndmp9_addr_type {
320 	NDMP9_ADDR_LOCAL,
321 	NDMP9_ADDR_TCP,
322 	/* IPC and FC addr types contemplated but never deployed */
323 	NDMP9_ADDR_AS_CONNECTED = 0x1000
324 };
325 
326 struct ndmp9_tcp_addr {
327 	uint32_t	ip_addr;
328 	uint16_t	port;
329 };
330 
331 union ndmp9_addr switch (ndmp9_addr_type addr_type) {
332 	case NDMP9_ADDR_LOCAL:
333 	case NDMP9_ADDR_AS_CONNECTED:
334 		void;
335 	case NDMP9_ADDR_TCP:
336 		ndmp9_tcp_addr	tcp_addr;
337 };
338 
339 
340 
341 
342 /*
343  * CONNECT INTERFACE
344  ****************************************************************
345  *
346  * The CONNECT INTERFACE is used to condition and authorize
347  * the control connection from the CONTROL Agent (DMA, Client)
348  * to the DATA, TAPE, or SCSI Agent (DSP, Servers).
349  *
350  * Most of this is addressed by NDMP0 (zero), which is a companion
351  * ficticious version. The NDMP0 features must never change to
352  * support protocol version negotiation. Once the version is
353  * negotiated, subsequent negotiations and authorization can
354  * take place.
355  */
356 
357 /* NDMP9_CONNECT_OPEN -- must never change, negotiate protocol version */
358 struct ndmp9_connect_open_request {
359 	uint16_t	protocol_version;	/* the version of protocol supported */
360 };
361 typedef ndmp9_just_error_reply	ndmp9_connect_open_reply;
362 
363 /* NDMP9_CONNECT_CLIENT_AUTH -- authorize client */
364 struct ndmp9_connect_client_auth_request {
365 	ndmp9_auth_data	auth_data;
366 };
367 typedef ndmp9_just_error_reply	ndmp9_connect_client_auth_reply;
368 
369 
370 /* NDMP9_CONNECT_CLOSE -- must never change, terminate control connection */
371 typedef ndmp9_no_arguments	ndmp9_connect_close_request;
372 typedef ndmp9_no_arguments	ndmp9_connect_close_reply;
373 
374 /* NDMP9_CONNECT_SERVER_AUTH -- once client is authorized, ask server to
375  * prove itself -- nobody is using this */
376 struct ndmp9_connect_server_auth_request {
377 	ndmp9_auth_attr		client_attr;
378 };
379 
380 struct ndmp9_connect_server_auth_reply {
381 	ndmp9_error		error;
382 	ndmp9_auth_data		server_result;
383 };
384 
385 
386 /*
387  * CONFIG INTERFACE
388  ****************************************************************
389  *
390  * The CONFIG interfaces allow the CONTROL Agent (DMA, client) to
391  * obtain resource and other information from the DATA/TAPE/SCSI
392  * Agent (DSP, server).
393  *
394  * For NDMPv9, the whole show is lumped into a single data structure.
395  * The specific CONFIG interfaces, which vary between versions,
396  * pick-n-choose the info needed.
397  */
398 
399 struct ndmp9_butype_info {
400 	string			butype_name<>;
401 	ndmp9_valid_u_long	v2attr;
402 	ndmp9_valid_u_long	v3attr;
403 	ndmp9_valid_u_long	v4attr;
404 	ndmp9_pval		default_env<>;
405 };
406 
407 struct ndmp9_fs_info {
408 	string			fs_type<>;
409 	string			fs_logical_device<>;
410 	string			fs_physical_device<>;
411 	ndmp9_valid_u_quad	total_size;
412 	ndmp9_valid_u_quad	used_size;
413 	ndmp9_valid_u_quad	avail_size;
414 	ndmp9_valid_u_quad	total_inodes;
415 	ndmp9_valid_u_quad	used_inodes;
416 	ndmp9_pval		fs_env<>;
417 	string			fs_status<>;
418 };
419 
420 struct ndmp9_device_capability {
421 	string			device<>;
422 	ndmp9_valid_u_long	v3attr;
423 	ndmp9_valid_u_long	v4attr;
424 	ndmp9_pval		capability<>;
425 };
426 
427 struct ndmp9_device_info {
428 	string			model<>;
429 	ndmp9_device_capability	caplist<>;
430 };
431 
432 const NDMP9_CONFIG_CONNTYPE_LOCAL	= 0x0001;
433 const NDMP9_CONFIG_CONNTYPE_TCP		= 0x0002;
434 
435 const NDMP9_CONFIG_AUTHTYPE_NONE	= 0x0001;
436 const NDMP9_CONFIG_AUTHTYPE_TEXT	= 0x0002;
437 const NDMP9_CONFIG_AUTHTYPE_MD5		= 0x0004;
438 
439 struct ndmp9_config_info {
440 	ndmp9_error		error;
441 
442 	/* ndmp[23]_config_get_host_info_reply */
443 	string			hostname<>; /* host name */
444 	string			os_type<>;  /* The O/S type (e.g. SOLARIS) */
445 	string			os_vers<>;  /* The O/S version (e.g. 2.5) */
446 	string			hostid<>;
447 
448 	/* ndmp[34]_config_get_server_info_reply */
449 	string			vendor_name<>;
450 	string			product_name<>;
451 	string			revision_number<>;
452 
453 	/* ndmp2_config_get_host_info */
454 	/* ndmp[34]_config_get_server_info */
455 	uint32_t		authtypes;
456 
457 	/* ndmp2_config_get_mover_type */
458 	/* ndmp[34]_config_get_connection_type */
459 	uint32_t		conntypes;
460 
461 	/* ndmp2_config_get_butype_attr */
462 	/* ndmp[34]_config_get_butype_info */
463 	ndmp9_butype_info	butype_info<>;
464 
465 	/* ndmp[34]_config_get_fs_info */
466 	ndmp9_fs_info		fs_info<>;
467 
468 	/* ndmp[34]_config_get_tape_info */
469 	ndmp9_device_info	tape_info<>;
470 
471 	/* ndmp[34]_config_get_scsi_info */
472 	ndmp9_device_info	scsi_info<>;
473 };
474 
475 /* NDMP9_CONFIG_GET_INFO */
476 typedef ndmp9_no_arguments	ndmp9_config_get_info_request;
477 struct ndmp9_config_get_info_reply {
478 	ndmp9_error		error;
479 	ndmp9_config_info	config_info;
480 };
481 
482 /* NDMP9_CONFIG_GET_HOST_INFO */
483 typedef ndmp9_no_arguments	ndmp9_config_get_host_info_request;
484 typedef ndmp9_config_get_info_reply ndmp9_config_get_host_info_reply;
485 
486 /* NDMP9_CONFIG_GET_CONNECTION_TYPE */
487 typedef ndmp9_no_arguments	ndmp9_config_get_connection_type_request;
488 typedef ndmp9_config_get_info_reply ndmp9_config_get_connection_type_reply;
489 
490 /* NDMP9_CONFIG_GET_SERVER_INFO */
491 typedef ndmp9_no_arguments	ndmp9_config_get_server_info_request;
492 typedef ndmp9_config_get_info_reply ndmp9_config_get_server_info_reply;
493 
494 /* NDMP9_CONFIG_GET_BUTYPE_INFO */
495 typedef ndmp9_no_arguments	ndmp9_config_get_butype_info_request;
496 typedef ndmp9_config_get_info_reply ndmp9_config_get_butype_info_reply;
497 
498 /* NDMP9_CONFIG_GET_FS_INFO */
499 typedef ndmp9_no_arguments	ndmp9_config_get_fs_info_request;
500 typedef ndmp9_config_get_info_reply ndmp9_config_get_fs_info_reply;
501 
502 /* NDMP9_CONFIG_GET_TAPE_INFO */
503 typedef ndmp9_no_arguments	ndmp9_config_get_tape_info_request;
504 typedef ndmp9_config_get_info_reply ndmp9_config_get_tape_info_reply;
505 
506 /* NDMP9_CONFIG_GET_SCSI_INFO */
507 typedef ndmp9_no_arguments	ndmp9_config_get_scsi_info_request;
508 typedef ndmp9_config_get_info_reply ndmp9_config_get_scsi_info_reply;
509 
510 
511 /* NDMP9_CONFIG_GET_AUTH_ATTR */
512 struct ndmp9_config_get_auth_attr_request {
513 	ndmp9_auth_type		auth_type;
514 };
515 
516 struct ndmp9_config_get_auth_attr_reply {
517 	ndmp9_error		error;
518 	ndmp9_auth_attr		server_attr;
519 };
520 
521 
522 
523 /*
524  * SCSI INTERFACE
525  ****************************************************************
526  *
527  * A SCSI pass-thru service. The CONTROL Agent (DMA, Client)
528  * manipulates a SCSI Media Changer through this interface.
529  * It may be used for other purposes.
530  */
531 
532 /* NDMP9_SCSI_OPEN */
533 struct ndmp9_scsi_open_request {
534 	string		device<>;
535 };
536 typedef ndmp9_just_error_reply	ndmp9_scsi_open_reply;
537 
538 /* NDMP9_SCSI_CLOSE */
539 typedef ndmp9_no_arguments	ndmp9_scsi_close_request;
540 typedef ndmp9_just_error_reply	ndmp9_scsi_close_reply;
541 
542 /* NDMP9_SCSI_GET_STATE */
543 typedef ndmp9_no_arguments	ndmp9_scsi_get_state_request;
544 struct ndmp9_scsi_get_state_reply {
545 	ndmp9_error	error;
546 	short		target_controller;
547 	short		target_id;
548 	short		target_lun;
549 };
550 
551 /* NDMP9_SCSI_SET_TARGET -- deleted for NDMPv4 */
552 struct ndmp9_scsi_set_target_request {
553 	string		device<>;
554 	uint16_t	target_controller;
555 	uint16_t	target_id;
556 	uint16_t	target_lun;
557 };
558 typedef ndmp9_just_error_reply	ndmp9_scsi_set_target_reply;
559 
560 
561 /* NDMP9_SCSI_RESET_DEVICE */
562 typedef ndmp9_no_arguments	ndmp9_scsi_reset_device_request;
563 typedef ndmp9_just_error_reply	ndmp9_scsi_reset_device_reply;
564 
565 /* NDMP9_SCSI_RESET_BUS -- deleted for NDMPv4 */
566 typedef ndmp9_no_arguments	ndmp9_scsi_reset_bus_request;
567 typedef ndmp9_just_error_reply	ndmp9_scsi_reset_bus_reply;
568 
569 
570 /* NDMP9_SCSI_EXECUTE_CDB */
571 enum ndmp9_scsi_data_dir {
572 	NDMP9_SCSI_DATA_DIR_NONE = 0,
573 	NDMP9_SCSI_DATA_DIR_IN = 1,	/* Expect data from SCSI device */
574 	NDMP9_SCSI_DATA_DIR_OUT = 2	/* Transfer data to SCSI device */
575 };
576 
577 struct ndmp9_execute_cdb_request {
578 	ndmp9_scsi_data_dir	data_dir;
579 	uint32_t		timeout;
580 	uint32_t		datain_len;	/* Set for expected datain */
581 	opaque			cdb<>;
582 	opaque			dataout<>;
583 };
584 
585 struct ndmp9_execute_cdb_reply {
586 	ndmp9_error	error;
587 	u_char		status;		/* SCSI status bytes */
588 	uint32_t	dataout_len;
589 	opaque		datain<>;	/* SCSI datain */
590 	opaque		ext_sense<>;	/* Extended sense data */
591 };
592 
593 typedef ndmp9_execute_cdb_request	ndmp9_scsi_execute_cdb_request;
594 typedef ndmp9_execute_cdb_reply		ndmp9_scsi_execute_cdb_reply;
595 
596 
597 
598 /******************/
599 /* TAPE INTERFACE */
600 /******************/
601 /* NDMP9_TAPE_OPEN */
602 enum ndmp9_tape_open_mode {
603 	NDMP9_TAPE_READ_MODE,
604 	NDMP9_TAPE_RDWR_MODE,
605 	NDMP9_TAPE_RAW_MODE		/* new for NDMPv4 */
606 };
607 
608 enum ndmp9_tape_state {
609 	NDMP9_TAPE_STATE_IDLE,		/* not doing anything */
610 	NDMP9_TAPE_STATE_OPEN,		/* open, tape operations OK */
611 	NDMP9_TAPE_STATE_MOVER		/* mover active, tape ops locked out */
612 					/* ie read, write, mtio, close, cdb */
613 };
614 
615 struct ndmp9_tape_open_request {
616 	string			device<>;
617 	ndmp9_tape_open_mode	mode;
618 };
619 typedef ndmp9_just_error_reply	ndmp9_tape_open_reply;
620 
621 /* NDMP9_TAPE_CLOSE */
622 typedef ndmp9_no_arguments	ndmp9_tape_close_request;
623 typedef ndmp9_just_error_reply	ndmp9_tape_close_reply;
624 
625 
626 /* NDMP9_TAPE_GET_STATE */
627 const NDMP9_TAPE_STATE_NOREWIND	= 0x0008;	/* non-rewind device */
628 const NDMP9_TAPE_STATE_WR_PROT	= 0x0010;	/* write-protected */
629 const NDMP9_TAPE_STATE_ERROR	= 0x0020;	/* media error */
630 const NDMP9_TAPE_STATE_UNLOAD	= 0x0040;	/* tape will be unloaded when
631 						 * the device is closed */
632 
633 typedef ndmp9_no_arguments	ndmp9_tape_get_state_request;
634 struct ndmp9_tape_get_state_reply {
635 	ndmp9_error		error;
636 	uint32_t		flags;		/* compatible NDMP[2349] */
637 	ndmp9_tape_state	state;
638 	ndmp9_tape_open_mode 	open_mode;
639 	ndmp9_valid_u_long	file_num;
640 	ndmp9_valid_u_long	soft_errors;
641 	ndmp9_valid_u_long	block_size;
642 	ndmp9_valid_u_long	blockno;
643 	ndmp9_valid_u_quad	total_space;
644 	ndmp9_valid_u_quad	space_remain;
645 	ndmp9_valid_u_long	partition;
646 };
647 
648 /* NDMP9_TAPE_MTIO */
649 enum ndmp9_tape_mtio_op {
650 	NDMP9_MTIO_FSF,
651 	NDMP9_MTIO_BSF,
652 	NDMP9_MTIO_FSR,
653 	NDMP9_MTIO_BSR,
654 	NDMP9_MTIO_REW,
655 	NDMP9_MTIO_EOF,
656 	NDMP9_MTIO_OFF
657 };
658 
659 struct ndmp9_tape_mtio_request {
660 	ndmp9_tape_mtio_op	tape_op;
661 	uint32_t		count;
662 };
663 
664 struct ndmp9_tape_mtio_reply {
665 	ndmp9_error	error;
666 	uint32_t	resid_count;
667 };
668 
669 
670 /* NDMP9_TAPE_WRITE */
671 struct ndmp9_tape_write_request {
672 	opaque		data_out<>;
673 };
674 
675 struct ndmp9_tape_write_reply {
676 	ndmp9_error	error;
677 	uint32_t	count;
678 };
679 
680 
681 /* NDMP9_TAPE_READ */
682 struct ndmp9_tape_read_request {
683 	uint32_t	count;
684 };
685 
686 struct ndmp9_tape_read_reply {
687 	ndmp9_error	error;
688 	opaque		data_in<>;
689 };
690 
691 /* NDMP9_TAPE_EXECUTE_CDB */
692 typedef ndmp9_execute_cdb_request	ndmp9_tape_execute_cdb_request;
693 typedef ndmp9_execute_cdb_reply		ndmp9_tape_execute_cdb_reply;
694 
695 
696 
697 
698 /********************************/
699 /* MOVER INTERFACE              */
700 /********************************/
701 enum ndmp9_mover_state {
702 	NDMP9_MOVER_STATE_IDLE,
703 	NDMP9_MOVER_STATE_LISTEN,
704 	NDMP9_MOVER_STATE_ACTIVE,
705 	NDMP9_MOVER_STATE_PAUSED,
706 	NDMP9_MOVER_STATE_HALTED,
707 	NDMP9_MOVER_STATE_STANDBY	/* awaiting mover_read_request */
708 };
709 
710 enum ndmp9_mover_mode {
711 	NDMP9_MOVER_MODE_READ,	/* read from data conn; write to tape */
712 	NDMP9_MOVER_MODE_WRITE	/* write to data conn; read from tape */
713 };
714 
715 enum ndmp9_mover_pause_reason {
716 	NDMP9_MOVER_PAUSE_NA,
717 	NDMP9_MOVER_PAUSE_EOM,
718 	NDMP9_MOVER_PAUSE_EOF,
719 	NDMP9_MOVER_PAUSE_SEEK,
720 	NDMP9_MOVER_PAUSE_MEDIA_ERROR,
721 	NDMP9_MOVER_PAUSE_EOW
722 };
723 
724 enum ndmp9_mover_halt_reason {
725 	NDMP9_MOVER_HALT_NA,
726 	NDMP9_MOVER_HALT_CONNECT_CLOSED,
727 	NDMP9_MOVER_HALT_ABORTED,
728 	NDMP9_MOVER_HALT_INTERNAL_ERROR,
729 	NDMP9_MOVER_HALT_CONNECT_ERROR,
730 	NDMP9_MOVER_HALT_MEDIA_ERROR
731 };
732 
733 /* NDMP9_MOVER_GET_STATE */
734 typedef ndmp9_no_arguments	ndmp9_mover_get_state_request;
735 struct ndmp9_mover_get_state_reply {
736 	ndmp9_error		error;
737 	ndmp9_mover_state	state;
738 	ndmp9_mover_mode	mode;
739 	ndmp9_mover_pause_reason pause_reason;
740 	ndmp9_mover_halt_reason	halt_reason;
741 	uint32_t		record_size;
742 	uint32_t		record_num;
743 	ndmp9_u_quad		bytes_moved;
744 	ndmp9_u_quad		seek_position;
745 	ndmp9_u_quad		bytes_left_to_read;
746 	ndmp9_u_quad		window_offset;
747 	ndmp9_u_quad		window_length;
748 	ndmp9_addr		data_connection_addr;
749 };
750 
751 /* NDMP9_MOVER_LISTEN */
752 struct ndmp9_mover_listen_request {
753 	ndmp9_mover_mode	mode;
754 	ndmp9_addr_type		addr_type;
755 };
756 
757 struct ndmp9_mover_listen_reply {
758 	ndmp9_error		error;
759 	ndmp9_addr		data_connection_addr;
760 };
761 
762 /* NDMP9_MOVER_CONNECT */
763 struct ndmp9_mover_connect_request {
764 	ndmp9_mover_mode	mode;
765 	ndmp9_addr		addr;
766 };
767 typedef ndmp9_just_error_reply	ndmp9_mover_connect_reply;
768 
769 /* NDMP9_MOVER_SET_RECORD_SIZE */
770 struct ndmp9_mover_set_record_size_request {
771 	uint32_t		record_size;
772 };
773 typedef ndmp9_just_error_reply	ndmp9_mover_set_record_size_reply;
774 
775 /* NDMP9_MOVER_SET_WINDOW */
776 struct ndmp9_mover_set_window_request {
777 	ndmp9_u_quad	offset;
778 	ndmp9_u_quad	length;
779 };
780 typedef ndmp9_just_error_reply	ndmp9_mover_set_window_reply;
781 
782 /* NDMP9_MOVER_CONTINUE */
783 typedef ndmp9_no_arguments	ndmp9_mover_continue_request;
784 typedef ndmp9_just_error_reply	ndmp9_mover_continue_reply;
785 
786 
787 /* NDMP9_MOVER_ABORT */
788 typedef ndmp9_no_arguments	ndmp9_mover_abort_request;
789 typedef ndmp9_just_error_reply	ndmp9_mover_abort_reply;
790 
791 /* NDMP9_MOVER_STOP */
792 typedef ndmp9_no_arguments	ndmp9_mover_stop_request;
793 typedef ndmp9_just_error_reply	ndmp9_mover_stop_reply;
794 
795 /* NDMP9_MOVER_READ */
796 struct ndmp9_mover_read_request {
797 	ndmp9_u_quad	offset;
798 	ndmp9_u_quad	length;
799 };
800 typedef ndmp9_just_error_reply	ndmp9_mover_read_reply;
801 
802 /* NDMP9_MOVER_CLOSE */
803 typedef ndmp9_no_arguments	ndmp9_mover_close_request;
804 typedef ndmp9_just_error_reply	ndmp9_mover_close_reply;
805 
806 
807 
808 
809 /****************************/
810 /* DATA INTERFACE	    */
811 /****************************/
812 
813 enum ndmp9_data_operation {
814 	NDMP9_DATA_OP_NOACTION,
815 	NDMP9_DATA_OP_BACKUP,
816 	NDMP9_DATA_OP_RECOVER,
817 	NDMP9_DATA_OP_RECOVER_FILEHIST
818 };
819 
820 enum ndmp9_data_state {
821 	NDMP9_DATA_STATE_IDLE,
822 	NDMP9_DATA_STATE_ACTIVE,
823 	NDMP9_DATA_STATE_HALTED,
824 	NDMP9_DATA_STATE_LISTEN,
825 	NDMP9_DATA_STATE_CONNECTED
826 };
827 
828 enum ndmp9_data_halt_reason {
829 	NDMP9_DATA_HALT_NA,
830 	NDMP9_DATA_HALT_SUCCESSFUL,
831 	NDMP9_DATA_HALT_ABORTED,
832 	NDMP9_DATA_HALT_INTERNAL_ERROR,
833 	NDMP9_DATA_HALT_CONNECT_ERROR
834 };
835 
836 /* NDMP9_DATA_START_BACKUP */
837 typedef ndmp9_no_arguments	ndmp9_data_get_state_request;
838 struct ndmp9_data_get_state_reply {
839 	ndmp9_error		error;
840 	ndmp9_data_operation	operation;
841 	ndmp9_data_state	state;
842 	ndmp9_data_halt_reason	halt_reason;
843 	ndmp9_u_quad		bytes_processed;
844 	ndmp9_valid_u_quad	est_bytes_remain;
845 	ndmp9_valid_u_long	est_time_remain;
846 	ndmp9_addr		data_connection_addr;
847 	ndmp9_u_quad		read_offset;
848 	ndmp9_u_quad		read_length;
849 };
850 
851 struct ndmp9_name {
852 	string			original_path<>; /* relative to backup root */
853 	string			destination_path<>;
854 	/* nt_destination_path<> */
855 	string			name<>;
856 	string			other_name<>;
857 	ndmp9_u_quad		node;
858 	ndmp9_valid_u_quad	fh_info;
859 };
860 
861 
862 
863 /* NDMP9_DATA_START_BACKUP */
864 struct ndmp9_data_start_backup_request {
865 	string		bu_type<>;	/* backup method to use */
866 	ndmp9_pval	env<>;		/* Parameters that may modify backup */
867 	ndmp9_addr	addr;
868 };
869 typedef ndmp9_just_error_reply	ndmp9_data_start_backup_reply;
870 
871 /* NDMP9_DATA_START_RECOVER */
872 struct ndmp9_data_start_recover_request {
873 	ndmp9_pval	env<>;
874 	ndmp9_name	nlist<>;
875 	string		bu_type<>;
876 	ndmp9_addr	addr;
877 };
878 typedef ndmp9_just_error_reply	ndmp9_data_start_recover_reply;
879 
880 /* NDMP9_DATA_START_RECOVER_FILEHIST */
881 typedef ndmp9_data_start_recover_request ndmp9_data_start_recover_filehist_request;
882 typedef ndmp9_data_start_recover_reply ndmp9_data_start_recover_filehist_reply;
883 
884 
885 /* NDMP9_DATA_ABORT */
886 typedef ndmp9_no_arguments	ndmp9_data_abort_request;
887 typedef ndmp9_just_error_reply	ndmp9_data_abort_reply;
888 
889 /* NDMP9_DATA_STOP */
890 typedef ndmp9_no_arguments	ndmp9_data_stop_request;
891 typedef ndmp9_just_error_reply	ndmp9_data_stop_reply;
892 
893 /* NDMP9_DATA_GET_ENV */
894 typedef ndmp9_no_arguments	ndmp9_data_get_env_request;
895 struct ndmp9_data_get_env_reply {
896 	ndmp9_error	error;
897 	ndmp9_pval	env<>;
898 };
899 
900 /* NDMP9_DATA_LISTEN */
901 struct ndmp9_data_listen_request {
902 	ndmp9_addr_type	addr_type;
903 };
904 
905 struct ndmp9_data_listen_reply {
906 	ndmp9_error	error;
907 	ndmp9_addr	data_connection_addr;
908 };
909 
910 /* NDMP9_DATA_CONNECT */
911 struct ndmp9_data_connect_request {
912 	ndmp9_addr	addr;
913 };
914 typedef ndmp9_just_error_reply	ndmp9_data_connect_reply;
915 
916 
917 
918 
919 /****************************/
920 /* NOTIFY INTERFACE	    */
921 /****************************/
922 
923 /* NDMP9_NOTIFY_DATA_HALTED */
924 struct ndmp9_notify_data_halted_request {
925 	ndmp9_data_halt_reason	reason;
926 };
927 
928 enum ndmp9_connect_reason {
929 	NDMP9_CONNECTED,	/* Connect sucessfully */
930 	NDMP9_SHUTDOWN,		/* Connection shutdown */
931 	NDMP9_REFUSED		/* reach the maximum number of connections */
932 };
933 
934 /* NDMP9_NOTIFY_CONNECTED */
935 struct ndmp9_notify_connected_request {
936 	ndmp9_connect_reason	reason;
937 	uint16_t		protocol_version;
938 	string			text_reason<>;
939 };
940 
941 /* NDMP9_NOTIFY_MOVER_HALTED */
942 struct ndmp9_notify_mover_halted_request {
943 	ndmp9_mover_halt_reason	reason;
944 };
945 
946 /* NDMP9_NOTIFY_MOVER_PAUSED */
947 struct ndmp9_notify_mover_paused_request {
948 	ndmp9_mover_pause_reason reason;
949 	ndmp9_u_quad		seek_position;
950 };
951 
952 /* NDMP9_NOTIFY_DATA_READ */
953 struct ndmp9_notify_data_read_request {
954 	ndmp9_u_quad	offset;
955 	ndmp9_u_quad	length;
956 };
957 
958 
959 /********************************/
960 /* LOG INTERFACE		*/
961 /********************************/
962 /* NDMP9_LOG_MESSAGE */
963 enum ndmp9_log_type {
964 	NDMP9_LOG_NORMAL,
965 	NDMP9_LOG_DEBUG,
966 	NDMP9_LOG_ERROR,
967 	NDMP9_LOG_WARNING
968 };
969 
970 struct ndmp9_log_message_request {
971 	ndmp9_log_type		log_type;
972 	uint32_t		message_id;
973 	string			entry<>;
974 	ndmp9_valid_u_long	associated_message_sequence;
975 };
976 /* No reply */
977 
978 enum ndmp9_recovery_status {
979 	NDMP9_RECOVERY_SUCCESSFUL             = 0,
980 	NDMP9_RECOVERY_FAILED_PERMISSION      = 1,
981 	NDMP9_RECOVERY_FAILED_NOT_FOUND       = 2,
982 	NDMP9_RECOVERY_FAILED_NO_DIRECTORY    = 3,
983 	NDMP9_RECOVERY_FAILED_OUT_OF_MEMORY   = 4,
984 	NDMP9_RECOVERY_FAILED_IO_ERROR        = 5,
985 	NDMP9_RECOVERY_FAILED_UNDEFINED_ERROR = 6
986 };
987 
988 /* NDMP9_LOG_FILE */
989 struct ndmp9_log_file_request {
990 	string			name<>;
991 	ndmp9_recovery_status	recovery_status;
992 };
993 /* No reply */
994 
995 
996 
997 /*
998  * FILE HISTORY INTERFACES
999  ****************************************************************
1000  */
1001 
1002 
1003 enum ndmp9_file_type {
1004 	NDMP9_FILE_DIR,
1005 	NDMP9_FILE_FIFO,
1006 	NDMP9_FILE_CSPEC,
1007 	NDMP9_FILE_BSPEC,
1008 	NDMP9_FILE_REG,
1009 	NDMP9_FILE_SLINK,
1010 	NDMP9_FILE_SOCK,
1011 	NDMP9_FILE_REGISTRY,
1012 	NDMP9_FILE_OTHER
1013 };
1014 
1015 struct ndmp9_file_stat {
1016 	ndmp9_file_type		ftype;
1017 	ndmp9_valid_u_long	mtime;
1018 	ndmp9_valid_u_long	atime;
1019 	ndmp9_valid_u_long	ctime;
1020 	ndmp9_valid_u_long	uid;
1021 	ndmp9_valid_u_long	gid;
1022 	ndmp9_valid_u_long	mode;
1023 	ndmp9_valid_u_quad	size;
1024 	ndmp9_valid_u_long	links;
1025 
1026 	/*
1027 	 * Add NT attributes here as ndmp9_valid_....
1028 	 */
1029 
1030 	ndmp9_valid_u_quad	node;	    /* id on disk at backup time */
1031 	ndmp9_valid_u_quad	fh_info;    /* id on tape at backup time */
1032 };
1033 
1034 
1035 /*
1036  * ndmp_fh_add_file
1037  * no reply
1038  */
1039 struct ndmp9_file {
1040 	string			unix_path<>;
1041 	/* nt_path<> here */
1042 	/* dos_path<> here */
1043 	ndmp9_file_stat		fstat;
1044 };
1045 
1046 struct ndmp9_fh_add_file_request {
1047 	ndmp9_file		files<>;
1048 };
1049 
1050 
1051 /*
1052  * ndmp_fh_add_dir
1053  * no reply
1054  */
1055 struct ndmp9_dir {
1056 	string			unix_name<>;
1057 	/* nt_name<> here */
1058 	/* dos_name<> here */
1059 	ndmp9_u_quad		node;
1060 	ndmp9_u_quad		parent;
1061 };
1062 
1063 struct ndmp9_fh_add_dir_request {
1064 	ndmp9_dir		dirs<>;
1065 };
1066 
1067 
1068 /*
1069  * ndmp_fh_add_node
1070  * no reply
1071  */
1072 struct ndmp9_node {
1073 	ndmp9_file_stat		fstat;
1074 };
1075 
1076 struct ndmp9_fh_add_node_request {
1077 	ndmp9_node		nodes<>;
1078 };
1079 /* No reply */
1080