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