3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
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.
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
38 #include "ndmos.h" /* rpc/rpc.h */
39 #include "ndmprotocol.h"
40 #include "ndmp_msg_buf.h"
41 #include "ndmp_translate.h"
47 * enum_conversion tables
48 ****************************************************************
49 * Used to make enum conversion convenient and dense.
50 * The first row is the default case in both directions,
51 * and is skipped while attempting precise conversion.
52 * The search stops with the first match.
56 convert_enum_to_9 (struct enum_conversion *ectab, int enum_x)
58 struct enum_conversion * ec = &ectab[1];
60 for (; !IS_END_ENUM_CONVERSION_TABLE(ec); ec++) {
61 if (ec->enum_x == enum_x)
65 return ectab[0].enum_9;
69 convert_enum_from_9 (struct enum_conversion *ectab, int enum_9)
71 struct enum_conversion * ec = &ectab[1];
73 for (; !IS_END_ENUM_CONVERSION_TABLE(ec); ec++) {
74 if (ec->enum_9 == enum_9)
78 return ectab[0].enum_x;
82 convert_valid_u_long_to_9 (u_long *valx, ndmp9_valid_u_long *val9)
86 if (*valx == NDMP_INVALID_U_LONG)
87 val9->valid = NDMP9_VALIDITY_INVALID;
89 val9->valid = NDMP9_VALIDITY_VALID;
95 convert_valid_u_long_from_9 (u_long *valx, ndmp9_valid_u_long *val9)
98 *valx = NDMP_INVALID_U_LONG;
106 convert_invalid_u_long_9 (struct ndmp9_valid_u_long *val9)
108 val9->value = NDMP_INVALID_U_LONG;
109 val9->valid = NDMP9_VALIDITY_INVALID;
115 convert_valid_u_quad_to_9 (ndmp9_u_quad *valx, ndmp9_valid_u_quad *val9)
119 if (*valx == NDMP_INVALID_U_QUAD)
120 val9->valid = NDMP9_VALIDITY_INVALID;
122 val9->valid = NDMP9_VALIDITY_VALID;
128 convert_valid_u_quad_from_9 (ndmp9_u_quad *valx, ndmp9_valid_u_quad *val9)
131 *valx = NDMP_INVALID_U_QUAD;
139 convert_invalid_u_quad_9 (struct ndmp9_valid_u_quad *val9)
141 val9->value = NDMP_INVALID_U_QUAD;
142 val9->valid = NDMP9_VALIDITY_INVALID;
148 convert_strdup (char *src, char **dstp)
154 *dstp = NDMOS_API_STRDUP (src);
163 * request/reply translation tables
164 ****************************************************************
167 struct reqrep_xlate_version_table reqrep_xlate_version_table[] = {
168 #ifndef NDMOS_OPTION_NO_NDMP2
169 { NDMP2VER, ndmp2_reqrep_xlate_table },
170 #endif /* !NDMOS_OPTION_NO_NDMP2 */
171 #ifndef NDMOS_OPTION_NO_NDMP3
172 { NDMP3VER, ndmp3_reqrep_xlate_table },
173 #endif /* !NDMOS_OPTION_NO_NDMP3 */
174 #ifndef NDMOS_OPTION_NO_NDMP4
175 { NDMP4VER, ndmp4_reqrep_xlate_table },
176 #endif /* !NDMOS_OPTION_NO_NDMP4 */
180 struct reqrep_xlate *
181 reqrep_xlate_lookup_version (
182 struct reqrep_xlate_version_table *rrvt,
183 unsigned protocol_version)
185 for (; rrvt->protocol_version > 0; rrvt++) {
186 if (rrvt->protocol_version == (int)protocol_version) {
187 return rrvt->reqrep_xlate_table;
195 struct reqrep_xlate *
196 ndmp_reqrep_by_v9 (struct reqrep_xlate *table, ndmp9_message v9_message)
198 struct reqrep_xlate * rrx = table;
200 for (; rrx->v9_message; rrx++)
201 if (rrx->v9_message == v9_message)
207 struct reqrep_xlate *
208 ndmp_reqrep_by_vx (struct reqrep_xlate *table, int vx_message)
210 struct reqrep_xlate * rrx = table;
212 for (; rrx->v9_message; rrx++)
213 if (rrx->vx_message == vx_message)
220 ndmp_xtox_no_arguments (void *vxbody, void *vybody)
227 ndmp_xtox_no_memused (void *vxbody)