xdr.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * linux/fs/lockd/xdr.c
  3. *
  4. * XDR support for lockd and the lock client.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #include <linux/nfs.h>
  11. #include <linux/sunrpc/xdr.h>
  12. #include <linux/sunrpc/clnt.h>
  13. #include <linux/sunrpc/svc.h>
  14. #include <linux/sunrpc/stats.h>
  15. #include <linux/lockd/lockd.h>
  16. #define NLMDBG_FACILITY NLMDBG_XDR
  17. static inline loff_t
  18. s32_to_loff_t(__s32 offset)
  19. {
  20. return (loff_t)offset;
  21. }
  22. static inline __s32
  23. loff_t_to_s32(loff_t offset)
  24. {
  25. __s32 res;
  26. if (offset >= NLM_OFFSET_MAX)
  27. res = NLM_OFFSET_MAX;
  28. else if (offset <= -NLM_OFFSET_MAX)
  29. res = -NLM_OFFSET_MAX;
  30. else
  31. res = offset;
  32. return res;
  33. }
  34. /*
  35. * XDR functions for basic NLM types
  36. */
  37. static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c)
  38. {
  39. unsigned int len;
  40. len = ntohl(*p++);
  41. if(len==0)
  42. {
  43. c->len=4;
  44. memset(c->data, 0, 4); /* hockeypux brain damage */
  45. }
  46. else if(len<=NLM_MAXCOOKIELEN)
  47. {
  48. c->len=len;
  49. memcpy(c->data, p, len);
  50. p+=XDR_QUADLEN(len);
  51. }
  52. else
  53. {
  54. dprintk("lockd: bad cookie size %d (only cookies under "
  55. "%d bytes are supported.)\n",
  56. len, NLM_MAXCOOKIELEN);
  57. return NULL;
  58. }
  59. return p;
  60. }
  61. static inline __be32 *
  62. nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
  63. {
  64. *p++ = htonl(c->len);
  65. memcpy(p, c->data, c->len);
  66. p+=XDR_QUADLEN(c->len);
  67. return p;
  68. }
  69. static __be32 *
  70. nlm_decode_fh(__be32 *p, struct nfs_fh *f)
  71. {
  72. unsigned int len;
  73. if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
  74. dprintk("lockd: bad fhandle size %d (should be %d)\n",
  75. len, NFS2_FHSIZE);
  76. return NULL;
  77. }
  78. f->size = NFS2_FHSIZE;
  79. memset(f->data, 0, sizeof(f->data));
  80. memcpy(f->data, p, NFS2_FHSIZE);
  81. return p + XDR_QUADLEN(NFS2_FHSIZE);
  82. }
  83. static inline __be32 *
  84. nlm_encode_fh(__be32 *p, struct nfs_fh *f)
  85. {
  86. *p++ = htonl(NFS2_FHSIZE);
  87. memcpy(p, f->data, NFS2_FHSIZE);
  88. return p + XDR_QUADLEN(NFS2_FHSIZE);
  89. }
  90. /*
  91. * Encode and decode owner handle
  92. */
  93. static inline __be32 *
  94. nlm_decode_oh(__be32 *p, struct xdr_netobj *oh)
  95. {
  96. return xdr_decode_netobj(p, oh);
  97. }
  98. static inline __be32 *
  99. nlm_encode_oh(__be32 *p, struct xdr_netobj *oh)
  100. {
  101. return xdr_encode_netobj(p, oh);
  102. }
  103. static __be32 *
  104. nlm_decode_lock(__be32 *p, struct nlm_lock *lock)
  105. {
  106. struct file_lock *fl = &lock->fl;
  107. s32 start, len, end;
  108. if (!(p = xdr_decode_string_inplace(p, &lock->caller,
  109. &lock->len,
  110. NLM_MAXSTRLEN))
  111. || !(p = nlm_decode_fh(p, &lock->fh))
  112. || !(p = nlm_decode_oh(p, &lock->oh)))
  113. return NULL;
  114. lock->svid = ntohl(*p++);
  115. locks_init_lock(fl);
  116. fl->fl_owner = current->files;
  117. fl->fl_pid = (pid_t)lock->svid;
  118. fl->fl_flags = FL_POSIX;
  119. fl->fl_type = F_RDLCK; /* as good as anything else */
  120. start = ntohl(*p++);
  121. len = ntohl(*p++);
  122. end = start + len - 1;
  123. fl->fl_start = s32_to_loff_t(start);
  124. if (len == 0 || end < 0)
  125. fl->fl_end = OFFSET_MAX;
  126. else
  127. fl->fl_end = s32_to_loff_t(end);
  128. return p;
  129. }
  130. /*
  131. * Encode a lock as part of an NLM call
  132. */
  133. static __be32 *
  134. nlm_encode_lock(__be32 *p, struct nlm_lock *lock)
  135. {
  136. struct file_lock *fl = &lock->fl;
  137. __s32 start, len;
  138. if (!(p = xdr_encode_string(p, lock->caller))
  139. || !(p = nlm_encode_fh(p, &lock->fh))
  140. || !(p = nlm_encode_oh(p, &lock->oh)))
  141. return NULL;
  142. if (fl->fl_start > NLM_OFFSET_MAX
  143. || (fl->fl_end > NLM_OFFSET_MAX && fl->fl_end != OFFSET_MAX))
  144. return NULL;
  145. start = loff_t_to_s32(fl->fl_start);
  146. if (fl->fl_end == OFFSET_MAX)
  147. len = 0;
  148. else
  149. len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
  150. *p++ = htonl(lock->svid);
  151. *p++ = htonl(start);
  152. *p++ = htonl(len);
  153. return p;
  154. }
  155. /*
  156. * Encode result of a TEST/TEST_MSG call
  157. */
  158. static __be32 *
  159. nlm_encode_testres(__be32 *p, struct nlm_res *resp)
  160. {
  161. s32 start, len;
  162. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  163. return NULL;
  164. *p++ = resp->status;
  165. if (resp->status == nlm_lck_denied) {
  166. struct file_lock *fl = &resp->lock.fl;
  167. *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
  168. *p++ = htonl(resp->lock.svid);
  169. /* Encode owner handle. */
  170. if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
  171. return NULL;
  172. start = loff_t_to_s32(fl->fl_start);
  173. if (fl->fl_end == OFFSET_MAX)
  174. len = 0;
  175. else
  176. len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
  177. *p++ = htonl(start);
  178. *p++ = htonl(len);
  179. }
  180. return p;
  181. }
  182. /*
  183. * First, the server side XDR functions
  184. */
  185. int
  186. nlmsvc_decode_testargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  187. {
  188. u32 exclusive;
  189. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  190. return 0;
  191. exclusive = ntohl(*p++);
  192. if (!(p = nlm_decode_lock(p, &argp->lock)))
  193. return 0;
  194. if (exclusive)
  195. argp->lock.fl.fl_type = F_WRLCK;
  196. return xdr_argsize_check(rqstp, p);
  197. }
  198. int
  199. nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  200. {
  201. if (!(p = nlm_encode_testres(p, resp)))
  202. return 0;
  203. return xdr_ressize_check(rqstp, p);
  204. }
  205. int
  206. nlmsvc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  207. {
  208. u32 exclusive;
  209. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  210. return 0;
  211. argp->block = ntohl(*p++);
  212. exclusive = ntohl(*p++);
  213. if (!(p = nlm_decode_lock(p, &argp->lock)))
  214. return 0;
  215. if (exclusive)
  216. argp->lock.fl.fl_type = F_WRLCK;
  217. argp->reclaim = ntohl(*p++);
  218. argp->state = ntohl(*p++);
  219. argp->monitor = 1; /* monitor client by default */
  220. return xdr_argsize_check(rqstp, p);
  221. }
  222. int
  223. nlmsvc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  224. {
  225. u32 exclusive;
  226. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  227. return 0;
  228. argp->block = ntohl(*p++);
  229. exclusive = ntohl(*p++);
  230. if (!(p = nlm_decode_lock(p, &argp->lock)))
  231. return 0;
  232. if (exclusive)
  233. argp->lock.fl.fl_type = F_WRLCK;
  234. return xdr_argsize_check(rqstp, p);
  235. }
  236. int
  237. nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  238. {
  239. if (!(p = nlm_decode_cookie(p, &argp->cookie))
  240. || !(p = nlm_decode_lock(p, &argp->lock)))
  241. return 0;
  242. argp->lock.fl.fl_type = F_UNLCK;
  243. return xdr_argsize_check(rqstp, p);
  244. }
  245. int
  246. nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  247. {
  248. struct nlm_lock *lock = &argp->lock;
  249. memset(lock, 0, sizeof(*lock));
  250. locks_init_lock(&lock->fl);
  251. lock->svid = ~(u32) 0;
  252. lock->fl.fl_pid = (pid_t)lock->svid;
  253. if (!(p = nlm_decode_cookie(p, &argp->cookie))
  254. || !(p = xdr_decode_string_inplace(p, &lock->caller,
  255. &lock->len, NLM_MAXSTRLEN))
  256. || !(p = nlm_decode_fh(p, &lock->fh))
  257. || !(p = nlm_decode_oh(p, &lock->oh)))
  258. return 0;
  259. argp->fsm_mode = ntohl(*p++);
  260. argp->fsm_access = ntohl(*p++);
  261. return xdr_argsize_check(rqstp, p);
  262. }
  263. int
  264. nlmsvc_encode_shareres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  265. {
  266. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  267. return 0;
  268. *p++ = resp->status;
  269. *p++ = xdr_zero; /* sequence argument */
  270. return xdr_ressize_check(rqstp, p);
  271. }
  272. int
  273. nlmsvc_encode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  274. {
  275. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  276. return 0;
  277. *p++ = resp->status;
  278. return xdr_ressize_check(rqstp, p);
  279. }
  280. int
  281. nlmsvc_decode_notify(struct svc_rqst *rqstp, __be32 *p, struct nlm_args *argp)
  282. {
  283. struct nlm_lock *lock = &argp->lock;
  284. if (!(p = xdr_decode_string_inplace(p, &lock->caller,
  285. &lock->len, NLM_MAXSTRLEN)))
  286. return 0;
  287. argp->state = ntohl(*p++);
  288. return xdr_argsize_check(rqstp, p);
  289. }
  290. int
  291. nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp)
  292. {
  293. if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN)))
  294. return 0;
  295. argp->state = ntohl(*p++);
  296. memcpy(&argp->priv.data, p, sizeof(argp->priv.data));
  297. p += XDR_QUADLEN(SM_PRIV_SIZE);
  298. return xdr_argsize_check(rqstp, p);
  299. }
  300. int
  301. nlmsvc_decode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  302. {
  303. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  304. return 0;
  305. resp->status = *p++;
  306. return xdr_argsize_check(rqstp, p);
  307. }
  308. int
  309. nlmsvc_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  310. {
  311. return xdr_argsize_check(rqstp, p);
  312. }
  313. int
  314. nlmsvc_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  315. {
  316. return xdr_ressize_check(rqstp, p);
  317. }
  318. /*
  319. * Now, the client side XDR functions
  320. */
  321. #ifdef NLMCLNT_SUPPORT_SHARES
  322. static int
  323. nlmclt_decode_void(struct rpc_rqst *req, u32 *p, void *ptr)
  324. {
  325. return 0;
  326. }
  327. #endif
  328. static int
  329. nlmclt_encode_testargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  330. {
  331. struct nlm_lock *lock = &argp->lock;
  332. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  333. return -EIO;
  334. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  335. if (!(p = nlm_encode_lock(p, lock)))
  336. return -EIO;
  337. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  338. return 0;
  339. }
  340. static int
  341. nlmclt_decode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  342. {
  343. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  344. return -EIO;
  345. resp->status = *p++;
  346. if (resp->status == nlm_lck_denied) {
  347. struct file_lock *fl = &resp->lock.fl;
  348. u32 excl;
  349. s32 start, len, end;
  350. memset(&resp->lock, 0, sizeof(resp->lock));
  351. locks_init_lock(fl);
  352. excl = ntohl(*p++);
  353. resp->lock.svid = ntohl(*p++);
  354. fl->fl_pid = (pid_t)resp->lock.svid;
  355. if (!(p = nlm_decode_oh(p, &resp->lock.oh)))
  356. return -EIO;
  357. fl->fl_flags = FL_POSIX;
  358. fl->fl_type = excl? F_WRLCK : F_RDLCK;
  359. start = ntohl(*p++);
  360. len = ntohl(*p++);
  361. end = start + len - 1;
  362. fl->fl_start = s32_to_loff_t(start);
  363. if (len == 0 || end < 0)
  364. fl->fl_end = OFFSET_MAX;
  365. else
  366. fl->fl_end = s32_to_loff_t(end);
  367. }
  368. return 0;
  369. }
  370. static int
  371. nlmclt_encode_lockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  372. {
  373. struct nlm_lock *lock = &argp->lock;
  374. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  375. return -EIO;
  376. *p++ = argp->block? xdr_one : xdr_zero;
  377. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  378. if (!(p = nlm_encode_lock(p, lock)))
  379. return -EIO;
  380. *p++ = argp->reclaim? xdr_one : xdr_zero;
  381. *p++ = htonl(argp->state);
  382. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  383. return 0;
  384. }
  385. static int
  386. nlmclt_encode_cancargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  387. {
  388. struct nlm_lock *lock = &argp->lock;
  389. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  390. return -EIO;
  391. *p++ = argp->block? xdr_one : xdr_zero;
  392. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  393. if (!(p = nlm_encode_lock(p, lock)))
  394. return -EIO;
  395. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  396. return 0;
  397. }
  398. static int
  399. nlmclt_encode_unlockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  400. {
  401. struct nlm_lock *lock = &argp->lock;
  402. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  403. return -EIO;
  404. if (!(p = nlm_encode_lock(p, lock)))
  405. return -EIO;
  406. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  407. return 0;
  408. }
  409. static int
  410. nlmclt_encode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  411. {
  412. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  413. return -EIO;
  414. *p++ = resp->status;
  415. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  416. return 0;
  417. }
  418. static int
  419. nlmclt_encode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  420. {
  421. if (!(p = nlm_encode_testres(p, resp)))
  422. return -EIO;
  423. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  424. return 0;
  425. }
  426. static int
  427. nlmclt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  428. {
  429. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  430. return -EIO;
  431. resp->status = *p++;
  432. return 0;
  433. }
  434. #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
  435. # error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
  436. #endif
  437. /*
  438. * Buffer requirements for NLM
  439. */
  440. #define NLM_void_sz 0
  441. #define NLM_cookie_sz 1+XDR_QUADLEN(NLM_MAXCOOKIELEN)
  442. #define NLM_caller_sz 1+XDR_QUADLEN(NLMCLNT_OHSIZE)
  443. #define NLM_owner_sz 1+XDR_QUADLEN(NLMCLNT_OHSIZE)
  444. #define NLM_fhandle_sz 1+XDR_QUADLEN(NFS2_FHSIZE)
  445. #define NLM_lock_sz 3+NLM_caller_sz+NLM_owner_sz+NLM_fhandle_sz
  446. #define NLM_holder_sz 4+NLM_owner_sz
  447. #define NLM_testargs_sz NLM_cookie_sz+1+NLM_lock_sz
  448. #define NLM_lockargs_sz NLM_cookie_sz+4+NLM_lock_sz
  449. #define NLM_cancargs_sz NLM_cookie_sz+2+NLM_lock_sz
  450. #define NLM_unlockargs_sz NLM_cookie_sz+NLM_lock_sz
  451. #define NLM_testres_sz NLM_cookie_sz+1+NLM_holder_sz
  452. #define NLM_res_sz NLM_cookie_sz+1
  453. #define NLM_norep_sz 0
  454. /*
  455. * For NLM, a void procedure really returns nothing
  456. */
  457. #define nlmclt_decode_norep NULL
  458. #define PROC(proc, argtype, restype) \
  459. [NLMPROC_##proc] = { \
  460. .p_proc = NLMPROC_##proc, \
  461. .p_encode = (kxdrproc_t) nlmclt_encode_##argtype, \
  462. .p_decode = (kxdrproc_t) nlmclt_decode_##restype, \
  463. .p_arglen = NLM_##argtype##_sz, \
  464. .p_replen = NLM_##restype##_sz, \
  465. .p_statidx = NLMPROC_##proc, \
  466. .p_name = #proc, \
  467. }
  468. static struct rpc_procinfo nlm_procedures[] = {
  469. PROC(TEST, testargs, testres),
  470. PROC(LOCK, lockargs, res),
  471. PROC(CANCEL, cancargs, res),
  472. PROC(UNLOCK, unlockargs, res),
  473. PROC(GRANTED, testargs, res),
  474. PROC(TEST_MSG, testargs, norep),
  475. PROC(LOCK_MSG, lockargs, norep),
  476. PROC(CANCEL_MSG, cancargs, norep),
  477. PROC(UNLOCK_MSG, unlockargs, norep),
  478. PROC(GRANTED_MSG, testargs, norep),
  479. PROC(TEST_RES, testres, norep),
  480. PROC(LOCK_RES, res, norep),
  481. PROC(CANCEL_RES, res, norep),
  482. PROC(UNLOCK_RES, res, norep),
  483. PROC(GRANTED_RES, res, norep),
  484. #ifdef NLMCLNT_SUPPORT_SHARES
  485. PROC(SHARE, shareargs, shareres),
  486. PROC(UNSHARE, shareargs, shareres),
  487. PROC(NM_LOCK, lockargs, res),
  488. PROC(FREE_ALL, notify, void),
  489. #endif
  490. };
  491. static struct rpc_version nlm_version1 = {
  492. .number = 1,
  493. .nrprocs = 16,
  494. .procs = nlm_procedures,
  495. };
  496. static struct rpc_version nlm_version3 = {
  497. .number = 3,
  498. .nrprocs = 24,
  499. .procs = nlm_procedures,
  500. };
  501. static struct rpc_version * nlm_versions[] = {
  502. [1] = &nlm_version1,
  503. [3] = &nlm_version3,
  504. #ifdef CONFIG_LOCKD_V4
  505. [4] = &nlm_version4,
  506. #endif
  507. };
  508. static struct rpc_stat nlm_stats;
  509. struct rpc_program nlm_program = {
  510. .name = "lockd",
  511. .number = NLM_PROGRAM,
  512. .nrvers = ARRAY_SIZE(nlm_versions),
  513. .version = nlm_versions,
  514. .stats = &nlm_stats,
  515. };
  516. #ifdef RPC_DEBUG
  517. const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
  518. {
  519. /*
  520. * We can get away with a static buffer because we're only
  521. * called with BKL held.
  522. */
  523. static char buf[2*NLM_MAXCOOKIELEN+1];
  524. unsigned int i, len = sizeof(buf);
  525. char *p = buf;
  526. len--; /* allow for trailing \0 */
  527. if (len < 3)
  528. return "???";
  529. for (i = 0 ; i < cookie->len ; i++) {
  530. if (len < 2) {
  531. strcpy(p-3, "...");
  532. break;
  533. }
  534. sprintf(p, "%02x", cookie->data[i]);
  535. p += 2;
  536. len -= 2;
  537. }
  538. *p = '\0';
  539. return buf;
  540. }
  541. #endif