xdr.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /* $NetBSD: xdr.c,v 1.22 2000/07/06 03:10:35 christos Exp $ */
  2. /*
  3. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4. * unrestricted use provided that this legend is included on all tape
  5. * media and as a part of the software program in whole or part. Users
  6. * may copy or modify Sun RPC without charge, but are not authorized
  7. * to license or distribute it to anyone else except as part of a product or
  8. * program developed by the user.
  9. *
  10. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13. *
  14. * Sun RPC is provided with no support and without any obligation on the
  15. * part of Sun Microsystems, Inc. to assist in its use, correction,
  16. * modification or enhancement.
  17. *
  18. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20. * OR ANY PART THEREOF.
  21. *
  22. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23. * or profits or other special, indirect and consequential damages, even if
  24. * Sun has been advised of the possibility of such damages.
  25. *
  26. * Sun Microsystems, Inc.
  27. * 2550 Garcia Avenue
  28. * Mountain View, California 94043
  29. */
  30. #include <sys/cdefs.h>
  31. /*
  32. * xdr.c, Generic XDR routines implementation.
  33. *
  34. * Copyright (C) 1986, Sun Microsystems, Inc.
  35. *
  36. * These are the "generic" xdr routines used to serialize and de-serialize
  37. * most common data items. See xdr.h for more info on the interface to
  38. * xdr.
  39. */
  40. #include <sys/param.h>
  41. #include <sys/systm.h>
  42. #include <sys/kernel.h>
  43. #include <sys/malloc.h>
  44. #include <sys/module.h>
  45. #include <rpc/rpc.h>
  46. #include <rpc/rpc_com.h>
  47. #include <rpc/types.h>
  48. #include <rpc/xdr.h>
  49. typedef quad_t longlong_t; /* ANSI long long type */
  50. typedef u_quad_t u_longlong_t; /* ANSI unsigned long long type */
  51. /*
  52. * constants specific to the xdr "protocol"
  53. */
  54. #define XDR_FALSE ((long) 0)
  55. #define XDR_TRUE ((long) 1)
  56. MALLOC_DEFINE(M_RPC, "rpc", "Remote Procedure Call");
  57. /*
  58. * for unit alignment
  59. */
  60. static const char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
  61. /*
  62. * Free a data structure using XDR
  63. * Not a filter, but a convenient utility nonetheless
  64. */
  65. void
  66. xdr_free(xdrproc_t proc, void *objp)
  67. {
  68. XDR x;
  69. x.x_op = XDR_FREE;
  70. (*proc)(&x, objp);
  71. }
  72. /*
  73. * XDR nothing
  74. */
  75. bool_t
  76. xdr_void(void)
  77. {
  78. return (TRUE);
  79. }
  80. /*
  81. * XDR integers
  82. */
  83. bool_t
  84. xdr_int(XDR *xdrs, int *ip)
  85. {
  86. long l;
  87. switch (xdrs->x_op) {
  88. case XDR_ENCODE:
  89. l = (long) *ip;
  90. return (XDR_PUTLONG(xdrs, &l));
  91. case XDR_DECODE:
  92. if (!XDR_GETLONG(xdrs, &l)) {
  93. return (FALSE);
  94. }
  95. *ip = (int) l;
  96. return (TRUE);
  97. case XDR_FREE:
  98. return (TRUE);
  99. }
  100. /* NOTREACHED */
  101. return (FALSE);
  102. }
  103. /*
  104. * XDR unsigned integers
  105. */
  106. bool_t
  107. xdr_u_int(XDR *xdrs, u_int *up)
  108. {
  109. u_long l;
  110. switch (xdrs->x_op) {
  111. case XDR_ENCODE:
  112. l = (u_long) *up;
  113. return (XDR_PUTLONG(xdrs, (long *)&l));
  114. case XDR_DECODE:
  115. if (!XDR_GETLONG(xdrs, (long *)&l)) {
  116. return (FALSE);
  117. }
  118. *up = (u_int) l;
  119. return (TRUE);
  120. case XDR_FREE:
  121. return (TRUE);
  122. }
  123. /* NOTREACHED */
  124. return (FALSE);
  125. }
  126. /*
  127. * XDR long integers
  128. * same as xdr_u_long - open coded to save a proc call!
  129. */
  130. bool_t
  131. xdr_long(XDR *xdrs, long *lp)
  132. {
  133. switch (xdrs->x_op) {
  134. case XDR_ENCODE:
  135. return (XDR_PUTLONG(xdrs, lp));
  136. case XDR_DECODE:
  137. return (XDR_GETLONG(xdrs, lp));
  138. case XDR_FREE:
  139. return (TRUE);
  140. }
  141. /* NOTREACHED */
  142. return (FALSE);
  143. }
  144. /*
  145. * XDR unsigned long integers
  146. * same as xdr_long - open coded to save a proc call!
  147. */
  148. bool_t
  149. xdr_u_long(XDR *xdrs, u_long *ulp)
  150. {
  151. switch (xdrs->x_op) {
  152. case XDR_ENCODE:
  153. return (XDR_PUTLONG(xdrs, (long *)ulp));
  154. case XDR_DECODE:
  155. return (XDR_GETLONG(xdrs, (long *)ulp));
  156. case XDR_FREE:
  157. return (TRUE);
  158. }
  159. /* NOTREACHED */
  160. return (FALSE);
  161. }
  162. /*
  163. * XDR 32-bit integers
  164. * same as xdr_uint32_t - open coded to save a proc call!
  165. */
  166. bool_t
  167. xdr_int32_t(XDR *xdrs, int32_t *int32_p)
  168. {
  169. long l;
  170. switch (xdrs->x_op) {
  171. case XDR_ENCODE:
  172. l = (long) *int32_p;
  173. return (XDR_PUTLONG(xdrs, &l));
  174. case XDR_DECODE:
  175. if (!XDR_GETLONG(xdrs, &l)) {
  176. return (FALSE);
  177. }
  178. *int32_p = (int32_t) l;
  179. return (TRUE);
  180. case XDR_FREE:
  181. return (TRUE);
  182. }
  183. /* NOTREACHED */
  184. return (FALSE);
  185. }
  186. /*
  187. * XDR unsigned 32-bit integers
  188. * same as xdr_int32_t - open coded to save a proc call!
  189. */
  190. bool_t
  191. xdr_uint32_t(XDR *xdrs, uint32_t *uint32_p)
  192. {
  193. u_long l;
  194. switch (xdrs->x_op) {
  195. case XDR_ENCODE:
  196. l = (u_long) *uint32_p;
  197. return (XDR_PUTLONG(xdrs, (long *)&l));
  198. case XDR_DECODE:
  199. if (!XDR_GETLONG(xdrs, (long *)&l)) {
  200. return (FALSE);
  201. }
  202. *uint32_p = (uint32_t) l;
  203. return (TRUE);
  204. case XDR_FREE:
  205. return (TRUE);
  206. }
  207. /* NOTREACHED */
  208. return (FALSE);
  209. }
  210. /*
  211. * XDR short integers
  212. */
  213. bool_t
  214. xdr_short(XDR *xdrs, short *sp)
  215. {
  216. long l;
  217. switch (xdrs->x_op) {
  218. case XDR_ENCODE:
  219. l = (long) *sp;
  220. return (XDR_PUTLONG(xdrs, &l));
  221. case XDR_DECODE:
  222. if (!XDR_GETLONG(xdrs, &l)) {
  223. return (FALSE);
  224. }
  225. *sp = (short) l;
  226. return (TRUE);
  227. case XDR_FREE:
  228. return (TRUE);
  229. }
  230. /* NOTREACHED */
  231. return (FALSE);
  232. }
  233. /*
  234. * XDR unsigned short integers
  235. */
  236. bool_t
  237. xdr_u_short(XDR *xdrs, u_short *usp)
  238. {
  239. u_long l;
  240. switch (xdrs->x_op) {
  241. case XDR_ENCODE:
  242. l = (u_long) *usp;
  243. return (XDR_PUTLONG(xdrs, (long *)&l));
  244. case XDR_DECODE:
  245. if (!XDR_GETLONG(xdrs, (long *)&l)) {
  246. return (FALSE);
  247. }
  248. *usp = (u_short) l;
  249. return (TRUE);
  250. case XDR_FREE:
  251. return (TRUE);
  252. }
  253. /* NOTREACHED */
  254. return (FALSE);
  255. }
  256. /*
  257. * XDR 16-bit integers
  258. */
  259. bool_t
  260. xdr_int16_t(XDR *xdrs, int16_t *int16_p)
  261. {
  262. long l;
  263. switch (xdrs->x_op) {
  264. case XDR_ENCODE:
  265. l = (long) *int16_p;
  266. return (XDR_PUTLONG(xdrs, &l));
  267. case XDR_DECODE:
  268. if (!XDR_GETLONG(xdrs, &l)) {
  269. return (FALSE);
  270. }
  271. *int16_p = (int16_t) l;
  272. return (TRUE);
  273. case XDR_FREE:
  274. return (TRUE);
  275. }
  276. /* NOTREACHED */
  277. return (FALSE);
  278. }
  279. /*
  280. * XDR unsigned 16-bit integers
  281. */
  282. bool_t
  283. xdr_uint16_t(XDR *xdrs, uint16_t *uint16_p)
  284. {
  285. u_long l;
  286. switch (xdrs->x_op) {
  287. case XDR_ENCODE:
  288. l = (u_long) *uint16_p;
  289. return (XDR_PUTLONG(xdrs, (long *)&l));
  290. case XDR_DECODE:
  291. if (!XDR_GETLONG(xdrs, (long *)&l)) {
  292. return (FALSE);
  293. }
  294. *uint16_p = (uint16_t) l;
  295. return (TRUE);
  296. case XDR_FREE:
  297. return (TRUE);
  298. }
  299. /* NOTREACHED */
  300. return (FALSE);
  301. }
  302. /*
  303. * XDR a char
  304. */
  305. bool_t
  306. xdr_char(XDR *xdrs, char *cp)
  307. {
  308. u_int i;
  309. i = *((unsigned char *)cp);
  310. if (!xdr_u_int(xdrs, &i)) {
  311. return (FALSE);
  312. }
  313. *((unsigned char *)cp) = i;
  314. return (TRUE);
  315. }
  316. /*
  317. * XDR an unsigned char
  318. */
  319. bool_t
  320. xdr_u_char(XDR *xdrs, u_char *cp)
  321. {
  322. u_int u;
  323. u = (*cp);
  324. if (!xdr_u_int(xdrs, &u)) {
  325. return (FALSE);
  326. }
  327. *cp = u;
  328. return (TRUE);
  329. }
  330. /*
  331. * XDR booleans
  332. */
  333. bool_t
  334. xdr_bool(XDR *xdrs, bool_t *bp)
  335. {
  336. long lb;
  337. switch (xdrs->x_op) {
  338. case XDR_ENCODE:
  339. lb = *bp ? XDR_TRUE : XDR_FALSE;
  340. return (XDR_PUTLONG(xdrs, &lb));
  341. case XDR_DECODE:
  342. if (!XDR_GETLONG(xdrs, &lb)) {
  343. return (FALSE);
  344. }
  345. *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
  346. return (TRUE);
  347. case XDR_FREE:
  348. return (TRUE);
  349. }
  350. /* NOTREACHED */
  351. return (FALSE);
  352. }
  353. /*
  354. * XDR enumerations
  355. */
  356. bool_t
  357. xdr_enum(XDR *xdrs, enum_t *ep)
  358. {
  359. enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
  360. /*
  361. * enums are treated as ints
  362. */
  363. /* LINTED */ if (sizeof (enum sizecheck) == sizeof (long)) {
  364. return (xdr_long(xdrs, (long *)(void *)ep));
  365. } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (int)) {
  366. return (xdr_int(xdrs, (int *)(void *)ep));
  367. } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (short)) {
  368. return (xdr_short(xdrs, (short *)(void *)ep));
  369. } else {
  370. return (FALSE);
  371. }
  372. }
  373. /*
  374. * XDR opaque data
  375. * Allows the specification of a fixed size sequence of opaque bytes.
  376. * cp points to the opaque object and cnt gives the byte length.
  377. */
  378. bool_t
  379. xdr_opaque(XDR *xdrs, caddr_t cp, u_int cnt)
  380. {
  381. u_int rndup;
  382. static int crud[BYTES_PER_XDR_UNIT];
  383. /*
  384. * if no data we are done
  385. */
  386. if (cnt == 0)
  387. return (TRUE);
  388. /*
  389. * round byte count to full xdr units
  390. */
  391. rndup = cnt % BYTES_PER_XDR_UNIT;
  392. if (rndup > 0)
  393. rndup = BYTES_PER_XDR_UNIT - rndup;
  394. if (xdrs->x_op == XDR_DECODE) {
  395. if (!XDR_GETBYTES(xdrs, cp, cnt)) {
  396. return (FALSE);
  397. }
  398. if (rndup == 0)
  399. return (TRUE);
  400. return (XDR_GETBYTES(xdrs, (caddr_t)(void *)crud, rndup));
  401. }
  402. if (xdrs->x_op == XDR_ENCODE) {
  403. if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
  404. return (FALSE);
  405. }
  406. if (rndup == 0)
  407. return (TRUE);
  408. return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
  409. }
  410. if (xdrs->x_op == XDR_FREE) {
  411. return (TRUE);
  412. }
  413. return (FALSE);
  414. }
  415. /*
  416. * XDR counted bytes
  417. * *cpp is a pointer to the bytes, *sizep is the count.
  418. * If *cpp is NULL maxsize bytes are allocated
  419. */
  420. bool_t
  421. xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
  422. {
  423. char *sp = *cpp; /* sp is the actual string pointer */
  424. u_int nodesize;
  425. bool_t ret, allocated = FALSE;
  426. /*
  427. * first deal with the length since xdr bytes are counted
  428. */
  429. if (! xdr_u_int(xdrs, sizep)) {
  430. return (FALSE);
  431. }
  432. nodesize = *sizep;
  433. if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
  434. return (FALSE);
  435. }
  436. /*
  437. * now deal with the actual bytes
  438. */
  439. switch (xdrs->x_op) {
  440. case XDR_DECODE:
  441. if (nodesize == 0) {
  442. return (TRUE);
  443. }
  444. if (sp == NULL) {
  445. *cpp = sp = mem_alloc(nodesize);
  446. allocated = TRUE;
  447. }
  448. if (sp == NULL) {
  449. printf("xdr_bytes: out of memory");
  450. return (FALSE);
  451. }
  452. /* FALLTHROUGH */
  453. case XDR_ENCODE:
  454. ret = xdr_opaque(xdrs, sp, nodesize);
  455. if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
  456. if (allocated == TRUE) {
  457. mem_free(sp, nodesize);
  458. *cpp = NULL;
  459. }
  460. }
  461. return (ret);
  462. case XDR_FREE:
  463. if (sp != NULL) {
  464. mem_free(sp, nodesize);
  465. *cpp = NULL;
  466. }
  467. return (TRUE);
  468. }
  469. /* NOTREACHED */
  470. return (FALSE);
  471. }
  472. /*
  473. * Implemented here due to commonality of the object.
  474. */
  475. bool_t
  476. xdr_netobj(XDR *xdrs, struct netobj *np)
  477. {
  478. return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
  479. }
  480. /*
  481. * XDR a descriminated union
  482. * Support routine for discriminated unions.
  483. * You create an array of xdrdiscrim structures, terminated with
  484. * an entry with a null procedure pointer. The routine gets
  485. * the discriminant value and then searches the array of xdrdiscrims
  486. * looking for that value. It calls the procedure given in the xdrdiscrim
  487. * to handle the discriminant. If there is no specific routine a default
  488. * routine may be called.
  489. * If there is no specific or default routine an error is returned.
  490. */
  491. bool_t
  492. xdr_union(XDR *xdrs,
  493. enum_t *dscmp, /* enum to decide which arm to work on */
  494. char *unp, /* the union itself */
  495. const struct xdr_discrim *choices, /* [value, xdr proc] for each arm */
  496. xdrproc_t dfault) /* default xdr routine */
  497. {
  498. enum_t dscm;
  499. /*
  500. * we deal with the discriminator; it's an enum
  501. */
  502. if (! xdr_enum(xdrs, dscmp)) {
  503. return (FALSE);
  504. }
  505. dscm = *dscmp;
  506. /*
  507. * search choices for a value that matches the discriminator.
  508. * if we find one, execute the xdr routine for that value.
  509. */
  510. for (; choices->proc != NULL_xdrproc_t; choices++) {
  511. if (choices->value == dscm)
  512. return ((*(choices->proc))(xdrs, unp));
  513. }
  514. /*
  515. * no match - execute the default xdr routine if there is one
  516. */
  517. return ((dfault == NULL_xdrproc_t) ? FALSE :
  518. (*dfault)(xdrs, unp));
  519. }
  520. /*
  521. * Non-portable xdr primitives.
  522. * Care should be taken when moving these routines to new architectures.
  523. */
  524. /*
  525. * XDR null terminated ASCII strings
  526. * xdr_string deals with "C strings" - arrays of bytes that are
  527. * terminated by a NULL character. The parameter cpp references a
  528. * pointer to storage; If the pointer is null, then the necessary
  529. * storage is allocated. The last parameter is the max allowed length
  530. * of the string as specified by a protocol.
  531. */
  532. bool_t
  533. xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
  534. {
  535. char *sp = *cpp; /* sp is the actual string pointer */
  536. u_int size;
  537. u_int nodesize;
  538. bool_t ret, allocated = FALSE;
  539. /*
  540. * first deal with the length since xdr strings are counted-strings
  541. */
  542. switch (xdrs->x_op) {
  543. case XDR_FREE:
  544. if (sp == NULL) {
  545. return(TRUE); /* already free */
  546. }
  547. /* FALLTHROUGH */
  548. case XDR_ENCODE:
  549. size = strlen(sp);
  550. break;
  551. case XDR_DECODE:
  552. break;
  553. }
  554. if (! xdr_u_int(xdrs, &size)) {
  555. return (FALSE);
  556. }
  557. if (size > maxsize) {
  558. return (FALSE);
  559. }
  560. nodesize = size + 1;
  561. /*
  562. * now deal with the actual bytes
  563. */
  564. switch (xdrs->x_op) {
  565. case XDR_DECODE:
  566. if (nodesize == 0) {
  567. return (TRUE);
  568. }
  569. if (sp == NULL) {
  570. *cpp = sp = mem_alloc(nodesize);
  571. allocated = TRUE;
  572. }
  573. if (sp == NULL) {
  574. printf("xdr_string: out of memory");
  575. return (FALSE);
  576. }
  577. sp[size] = 0;
  578. /* FALLTHROUGH */
  579. case XDR_ENCODE:
  580. ret = xdr_opaque(xdrs, sp, size);
  581. if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
  582. if (allocated == TRUE) {
  583. mem_free(sp, nodesize);
  584. *cpp = NULL;
  585. }
  586. }
  587. return (ret);
  588. case XDR_FREE:
  589. mem_free(sp, nodesize);
  590. *cpp = NULL;
  591. return (TRUE);
  592. }
  593. /* NOTREACHED */
  594. return (FALSE);
  595. }
  596. /*
  597. * Wrapper for xdr_string that can be called directly from
  598. * routines like clnt_call
  599. */
  600. bool_t
  601. xdr_wrapstring(XDR *xdrs, char **cpp)
  602. {
  603. return xdr_string(xdrs, cpp, RPC_MAXDATASIZE);
  604. }
  605. /*
  606. * NOTE: xdr_hyper(), xdr_u_hyper(), xdr_longlong_t(), and xdr_u_longlong_t()
  607. * are in the "non-portable" section because they require that a `long long'
  608. * be a 64-bit type.
  609. *
  610. * --thorpej@netbsd.org, November 30, 1999
  611. */
  612. /*
  613. * XDR 64-bit integers
  614. */
  615. bool_t
  616. xdr_int64_t(XDR *xdrs, int64_t *llp)
  617. {
  618. u_long ul[2];
  619. switch (xdrs->x_op) {
  620. case XDR_ENCODE:
  621. ul[0] = (u_long)((uint64_t)*llp >> 32) & 0xffffffff;
  622. ul[1] = (u_long)((uint64_t)*llp) & 0xffffffff;
  623. if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE)
  624. return (FALSE);
  625. return (XDR_PUTLONG(xdrs, (long *)&ul[1]));
  626. case XDR_DECODE:
  627. if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE)
  628. return (FALSE);
  629. if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE)
  630. return (FALSE);
  631. *llp = (int64_t)
  632. (((uint64_t)ul[0] << 32) | ((uint64_t)ul[1]));
  633. return (TRUE);
  634. case XDR_FREE:
  635. return (TRUE);
  636. }
  637. /* NOTREACHED */
  638. return (FALSE);
  639. }
  640. /*
  641. * XDR unsigned 64-bit integers
  642. */
  643. bool_t
  644. xdr_uint64_t(XDR *xdrs, uint64_t *ullp)
  645. {
  646. u_long ul[2];
  647. switch (xdrs->x_op) {
  648. case XDR_ENCODE:
  649. ul[0] = (u_long)(*ullp >> 32) & 0xffffffff;
  650. ul[1] = (u_long)(*ullp) & 0xffffffff;
  651. if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE)
  652. return (FALSE);
  653. return (XDR_PUTLONG(xdrs, (long *)&ul[1]));
  654. case XDR_DECODE:
  655. if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE)
  656. return (FALSE);
  657. if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE)
  658. return (FALSE);
  659. *ullp = (uint64_t)
  660. (((uint64_t)ul[0] << 32) | ((uint64_t)ul[1]));
  661. return (TRUE);
  662. case XDR_FREE:
  663. return (TRUE);
  664. }
  665. /* NOTREACHED */
  666. return (FALSE);
  667. }
  668. /*
  669. * XDR hypers
  670. */
  671. bool_t
  672. xdr_hyper(XDR *xdrs, longlong_t *llp)
  673. {
  674. /*
  675. * Don't bother open-coding this; it's a fair amount of code. Just
  676. * call xdr_int64_t().
  677. */
  678. return (xdr_int64_t(xdrs, (int64_t *)llp));
  679. }
  680. /*
  681. * XDR unsigned hypers
  682. */
  683. bool_t
  684. xdr_u_hyper(XDR *xdrs, u_longlong_t *ullp)
  685. {
  686. /*
  687. * Don't bother open-coding this; it's a fair amount of code. Just
  688. * call xdr_uint64_t().
  689. */
  690. return (xdr_uint64_t(xdrs, (uint64_t *)ullp));
  691. }
  692. /*
  693. * XDR longlong_t's
  694. */
  695. bool_t
  696. xdr_longlong_t(XDR *xdrs, longlong_t *llp)
  697. {
  698. /*
  699. * Don't bother open-coding this; it's a fair amount of code. Just
  700. * call xdr_int64_t().
  701. */
  702. return (xdr_int64_t(xdrs, (int64_t *)llp));
  703. }
  704. /*
  705. * XDR u_longlong_t's
  706. */
  707. bool_t
  708. xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp)
  709. {
  710. /*
  711. * Don't bother open-coding this; it's a fair amount of code. Just
  712. * call xdr_uint64_t().
  713. */
  714. return (xdr_uint64_t(xdrs, (uint64_t *)ullp));
  715. }
  716. /*
  717. * Kernel module glue
  718. */
  719. static int
  720. xdr_modevent(module_t mod, int type, void *data)
  721. {
  722. return (0);
  723. }
  724. static moduledata_t xdr_mod = {
  725. "xdr",
  726. xdr_modevent,
  727. NULL,
  728. };
  729. DECLARE_MODULE(xdr, xdr_mod, SI_SUB_VFS, SI_ORDER_ANY);
  730. MODULE_VERSION(xdr, 1);