1 /* 2 * Copyright (c) 1989 Jan-Simon Pendry 3 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 4 * Copyright (c) 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Jan-Simon Pendry at Imperial College, London. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * from: @(#)nfs_prot_xdr.c 8.1 (Berkeley) 6/6/93 39 * $Id: nfs_prot_xdr.c,v 1.1.1.1 1995/10/18 08:47:23 deraadt Exp $ 40 * 41 */ 42 43 #include "am.h" 44 45 46 #ifndef xdr_nfsstat 47 bool_t 48 xdr_nfsstat(xdrs, objp) 49 XDR *xdrs; 50 nfsstat *objp; 51 { 52 if (!xdr_enum(xdrs, (enum_t *)objp)) { 53 return (FALSE); 54 } 55 return (TRUE); 56 } 57 #endif /* xdr_nfsstat */ 58 59 60 61 #ifndef xdr_ftype 62 static bool_t 63 xdr_ftype(xdrs, objp) 64 XDR *xdrs; 65 ftype *objp; 66 { 67 if (!xdr_enum(xdrs, (enum_t *)objp)) { 68 return (FALSE); 69 } 70 return (TRUE); 71 } 72 #endif /* xdr_ftype */ 73 74 75 76 bool_t 77 xdr_nfs_fh(xdrs, objp) 78 XDR *xdrs; 79 nfs_fh *objp; 80 { 81 if (!xdr_opaque(xdrs, objp->data, NFS_FHSIZE)) { 82 return (FALSE); 83 } 84 return (TRUE); 85 } 86 87 88 89 90 static bool_t 91 xdr_nfstime(xdrs, objp) 92 XDR *xdrs; 93 nfstime *objp; 94 { 95 if (!xdr_u_int(xdrs, &objp->seconds)) { 96 return (FALSE); 97 } 98 if (!xdr_u_int(xdrs, &objp->useconds)) { 99 return (FALSE); 100 } 101 return (TRUE); 102 } 103 104 105 106 107 static bool_t 108 xdr_fattr(xdrs, objp) 109 XDR *xdrs; 110 fattr *objp; 111 { 112 if (!xdr_ftype(xdrs, (enum_t *) &objp->type)) { 113 return (FALSE); 114 } 115 if (!xdr_u_int(xdrs, &objp->mode)) { 116 return (FALSE); 117 } 118 if (!xdr_u_int(xdrs, &objp->nlink)) { 119 return (FALSE); 120 } 121 if (!xdr_u_int(xdrs, &objp->uid)) { 122 return (FALSE); 123 } 124 if (!xdr_u_int(xdrs, &objp->gid)) { 125 return (FALSE); 126 } 127 if (!xdr_u_int(xdrs, &objp->size)) { 128 return (FALSE); 129 } 130 if (!xdr_u_int(xdrs, &objp->blocksize)) { 131 return (FALSE); 132 } 133 if (!xdr_u_int(xdrs, &objp->rdev)) { 134 return (FALSE); 135 } 136 if (!xdr_u_int(xdrs, &objp->blocks)) { 137 return (FALSE); 138 } 139 if (!xdr_u_int(xdrs, &objp->fsid)) { 140 return (FALSE); 141 } 142 if (!xdr_u_int(xdrs, &objp->fileid)) { 143 return (FALSE); 144 } 145 if (!xdr_nfstime(xdrs, &objp->atime)) { 146 return (FALSE); 147 } 148 if (!xdr_nfstime(xdrs, &objp->mtime)) { 149 return (FALSE); 150 } 151 if (!xdr_nfstime(xdrs, &objp->ctime)) { 152 return (FALSE); 153 } 154 return (TRUE); 155 } 156 157 158 159 160 static bool_t 161 xdr_sattr(xdrs, objp) 162 XDR *xdrs; 163 sattr *objp; 164 { 165 if (!xdr_u_int(xdrs, &objp->mode)) { 166 return (FALSE); 167 } 168 if (!xdr_u_int(xdrs, &objp->uid)) { 169 return (FALSE); 170 } 171 if (!xdr_u_int(xdrs, &objp->gid)) { 172 return (FALSE); 173 } 174 if (!xdr_u_int(xdrs, &objp->size)) { 175 return (FALSE); 176 } 177 if (!xdr_nfstime(xdrs, &objp->atime)) { 178 return (FALSE); 179 } 180 if (!xdr_nfstime(xdrs, &objp->mtime)) { 181 return (FALSE); 182 } 183 return (TRUE); 184 } 185 186 187 188 189 static bool_t 190 xdr_filename(xdrs, objp) 191 XDR *xdrs; 192 filename *objp; 193 { 194 if (!xdr_string(xdrs, objp, NFS_MAXNAMLEN)) { 195 return (FALSE); 196 } 197 return (TRUE); 198 } 199 200 201 202 203 bool_t 204 xdr_nfspath(xdrs, objp) 205 XDR *xdrs; 206 nfspath *objp; 207 { 208 if (!xdr_string(xdrs, objp, NFS_MAXPATHLEN)) { 209 return (FALSE); 210 } 211 return (TRUE); 212 } 213 214 215 216 217 bool_t 218 xdr_attrstat(xdrs, objp) 219 XDR *xdrs; 220 attrstat *objp; 221 { 222 if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) { 223 return (FALSE); 224 } 225 switch (objp->status) { 226 case NFS_OK: 227 if (!xdr_fattr(xdrs, &objp->attrstat_u.attributes)) { 228 return (FALSE); 229 } 230 break; 231 } 232 return (TRUE); 233 } 234 235 236 237 238 bool_t 239 xdr_sattrargs(xdrs, objp) 240 XDR *xdrs; 241 sattrargs *objp; 242 { 243 if (!xdr_nfs_fh(xdrs, &objp->file)) { 244 return (FALSE); 245 } 246 if (!xdr_sattr(xdrs, &objp->attributes)) { 247 return (FALSE); 248 } 249 return (TRUE); 250 } 251 252 253 254 255 bool_t 256 xdr_diropargs(xdrs, objp) 257 XDR *xdrs; 258 diropargs *objp; 259 { 260 if (!xdr_nfs_fh(xdrs, &objp->dir)) { 261 return (FALSE); 262 } 263 if (!xdr_filename(xdrs, &objp->name)) { 264 return (FALSE); 265 } 266 return (TRUE); 267 } 268 269 270 271 272 bool_t 273 xdr_diropokres(xdrs, objp) 274 XDR *xdrs; 275 diropokres *objp; 276 { 277 if (!xdr_nfs_fh(xdrs, &objp->file)) { 278 return (FALSE); 279 } 280 if (!xdr_fattr(xdrs, &objp->attributes)) { 281 return (FALSE); 282 } 283 return (TRUE); 284 } 285 286 287 288 289 bool_t 290 xdr_diropres(xdrs, objp) 291 XDR *xdrs; 292 diropres *objp; 293 { 294 if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) { 295 return (FALSE); 296 } 297 switch (objp->status) { 298 case NFS_OK: 299 if (!xdr_diropokres(xdrs, &objp->diropres_u.diropres)) { 300 return (FALSE); 301 } 302 break; 303 } 304 return (TRUE); 305 } 306 307 308 309 310 bool_t 311 xdr_readlinkres(xdrs, objp) 312 XDR *xdrs; 313 readlinkres *objp; 314 { 315 if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) { 316 return (FALSE); 317 } 318 switch (objp->status) { 319 case NFS_OK: 320 if (!xdr_nfspath(xdrs, &objp->readlinkres_u.data)) { 321 return (FALSE); 322 } 323 break; 324 } 325 return (TRUE); 326 } 327 328 329 330 331 bool_t 332 xdr_readargs(xdrs, objp) 333 XDR *xdrs; 334 readargs *objp; 335 { 336 if (!xdr_nfs_fh(xdrs, &objp->file)) { 337 return (FALSE); 338 } 339 if (!xdr_u_int(xdrs, &objp->offset)) { 340 return (FALSE); 341 } 342 if (!xdr_u_int(xdrs, &objp->count)) { 343 return (FALSE); 344 } 345 if (!xdr_u_int(xdrs, &objp->totalcount)) { 346 return (FALSE); 347 } 348 return (TRUE); 349 } 350 351 352 353 354 bool_t 355 xdr_readokres(xdrs, objp) 356 XDR *xdrs; 357 readokres *objp; 358 { 359 if (!xdr_fattr(xdrs, &objp->attributes)) { 360 return (FALSE); 361 } 362 if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, NFS_MAXDATA)) { 363 return (FALSE); 364 } 365 return (TRUE); 366 } 367 368 369 370 371 bool_t 372 xdr_readres(xdrs, objp) 373 XDR *xdrs; 374 readres *objp; 375 { 376 if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) { 377 return (FALSE); 378 } 379 switch (objp->status) { 380 case NFS_OK: 381 if (!xdr_readokres(xdrs, &objp->readres_u.reply)) { 382 return (FALSE); 383 } 384 break; 385 } 386 return (TRUE); 387 } 388 389 390 391 392 bool_t 393 xdr_writeargs(xdrs, objp) 394 XDR *xdrs; 395 writeargs *objp; 396 { 397 if (!xdr_nfs_fh(xdrs, &objp->file)) { 398 return (FALSE); 399 } 400 if (!xdr_u_int(xdrs, &objp->beginoffset)) { 401 return (FALSE); 402 } 403 if (!xdr_u_int(xdrs, &objp->offset)) { 404 return (FALSE); 405 } 406 if (!xdr_u_int(xdrs, &objp->totalcount)) { 407 return (FALSE); 408 } 409 if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, NFS_MAXDATA)) { 410 return (FALSE); 411 } 412 return (TRUE); 413 } 414 415 416 417 418 bool_t 419 xdr_createargs(xdrs, objp) 420 XDR *xdrs; 421 createargs *objp; 422 { 423 if (!xdr_diropargs(xdrs, &objp->where)) { 424 return (FALSE); 425 } 426 if (!xdr_sattr(xdrs, &objp->attributes)) { 427 return (FALSE); 428 } 429 return (TRUE); 430 } 431 432 433 434 435 bool_t 436 xdr_renameargs(xdrs, objp) 437 XDR *xdrs; 438 renameargs *objp; 439 { 440 if (!xdr_diropargs(xdrs, &objp->from)) { 441 return (FALSE); 442 } 443 if (!xdr_diropargs(xdrs, &objp->to)) { 444 return (FALSE); 445 } 446 return (TRUE); 447 } 448 449 450 451 452 bool_t 453 xdr_linkargs(xdrs, objp) 454 XDR *xdrs; 455 linkargs *objp; 456 { 457 if (!xdr_nfs_fh(xdrs, &objp->from)) { 458 return (FALSE); 459 } 460 if (!xdr_diropargs(xdrs, &objp->to)) { 461 return (FALSE); 462 } 463 return (TRUE); 464 } 465 466 467 468 469 bool_t 470 xdr_symlinkargs(xdrs, objp) 471 XDR *xdrs; 472 symlinkargs *objp; 473 { 474 if (!xdr_diropargs(xdrs, &objp->from)) { 475 return (FALSE); 476 } 477 if (!xdr_nfspath(xdrs, &objp->to)) { 478 return (FALSE); 479 } 480 if (!xdr_sattr(xdrs, &objp->attributes)) { 481 return (FALSE); 482 } 483 return (TRUE); 484 } 485 486 487 488 489 static bool_t 490 xdr_nfscookie(xdrs, objp) 491 XDR *xdrs; 492 nfscookie objp; 493 { 494 if (!xdr_opaque(xdrs, objp, NFS_COOKIESIZE)) { 495 return (FALSE); 496 } 497 return (TRUE); 498 } 499 500 501 502 503 bool_t 504 xdr_readdirargs(xdrs, objp) 505 XDR *xdrs; 506 readdirargs *objp; 507 { 508 if (!xdr_nfs_fh(xdrs, &objp->dir)) { 509 return (FALSE); 510 } 511 if (!xdr_nfscookie(xdrs, objp->cookie)) { 512 return (FALSE); 513 } 514 if (!xdr_u_int(xdrs, &objp->count)) { 515 return (FALSE); 516 } 517 return (TRUE); 518 } 519 520 521 522 523 static bool_t 524 xdr_entry(xdrs, objp) 525 XDR *xdrs; 526 entry *objp; 527 { 528 if (!xdr_u_int(xdrs, &objp->fileid)) { 529 return (FALSE); 530 } 531 if (!xdr_filename(xdrs, &objp->name)) { 532 return (FALSE); 533 } 534 if (!xdr_nfscookie(xdrs, objp->cookie)) { 535 return (FALSE); 536 } 537 if (!xdr_pointer(xdrs, (char **)&objp->nextentry, sizeof(entry), xdr_entry)) { 538 return (FALSE); 539 } 540 return (TRUE); 541 } 542 543 544 545 546 static bool_t 547 xdr_dirlist(xdrs, objp) 548 XDR *xdrs; 549 dirlist *objp; 550 { 551 if (!xdr_pointer(xdrs, (char **)&objp->entries, sizeof(entry), xdr_entry)) { 552 return (FALSE); 553 } 554 if (!xdr_bool(xdrs, &objp->eof)) { 555 return (FALSE); 556 } 557 return (TRUE); 558 } 559 560 561 562 563 bool_t 564 xdr_readdirres(xdrs, objp) 565 XDR *xdrs; 566 readdirres *objp; 567 { 568 if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) { 569 return (FALSE); 570 } 571 switch (objp->status) { 572 case NFS_OK: 573 if (!xdr_dirlist(xdrs, &objp->readdirres_u.reply)) { 574 return (FALSE); 575 } 576 break; 577 } 578 return (TRUE); 579 } 580 581 582 583 584 bool_t 585 xdr_statfsokres(xdrs, objp) 586 XDR *xdrs; 587 statfsokres *objp; 588 { 589 if (!xdr_u_int(xdrs, &objp->tsize)) { 590 return (FALSE); 591 } 592 if (!xdr_u_int(xdrs, &objp->bsize)) { 593 return (FALSE); 594 } 595 if (!xdr_u_int(xdrs, &objp->blocks)) { 596 return (FALSE); 597 } 598 if (!xdr_u_int(xdrs, &objp->bfree)) { 599 return (FALSE); 600 } 601 if (!xdr_u_int(xdrs, &objp->bavail)) { 602 return (FALSE); 603 } 604 return (TRUE); 605 } 606 607 608 609 610 bool_t 611 xdr_statfsres(xdrs, objp) 612 XDR *xdrs; 613 statfsres *objp; 614 { 615 if (!xdr_nfsstat(xdrs, (enum_t *) &objp->status)) { 616 return (FALSE); 617 } 618 switch (objp->status) { 619 case NFS_OK: 620 if (!xdr_statfsokres(xdrs, &objp->statfsres_u.reply)) { 621 return (FALSE); 622 } 623 break; 624 } 625 return (TRUE); 626 } 627