Imported Upstream version 3.1.0
[debian/amanda] / ndmp-src / ndmp2_pp.c
1 /*
2  * Copyright (c) 1998,1999,2000
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  *
35  */
36
37
38 #include "ndmos.h"              /* rpc/rpc.h */
39 #include "ndmprotocol.h"
40
41
42 #ifndef NDMOS_OPTION_NO_NDMP2
43
44
45 int
46 ndmp2_pp_header (void *data, char *buf)
47 {
48         ndmp2_header *          mh = (ndmp2_header *) data;
49
50         if (mh->message_type == NDMP2_MESSAGE_REQUEST) {
51                 sprintf (buf, "C %s %lu",
52                         ndmp2_message_to_str (mh->message),
53                         mh->sequence);
54         } else if (mh->message_type == NDMP2_MESSAGE_REPLY) {
55                 sprintf (buf, "R %s %lu (%lu)",
56                         ndmp2_message_to_str (mh->message),
57                         mh->reply_sequence,
58                         mh->sequence);
59                 if (mh->error != NDMP2_NO_ERR) {
60                         sprintf (NDMOS_API_STREND(buf), " %s",
61                                 ndmp2_error_to_str (mh->error));
62                         return 0;       /* no body */
63                 }
64         } else {
65                 strcpy (buf, "??? INVALID MESSAGE TYPE");
66                 return -1;      /* no body */
67         }
68         return 1;       /* body */
69 }
70
71 int
72 ndmp2_pp_mover_addr (char *buf, ndmp2_mover_addr *ma)
73 {
74         sprintf (buf, "%s", ndmp2_mover_addr_type_to_str (ma->addr_type));
75         if (ma->addr_type == NDMP2_ADDR_TCP) {
76                 sprintf (NDMOS_API_STREND(buf), "(%lx,%d)",
77                         ma->ndmp2_mover_addr_u.addr.ip_addr,
78                         ma->ndmp2_mover_addr_u.addr.port);
79         }
80         return 0;
81 }
82
83
84 int
85 ndmp2_pp_request (ndmp2_message msg, void *data, int lineno, char *buf)
86 {
87     int             i;
88     unsigned int    j;
89
90     switch (msg) {
91     default:
92         strcpy (buf, "<<INVALID MSG>>");
93         return -1;
94
95     case NDMP2_CONNECT_OPEN:
96       NDMP_PP_WITH(ndmp2_connect_open_request)
97         sprintf (buf, "version=%d", p->protocol_version);
98       NDMP_PP_ENDWITH
99       break;
100
101     case NDMP2_CONNECT_CLIENT_AUTH:
102       NDMP_PP_WITH(ndmp2_connect_client_auth_request)
103         sprintf (buf, "auth_type=%s",
104                 ndmp2_auth_type_to_str (p->auth_data.auth_type));
105         switch (p->auth_data.auth_type) {
106         case NDMP2_AUTH_NONE:
107                 break;
108
109         case NDMP2_AUTH_TEXT:
110                 sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
111                         p->auth_data.ndmp2_auth_data_u.auth_text.auth_id);
112                 break;
113
114         case NDMP2_AUTH_MD5:
115                 sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
116                         p->auth_data.ndmp2_auth_data_u.auth_md5.auth_id);
117                 break;
118
119         default:
120                 sprintf (NDMOS_API_STREND(buf), " ????");
121                 break;
122         }
123       NDMP_PP_ENDWITH
124       break;
125
126     case NDMP2_CONNECT_CLOSE:
127     case NDMP2_CONFIG_GET_HOST_INFO:
128     case NDMP2_CONFIG_GET_MOVER_TYPE:
129     case NDMP2_SCSI_CLOSE:
130     case NDMP2_SCSI_GET_STATE:
131     case NDMP2_SCSI_RESET_DEVICE:
132     case NDMP2_SCSI_RESET_BUS:
133     case NDMP2_TAPE_GET_STATE:
134     case NDMP2_TAPE_CLOSE:
135     case NDMP2_MOVER_GET_STATE:
136     case NDMP2_MOVER_CONTINUE:
137     case NDMP2_MOVER_ABORT:
138     case NDMP2_MOVER_STOP:
139     case NDMP2_MOVER_CLOSE:
140     case NDMP2_DATA_GET_STATE:
141     case NDMP2_DATA_ABORT:
142     case NDMP2_DATA_STOP:
143     case NDMP2_DATA_GET_ENV:
144         *buf = 0;       /* no body */
145         return 0;
146
147     case NDMP2_CONNECT_SERVER_AUTH:
148         strcpy (buf, "<<unimplemented pp>>");
149       break;
150
151     case NDMP2_CONFIG_GET_BUTYPE_ATTR:
152       NDMP_PP_WITH(ndmp2_config_get_butype_attr_request)
153         sprintf (buf, "bu_type='%s'", p->name);
154       NDMP_PP_ENDWITH
155       break;
156
157     case NDMP2_CONFIG_GET_AUTH_ATTR:
158       NDMP_PP_WITH(ndmp2_config_get_auth_attr_request)
159         sprintf (buf, "auth_type=%s", ndmp2_auth_type_to_str (p->auth_type));
160       NDMP_PP_ENDWITH
161       break;
162
163     case NDMP2_SCSI_OPEN:
164       NDMP_PP_WITH(ndmp2_scsi_open_request)
165         sprintf (buf, "device='%s'", p->device.name);
166       NDMP_PP_ENDWITH
167       break;
168
169     case NDMP2_SCSI_SET_TARGET:
170       NDMP_PP_WITH(ndmp2_scsi_set_target_request)
171         sprintf (buf, "device='%s' cont=%d sid=%d lun=%d",
172                 p->device.name, p->target_controller,
173                 p->target_id, p->target_lun);
174       NDMP_PP_ENDWITH
175       break;
176
177     case NDMP2_SCSI_EXECUTE_CDB:
178     case NDMP2_TAPE_EXECUTE_CDB:
179       NDMP_PP_WITH(ndmp2_execute_cdb_request)
180         switch (lineno) {
181         case 0: sprintf (buf, "flags=0x%lx timeout=%ld datain_len=%ld",
182                         p->flags, p->timeout, p->datain_len);
183                 break;
184         case 1: sprintf (buf, "cmd[%d]={", p->cdb.cdb_len);
185                 for (j = 0; j < p->cdb.cdb_len; j++) {
186                         sprintf (NDMOS_API_STREND(buf), " %02x",
187                                                 p->cdb.cdb_val[j]&0xFF);
188                 }
189                 strcat (buf, " }");
190                 break;
191         }
192         return 2;
193       NDMP_PP_ENDWITH
194       break;
195
196     case NDMP2_TAPE_OPEN:
197       NDMP_PP_WITH(ndmp2_tape_open_request)
198         sprintf (buf, "device='%s' mode=%s",
199                 p->device.name,
200                 ndmp2_tape_open_mode_to_str (p->mode));
201       NDMP_PP_ENDWITH
202       break;
203
204     case NDMP2_TAPE_MTIO:
205       NDMP_PP_WITH(ndmp2_tape_mtio_request)
206         sprintf (buf, "op=%s count=%ld",
207                 ndmp2_tape_mtio_op_to_str(p->tape_op),
208                 p->count);
209       NDMP_PP_ENDWITH
210       break;
211
212     case NDMP2_TAPE_WRITE:
213       NDMP_PP_WITH(ndmp2_tape_write_request)
214         sprintf (buf, "data_out_len=%d", p->data_out.data_out_len);
215       NDMP_PP_ENDWITH
216       break;
217
218     case NDMP2_TAPE_READ:
219       NDMP_PP_WITH(ndmp2_tape_read_request)
220         sprintf (buf, "count=%ld", p->count);
221       NDMP_PP_ENDWITH
222       break;
223
224     case NDMP2_DATA_START_BACKUP:
225       NDMP_PP_WITH(ndmp2_data_start_backup_request)
226         if (lineno == 0) {
227                 sprintf (buf, "bu_type='%s' n_env=%d mover=",
228                         p->bu_type, p->env.env_len);
229                 ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
230         } else {
231                 i = lineno - 1;
232                 if (0 <= i && (unsigned)i < p->env.env_len) {
233                         sprintf (buf, "env[%d] name='%s' value='%s'",
234                                 i, p->env.env_val[i].name,
235                                 p->env.env_val[i].value);
236                 } else {
237                         strcpy (buf, "--INVALID--");
238                 }
239         }
240         return 1 + p->env.env_len;
241       NDMP_PP_ENDWITH
242       break;
243
244     case NDMP2_DATA_START_RECOVER:
245     case NDMP2_DATA_START_RECOVER_FILEHIST:
246       NDMP_PP_WITH(ndmp2_data_start_recover_request)
247         if (lineno == 0) {
248                 sprintf (buf, "bu_type='%s' n_env=%d n_nlist=%d mover=",
249                         p->bu_type, p->env.env_len,
250                         p->nlist.nlist_len);
251                 ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
252         } else {
253                 i = lineno - 1;
254                 if (0 <= i && (unsigned)i < p->env.env_len) {
255                         sprintf (buf, "env[%d] name='%s' value='%s'",
256                                 i, p->env.env_val[i].name,
257                                 p->env.env_val[i].value);
258                 } else {
259                         i -= p->env.env_len;
260                         if (0 <= i && (unsigned)i < p->nlist.nlist_len) {
261                                 sprintf (buf,
262                                         "nl[%d] name='%s' fhi=%lld dest='%s'",
263                                         i,
264                                         p->nlist.nlist_val[i].name,
265                                         p->nlist.nlist_val[i].fh_info,
266                                         p->nlist.nlist_val[i].dest);
267                         } else {
268                                 strcpy (buf, "--INVALID--");
269                         }
270                 }
271         }
272         return 1 + p->env.env_len + p->nlist.nlist_len;
273       NDMP_PP_ENDWITH
274       break;
275
276     case NDMP2_NOTIFY_DATA_HALTED:
277       NDMP_PP_WITH(ndmp2_notify_data_halted_request)
278         sprintf (buf, "reason=%s text_reason='%s'",
279                 ndmp2_data_halt_reason_to_str(p->reason),
280                 p->text_reason);
281       NDMP_PP_ENDWITH
282       break;
283
284     case NDMP2_NOTIFY_CONNECTED:
285       NDMP_PP_WITH(ndmp2_notify_connected_request)
286         sprintf (buf, "reason=%s protocol_version=%d text_reason='%s'",
287                 ndmp2_connect_reason_to_str(p->reason),
288                 p->protocol_version,
289                 p->text_reason);
290       NDMP_PP_ENDWITH
291       break;
292
293     case NDMP2_NOTIFY_MOVER_HALTED:
294       NDMP_PP_WITH(ndmp2_notify_mover_halted_request)
295         sprintf (buf, "reason=%s text_reason='%s'",
296                 ndmp2_mover_halt_reason_to_str(p->reason),
297                 p->text_reason);
298       NDMP_PP_ENDWITH
299       break;
300
301     case NDMP2_NOTIFY_MOVER_PAUSED:
302       NDMP_PP_WITH(ndmp2_notify_mover_paused_request)
303         sprintf (buf, "reason=%s seek_position=%lld",
304                 ndmp2_mover_pause_reason_to_str(p->reason),
305                 p->seek_position);
306       NDMP_PP_ENDWITH
307       break;
308
309     case NDMP2_NOTIFY_DATA_READ:
310       NDMP_PP_WITH(ndmp2_notify_data_read_request)
311         sprintf (buf, "offset=%lld length=%lld",
312                 p->offset, p->length);
313       NDMP_PP_ENDWITH
314       break;
315
316     case NDMP2_LOG_LOG:
317       NDMP_PP_WITH(ndmp2_log_log_request)
318         sprintf (buf, "entry='%s'", p->entry);
319       NDMP_PP_ENDWITH
320       break;
321
322     case NDMP2_LOG_DEBUG:
323       NDMP_PP_WITH(ndmp2_log_debug_request)
324         sprintf (buf, "level=%s message='%s'",
325                 ndmp2_debug_level_to_str(p->level), p->message);
326       NDMP_PP_ENDWITH
327       break;
328
329     case NDMP2_LOG_FILE:
330       NDMP_PP_WITH(ndmp2_log_file_request)
331         sprintf (buf, "file=%s error=%s",
332                 p->name,
333                 ndmp2_error_to_str(p->error));
334       NDMP_PP_ENDWITH
335       break;
336
337     case NDMP2_FH_ADD_UNIX_PATH:
338       NDMP_PP_WITH(ndmp2_fh_add_unix_path_request)
339         if (lineno == 0) {
340                 sprintf (buf, "n_paths=%d", p->paths.paths_len);
341         } else {
342                 i = lineno - 1;
343                 if (0 <= i && (unsigned)i < p->paths.paths_len) {
344                         struct ndmp2_fh_unix_path *pa;
345
346                         pa = &p->paths.paths_val[i];
347                         sprintf (buf, "[%d] %-15s %7llu %s [%lld]", i,
348                                 ndmp2_unix_file_type_to_str(pa->fstat.ftype),
349                                 pa->fstat.size,
350                                 pa->name,
351                                 pa->fstat.fh_info);
352                 } else {
353                         strcpy (buf, "--INVALID--");
354                 }
355         }
356         return 1 + p->paths.paths_len;
357       NDMP_PP_ENDWITH
358       break;
359
360     case NDMP2_FH_ADD_UNIX_DIR:
361       NDMP_PP_WITH(ndmp2_fh_add_unix_dir_request)
362         if (lineno == 0) {
363                 sprintf (buf, "n_dirs=%d", p->dirs.dirs_len);
364         } else {
365                 i = lineno - 1;
366                 if (0 <= i && (unsigned)i < p->dirs.dirs_len) {
367                         struct ndmp2_fh_unix_dir *de;
368
369                         de = &p->dirs.dirs_val[i];
370                         sprintf (buf, "[%d] %lu %lu %s", i,
371                                 de->node, de->parent, de->name);
372                 } else {
373                         strcpy (buf, "--INVALID--");
374                 }
375         }
376         return 1 + p->dirs.dirs_len;
377       NDMP_PP_ENDWITH
378       break;
379
380     case NDMP2_FH_ADD_UNIX_NODE:
381       NDMP_PP_WITH(ndmp2_fh_add_unix_node_request)
382         if (lineno == 0) {
383                 sprintf (buf, "n_nodes=%d", p->nodes.nodes_len);
384         } else {
385                 i = lineno - 1;
386                 if (0 <= i && (unsigned)i < p->nodes.nodes_len) {
387                         struct ndmp2_fh_unix_node *nd;
388
389                         nd = &p->nodes.nodes_val[i];
390                         sprintf (buf, "[%d] %-15s %7llu %lu [%lld]", i,
391                                 ndmp2_unix_file_type_to_str(nd->fstat.ftype),
392                                 nd->fstat.size,
393                                 nd->node,
394                                 nd->fstat.fh_info);
395                 } else {
396                         strcpy (buf, "--INVALID--");
397                 }
398         }
399         return 1 + p->nodes.nodes_len;
400       NDMP_PP_ENDWITH
401       break;
402
403     case NDMP2_MOVER_LISTEN:
404       NDMP_PP_WITH(ndmp2_mover_listen_request)
405         sprintf (buf, "mode=%s addr_type=%s",
406                 ndmp2_mover_mode_to_str (p->mode),
407                 ndmp2_mover_addr_type_to_str (p->addr_type));
408       NDMP_PP_ENDWITH
409       break;
410
411     case NDMP2_MOVER_SET_WINDOW:
412       NDMP_PP_WITH(ndmp2_mover_set_window_request)
413         sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
414       NDMP_PP_ENDWITH
415       break;
416
417     case NDMP2_MOVER_READ:
418       NDMP_PP_WITH(ndmp2_mover_read_request)
419         sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
420       NDMP_PP_ENDWITH
421       break;
422
423     case NDMP2_MOVER_SET_RECORD_SIZE:
424       NDMP_PP_WITH(ndmp2_mover_set_record_size_request)
425         sprintf (buf, "len=%lu", p->len);
426       NDMP_PP_ENDWITH
427       break;
428     }
429     return 1;   /* one line in buf */
430 }
431
432
433
434 int
435 ndmp2_pp_reply (ndmp2_message msg, void *data, int lineno, char *buf)
436 {
437     int                 i;
438     unsigned int        j;
439
440     switch (msg) {
441     default:
442         strcpy (buf, "<<INVALID MSG>>");
443         return -1;
444
445     case NDMP2_CONNECT_OPEN:
446     case NDMP2_CONNECT_CLIENT_AUTH:
447     case NDMP2_SCSI_OPEN:
448     case NDMP2_SCSI_CLOSE:
449     case NDMP2_SCSI_SET_TARGET:
450     case NDMP2_SCSI_RESET_DEVICE:
451     case NDMP2_SCSI_RESET_BUS:
452     case NDMP2_TAPE_OPEN:
453     case NDMP2_TAPE_CLOSE:
454     case NDMP2_MOVER_CONTINUE:
455     case NDMP2_MOVER_ABORT:
456     case NDMP2_MOVER_STOP:
457     case NDMP2_MOVER_READ:
458     case NDMP2_MOVER_SET_WINDOW:
459     case NDMP2_MOVER_CLOSE:
460     case NDMP2_MOVER_SET_RECORD_SIZE:
461     case NDMP2_DATA_START_BACKUP:
462     case NDMP2_DATA_START_RECOVER:
463     case NDMP2_DATA_START_RECOVER_FILEHIST:
464     case NDMP2_DATA_ABORT:
465     case NDMP2_DATA_STOP:
466       NDMP_PP_WITH(ndmp2_error)
467         sprintf (buf, "error=%s", ndmp2_error_to_str(*p));
468       NDMP_PP_ENDWITH
469       break;
470
471     case NDMP2_CONNECT_CLOSE:
472         *buf = 0;
473         return 0;
474
475     case NDMP2_CONNECT_SERVER_AUTH:
476         strcpy (buf, "<<unimplemented pp>>");
477       break;
478
479     case NDMP2_CONFIG_GET_HOST_INFO:
480       NDMP_PP_WITH(ndmp2_config_get_host_info_reply)
481         switch (lineno) {
482         case 0: sprintf (buf, "error=%s hostname=%s",
483                         ndmp2_error_to_str(p->error),
484                         p->hostname);
485                 break;
486         case 1: sprintf (buf, "os_type=%s os_vers=%s hostid=%s",
487                         p->os_type, p->os_vers, p->hostid);
488                 break;
489         case 2: sprintf (buf, "auth_type[%d]={", p->auth_type.auth_type_len);
490                 for (j = 0; j < p->auth_type.auth_type_len; j++) {
491                         sprintf (NDMOS_API_STREND(buf), " %s",
492                                 ndmp2_auth_type_to_str(
493                                         p->auth_type.auth_type_val[j]));
494                 }
495                 strcat (buf, " }");
496                 break;
497         default:
498                 strcpy (buf, "--INVALID--");
499                 break;
500         }
501         return 3;
502       NDMP_PP_ENDWITH
503       break;
504
505     case NDMP2_CONFIG_GET_BUTYPE_ATTR:
506       NDMP_PP_WITH(ndmp2_config_get_butype_attr_reply)
507         sprintf (buf, "error=%s attrs=0x%lx",
508                         ndmp2_error_to_str(p->error),
509                         p->attrs);
510       NDMP_PP_ENDWITH
511       break;
512
513     case NDMP2_CONFIG_GET_MOVER_TYPE:
514       NDMP_PP_WITH(ndmp2_config_get_mover_type_reply)
515         sprintf (buf, "error=%s methods[%d]={",
516                         ndmp2_error_to_str(p->error),
517                         p->methods.methods_len);
518         for (j = 0; j < p->methods.methods_len; j++) {
519                 sprintf (NDMOS_API_STREND(buf), " %s",
520                     ndmp2_mover_addr_type_to_str(p->methods.methods_val[j]));
521         }
522         strcat (buf, " }");
523       NDMP_PP_ENDWITH
524       break;
525
526     case NDMP2_CONFIG_GET_AUTH_ATTR:
527         strcpy (buf, "<<unimplemented pp>>");
528       break;
529
530     case NDMP2_SCSI_GET_STATE:
531       NDMP_PP_WITH(ndmp2_scsi_get_state_reply)
532         sprintf (buf, "error=%s cont=%d sid=%d lun=%d",
533                 ndmp2_error_to_str(p->error),
534                 p->target_controller,
535                 p->target_id, p->target_lun);
536       NDMP_PP_ENDWITH
537       break;
538
539     case NDMP2_SCSI_EXECUTE_CDB:
540     case NDMP2_TAPE_EXECUTE_CDB:
541       NDMP_PP_WITH(ndmp2_execute_cdb_reply)
542         switch (lineno) {
543         case 0: sprintf (buf,
544                         "error=%s status=%02x dataout_len=%ld datain_len=%d",
545                         ndmp2_error_to_str(p->error),
546                         p->status, p->dataout_len, p->datain.datain_len);
547                 break;
548         case 1: sprintf (buf, "sense[%d]={", p->ext_sense.ext_sense_len);
549                 for (j = 0; j < p->ext_sense.ext_sense_len; j++) {
550                         sprintf (NDMOS_API_STREND(buf), " %02x",
551                                 p->ext_sense.ext_sense_val[j]&0xFF);
552                 }
553                 strcat (buf, " }");
554                 break;
555         }
556         return 2;
557       NDMP_PP_ENDWITH
558       break;
559
560     case NDMP2_TAPE_GET_STATE:
561       NDMP_PP_WITH(ndmp2_tape_get_state_reply)
562         switch (lineno) {
563         case 0: sprintf (buf, "error=%s flags=0x%lx file_num=%ld",
564                         ndmp2_error_to_str(p->error),
565                         p->flags, p->file_num);
566                 break;
567         case 1: sprintf (buf, "soft_errors=%lu block_size=%lu blockno=%lu",
568                         p->soft_errors, p->block_size, p->blockno);
569                 break;
570         case 2: sprintf (buf, "total_space=%lld space_remain=%lld",
571                         p->total_space, p->space_remain);
572                 break;
573         default:
574                 strcpy (buf, "--INVALID--");
575                 break;
576         }
577         return 3;
578       NDMP_PP_ENDWITH
579       break;
580
581     case NDMP2_TAPE_MTIO:
582       NDMP_PP_WITH(ndmp2_tape_mtio_reply)
583         sprintf (buf, "error=%s resid_count=%ld",
584                 ndmp2_error_to_str(p->error), p->resid_count);
585       NDMP_PP_ENDWITH
586       break;
587
588     case NDMP2_TAPE_WRITE:
589       NDMP_PP_WITH(ndmp2_tape_write_reply)
590         sprintf (buf, "error=%s count=%ld",
591                 ndmp2_error_to_str(p->error), p->count);
592       NDMP_PP_ENDWITH
593       break;
594
595     case NDMP2_TAPE_READ:
596       NDMP_PP_WITH(ndmp2_tape_read_reply)
597         sprintf (buf, "error=%s data_in_len=%d",
598                 ndmp2_error_to_str(p->error), p->data_in.data_in_len);
599       NDMP_PP_ENDWITH
600       break;
601
602     case NDMP2_DATA_GET_STATE:
603       NDMP_PP_WITH(ndmp2_data_get_state_reply)
604         switch (lineno) {
605         case 0: sprintf (buf, "error=%s op=%s",
606                         ndmp2_error_to_str(p->error),
607                         ndmp2_data_operation_to_str(p->operation));
608                 break;
609         case 1: sprintf (buf, "state=%s",
610                         ndmp2_data_state_to_str(p->state));
611                 break;
612         case 2: sprintf (buf, "halt_reason=%s",
613                         ndmp2_data_halt_reason_to_str(p->halt_reason));
614                 break;
615         case 3: sprintf (buf, "bytes_processed=%lld est_bytes_remain=%lld",
616                         p->bytes_processed, p->est_bytes_remain);
617                 break;
618         case 4: sprintf (buf, "est_time_remain=%ld mover=",
619                         p->est_time_remain);
620                 ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
621                 break;
622         case 5: sprintf (buf, "read_offset=%lld read_length=%lld",
623                         p->read_offset, p->read_length);
624                 break;
625         default:
626                 strcpy (buf, "--INVALID--");
627                 break;
628         }
629         return 6;
630       NDMP_PP_ENDWITH
631       break;
632
633     case NDMP2_DATA_GET_ENV:
634       NDMP_PP_WITH(ndmp2_data_get_env_reply)
635         if (lineno == 0) {
636                 sprintf (buf, "error=%s n_env=%d",
637                         ndmp2_error_to_str(p->error),
638                         p->env.env_len);
639         } else {
640                 i = lineno - 1;
641                 if (0 <= i && (unsigned)i < p->env.env_len) {
642                         sprintf (buf, "[%d] name='%s' value='%s'",
643                                 i, p->env.env_val[i].name,
644                                 p->env.env_val[i].value);
645                 } else {
646                         strcpy (buf, "--INVALID--");
647                 }
648         }
649         return p->env.env_len + 1;
650       NDMP_PP_ENDWITH
651       break;
652
653     case NDMP2_NOTIFY_DATA_HALTED:
654     case NDMP2_NOTIFY_CONNECTED:
655     case NDMP2_NOTIFY_MOVER_HALTED:
656     case NDMP2_NOTIFY_MOVER_PAUSED:
657     case NDMP2_NOTIFY_DATA_READ:
658     case NDMP2_LOG_LOG:
659     case NDMP2_LOG_DEBUG:
660     case NDMP2_LOG_FILE:
661     case NDMP2_FH_ADD_UNIX_PATH:
662     case NDMP2_FH_ADD_UNIX_DIR:
663     case NDMP2_FH_ADD_UNIX_NODE:
664         strcpy (buf, "<<ILLEGAL REPLY>>");
665       break;
666
667     case NDMP2_MOVER_GET_STATE:
668       NDMP_PP_WITH(ndmp2_mover_get_state_reply)
669         switch (lineno) {
670         case 0: sprintf (buf, "error=%s state=%s",
671                         ndmp2_error_to_str(p->error),
672                         ndmp2_mover_state_to_str(p->state));
673                 break;
674         case 1: sprintf (buf, "pause_reason=%s",
675                         ndmp2_mover_pause_reason_to_str(p->pause_reason));
676                 break;
677         case 2: sprintf (buf, "halt_reason=%s",
678                         ndmp2_mover_halt_reason_to_str(p->halt_reason));
679                 break;
680         case 3: sprintf (buf,"record_size=%lu record_num=%lu data_written=%lld",
681                         p->record_size, p->record_num, p->data_written);
682                 break;
683         case 4: sprintf (buf, "seek=%lld to_read=%lld win_off=%lld win_len=%lld",
684                         p->seek_position, p->bytes_left_to_read,
685                         p->window_offset, p->window_length);
686                 break;
687         default:
688                 strcpy (buf, "--INVALID--");
689                 break;
690         }
691         return 5;
692       NDMP_PP_ENDWITH
693       break;
694
695     case NDMP2_MOVER_LISTEN:
696       NDMP_PP_WITH(ndmp2_mover_listen_reply)
697         sprintf (buf, "error=%s mover=", ndmp2_error_to_str(p->error));
698         ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
699       NDMP_PP_ENDWITH
700       break;
701     }
702
703     return 1;   /* one line in buf */
704 }
705
706 #endif /* NDMOS_OPTION_NO_NDMP2 */