1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * XDR support for nfsd/protocol version 3. 4 * 5 * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de> 6 * 7 * 2003-08-09 Jamie Lokier: Use htonl() for nanoseconds, not htons()! 8 */ 9 10 #include <linux/namei.h> 11 #include <linux/sunrpc/svc_xprt.h> 12 #include "xdr3.h" 13 #include "auth.h" 14 #include "netns.h" 15 #include "vfs.h" 16 17 /* 18 * Force construction of an empty post-op attr 19 */ 20 static const struct svc_fh nfs3svc_null_fh = { 21 .fh_no_wcc = true, 22 }; 23 24 /* 25 * time_delta. {1, 0} means the server is accurate only 26 * to the nearest second. 27 */ 28 static const struct timespec64 nfs3svc_time_delta = { 29 .tv_sec = 1, 30 .tv_nsec = 0, 31 }; 32 33 /* 34 * Mapping of S_IF* types to NFS file types 35 */ 36 static const u32 nfs3_ftypes[] = { 37 NF3NON, NF3FIFO, NF3CHR, NF3BAD, 38 NF3DIR, NF3BAD, NF3BLK, NF3BAD, 39 NF3REG, NF3BAD, NF3LNK, NF3BAD, 40 NF3SOCK, NF3BAD, NF3LNK, NF3BAD, 41 }; 42 43 44 /* 45 * Basic NFSv3 data types (RFC 1813 Sections 2.5 and 2.6) 46 */ 47 48 static __be32 * 49 encode_nfstime3(__be32 *p, const struct timespec64 *time) 50 { 51 *p++ = cpu_to_be32((u32)time->tv_sec); 52 *p++ = cpu_to_be32(time->tv_nsec); 53 54 return p; 55 } 56 57 static bool 58 svcxdr_decode_nfstime3(struct xdr_stream *xdr, struct timespec64 *timep) 59 { 60 __be32 *p; 61 62 p = xdr_inline_decode(xdr, XDR_UNIT * 2); 63 if (!p) 64 return false; 65 timep->tv_sec = be32_to_cpup(p++); 66 timep->tv_nsec = be32_to_cpup(p); 67 68 return true; 69 } 70 71 /** 72 * svcxdr_decode_nfs_fh3 - Decode an NFSv3 file handle 73 * @xdr: XDR stream positioned at an undecoded NFSv3 FH 74 * @fhp: OUT: filled-in server file handle 75 * 76 * Return values: 77 * %false: The encoded file handle was not valid 78 * %true: @fhp has been initialized 79 */ 80 bool 81 svcxdr_decode_nfs_fh3(struct xdr_stream *xdr, struct svc_fh *fhp) 82 { 83 __be32 *p; 84 u32 size; 85 86 if (xdr_stream_decode_u32(xdr, &size) < 0) 87 return false; 88 if (size == 0 || size > NFS3_FHSIZE) 89 return false; 90 p = xdr_inline_decode(xdr, size); 91 if (!p) 92 return false; 93 fh_init(fhp, NFS3_FHSIZE); 94 fhp->fh_handle.fh_size = size; 95 memcpy(&fhp->fh_handle.fh_raw, p, size); 96 97 return true; 98 } 99 100 /** 101 * svcxdr_encode_nfsstat3 - Encode an NFSv3 status code 102 * @xdr: XDR stream 103 * @status: status value to encode 104 * 105 * Return values: 106 * %false: Send buffer space was exhausted 107 * %true: Success 108 */ 109 bool 110 svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status) 111 { 112 __be32 *p; 113 114 p = xdr_reserve_space(xdr, sizeof(status)); 115 if (!p) 116 return false; 117 *p = status; 118 119 return true; 120 } 121 122 static bool 123 svcxdr_encode_nfs_fh3(struct xdr_stream *xdr, const struct svc_fh *fhp) 124 { 125 u32 size = fhp->fh_handle.fh_size; 126 __be32 *p; 127 128 p = xdr_reserve_space(xdr, XDR_UNIT + size); 129 if (!p) 130 return false; 131 *p++ = cpu_to_be32(size); 132 if (size) 133 p[XDR_QUADLEN(size) - 1] = 0; 134 memcpy(p, &fhp->fh_handle.fh_raw, size); 135 136 return true; 137 } 138 139 static bool 140 svcxdr_encode_post_op_fh3(struct xdr_stream *xdr, const struct svc_fh *fhp) 141 { 142 if (xdr_stream_encode_item_present(xdr) < 0) 143 return false; 144 if (!svcxdr_encode_nfs_fh3(xdr, fhp)) 145 return false; 146 147 return true; 148 } 149 150 static bool 151 svcxdr_encode_cookieverf3(struct xdr_stream *xdr, const __be32 *verf) 152 { 153 __be32 *p; 154 155 p = xdr_reserve_space(xdr, NFS3_COOKIEVERFSIZE); 156 if (!p) 157 return false; 158 memcpy(p, verf, NFS3_COOKIEVERFSIZE); 159 160 return true; 161 } 162 163 static bool 164 svcxdr_encode_writeverf3(struct xdr_stream *xdr, const __be32 *verf) 165 { 166 __be32 *p; 167 168 p = xdr_reserve_space(xdr, NFS3_WRITEVERFSIZE); 169 if (!p) 170 return false; 171 memcpy(p, verf, NFS3_WRITEVERFSIZE); 172 173 return true; 174 } 175 176 static bool 177 svcxdr_decode_filename3(struct xdr_stream *xdr, char **name, unsigned int *len) 178 { 179 u32 size, i; 180 __be32 *p; 181 char *c; 182 183 if (xdr_stream_decode_u32(xdr, &size) < 0) 184 return false; 185 if (size == 0 || size > NFS3_MAXNAMLEN) 186 return false; 187 p = xdr_inline_decode(xdr, size); 188 if (!p) 189 return false; 190 191 *len = size; 192 *name = (char *)p; 193 for (i = 0, c = *name; i < size; i++, c++) { 194 if (*c == '\0' || *c == '/') 195 return false; 196 } 197 198 return true; 199 } 200 201 static bool 202 svcxdr_decode_diropargs3(struct xdr_stream *xdr, struct svc_fh *fhp, 203 char **name, unsigned int *len) 204 { 205 return svcxdr_decode_nfs_fh3(xdr, fhp) && 206 svcxdr_decode_filename3(xdr, name, len); 207 } 208 209 static bool 210 svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr, 211 struct iattr *iap) 212 { 213 u32 set_it; 214 215 iap->ia_valid = 0; 216 217 if (xdr_stream_decode_bool(xdr, &set_it) < 0) 218 return false; 219 if (set_it) { 220 u32 mode; 221 222 if (xdr_stream_decode_u32(xdr, &mode) < 0) 223 return false; 224 iap->ia_valid |= ATTR_MODE; 225 iap->ia_mode = mode; 226 } 227 if (xdr_stream_decode_bool(xdr, &set_it) < 0) 228 return false; 229 if (set_it) { 230 u32 uid; 231 232 if (xdr_stream_decode_u32(xdr, &uid) < 0) 233 return false; 234 iap->ia_uid = make_kuid(nfsd_user_namespace(rqstp), uid); 235 if (uid_valid(iap->ia_uid)) 236 iap->ia_valid |= ATTR_UID; 237 } 238 if (xdr_stream_decode_bool(xdr, &set_it) < 0) 239 return false; 240 if (set_it) { 241 u32 gid; 242 243 if (xdr_stream_decode_u32(xdr, &gid) < 0) 244 return false; 245 iap->ia_gid = make_kgid(nfsd_user_namespace(rqstp), gid); 246 if (gid_valid(iap->ia_gid)) 247 iap->ia_valid |= ATTR_GID; 248 } 249 if (xdr_stream_decode_bool(xdr, &set_it) < 0) 250 return false; 251 if (set_it) { 252 u64 newsize; 253 254 if (xdr_stream_decode_u64(xdr, &newsize) < 0) 255 return false; 256 iap->ia_valid |= ATTR_SIZE; 257 iap->ia_size = min_t(u64, newsize, NFS_OFFSET_MAX); 258 } 259 if (xdr_stream_decode_u32(xdr, &set_it) < 0) 260 return false; 261 switch (set_it) { 262 case DONT_CHANGE: 263 break; 264 case SET_TO_SERVER_TIME: 265 iap->ia_valid |= ATTR_ATIME; 266 break; 267 case SET_TO_CLIENT_TIME: 268 if (!svcxdr_decode_nfstime3(xdr, &iap->ia_atime)) 269 return false; 270 iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET; 271 break; 272 default: 273 return false; 274 } 275 if (xdr_stream_decode_u32(xdr, &set_it) < 0) 276 return false; 277 switch (set_it) { 278 case DONT_CHANGE: 279 break; 280 case SET_TO_SERVER_TIME: 281 iap->ia_valid |= ATTR_MTIME; 282 break; 283 case SET_TO_CLIENT_TIME: 284 if (!svcxdr_decode_nfstime3(xdr, &iap->ia_mtime)) 285 return false; 286 iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET; 287 break; 288 default: 289 return false; 290 } 291 292 return true; 293 } 294 295 static bool 296 svcxdr_decode_sattrguard3(struct xdr_stream *xdr, struct nfsd3_sattrargs *args) 297 { 298 __be32 *p; 299 u32 check; 300 301 if (xdr_stream_decode_bool(xdr, &check) < 0) 302 return false; 303 if (check) { 304 p = xdr_inline_decode(xdr, XDR_UNIT * 2); 305 if (!p) 306 return false; 307 args->check_guard = 1; 308 args->guardtime = be32_to_cpup(p); 309 } else 310 args->check_guard = 0; 311 312 return true; 313 } 314 315 static bool 316 svcxdr_decode_specdata3(struct xdr_stream *xdr, struct nfsd3_mknodargs *args) 317 { 318 __be32 *p; 319 320 p = xdr_inline_decode(xdr, XDR_UNIT * 2); 321 if (!p) 322 return false; 323 args->major = be32_to_cpup(p++); 324 args->minor = be32_to_cpup(p); 325 326 return true; 327 } 328 329 static bool 330 svcxdr_decode_devicedata3(struct svc_rqst *rqstp, struct xdr_stream *xdr, 331 struct nfsd3_mknodargs *args) 332 { 333 return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs) && 334 svcxdr_decode_specdata3(xdr, args); 335 } 336 337 static bool 338 svcxdr_encode_fattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr, 339 const struct svc_fh *fhp, const struct kstat *stat) 340 { 341 struct user_namespace *userns = nfsd_user_namespace(rqstp); 342 __be32 *p; 343 u64 fsid; 344 345 p = xdr_reserve_space(xdr, XDR_UNIT * 21); 346 if (!p) 347 return false; 348 349 *p++ = cpu_to_be32(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]); 350 *p++ = cpu_to_be32((u32)(stat->mode & S_IALLUGO)); 351 *p++ = cpu_to_be32((u32)stat->nlink); 352 *p++ = cpu_to_be32((u32)from_kuid_munged(userns, stat->uid)); 353 *p++ = cpu_to_be32((u32)from_kgid_munged(userns, stat->gid)); 354 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) 355 p = xdr_encode_hyper(p, (u64)NFS3_MAXPATHLEN); 356 else 357 p = xdr_encode_hyper(p, (u64)stat->size); 358 359 /* used */ 360 p = xdr_encode_hyper(p, ((u64)stat->blocks) << 9); 361 362 /* rdev */ 363 *p++ = cpu_to_be32((u32)MAJOR(stat->rdev)); 364 *p++ = cpu_to_be32((u32)MINOR(stat->rdev)); 365 366 switch(fsid_source(fhp)) { 367 case FSIDSOURCE_FSID: 368 fsid = (u64)fhp->fh_export->ex_fsid; 369 break; 370 case FSIDSOURCE_UUID: 371 fsid = ((u64 *)fhp->fh_export->ex_uuid)[0]; 372 fsid ^= ((u64 *)fhp->fh_export->ex_uuid)[1]; 373 break; 374 default: 375 fsid = (u64)huge_encode_dev(fhp->fh_dentry->d_sb->s_dev); 376 } 377 p = xdr_encode_hyper(p, fsid); 378 379 /* fileid */ 380 p = xdr_encode_hyper(p, stat->ino); 381 382 p = encode_nfstime3(p, &stat->atime); 383 p = encode_nfstime3(p, &stat->mtime); 384 encode_nfstime3(p, &stat->ctime); 385 386 return true; 387 } 388 389 static bool 390 svcxdr_encode_wcc_attr(struct xdr_stream *xdr, const struct svc_fh *fhp) 391 { 392 __be32 *p; 393 394 p = xdr_reserve_space(xdr, XDR_UNIT * 6); 395 if (!p) 396 return false; 397 p = xdr_encode_hyper(p, (u64)fhp->fh_pre_size); 398 p = encode_nfstime3(p, &fhp->fh_pre_mtime); 399 encode_nfstime3(p, &fhp->fh_pre_ctime); 400 401 return true; 402 } 403 404 static bool 405 svcxdr_encode_pre_op_attr(struct xdr_stream *xdr, const struct svc_fh *fhp) 406 { 407 if (!fhp->fh_pre_saved) { 408 if (xdr_stream_encode_item_absent(xdr) < 0) 409 return false; 410 return true; 411 } 412 413 if (xdr_stream_encode_item_present(xdr) < 0) 414 return false; 415 return svcxdr_encode_wcc_attr(xdr, fhp); 416 } 417 418 /** 419 * svcxdr_encode_post_op_attr - Encode NFSv3 post-op attributes 420 * @rqstp: Context of a completed RPC transaction 421 * @xdr: XDR stream 422 * @fhp: File handle to encode 423 * 424 * Return values: 425 * %false: Send buffer space was exhausted 426 * %true: Success 427 */ 428 bool 429 svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, 430 const struct svc_fh *fhp) 431 { 432 struct dentry *dentry = fhp->fh_dentry; 433 struct kstat stat; 434 435 /* 436 * The inode may be NULL if the call failed because of a 437 * stale file handle. In this case, no attributes are 438 * returned. 439 */ 440 if (fhp->fh_no_wcc || !dentry || !d_really_is_positive(dentry)) 441 goto no_post_op_attrs; 442 if (fh_getattr(fhp, &stat) != nfs_ok) 443 goto no_post_op_attrs; 444 445 if (xdr_stream_encode_item_present(xdr) < 0) 446 return false; 447 lease_get_mtime(d_inode(dentry), &stat.mtime); 448 if (!svcxdr_encode_fattr3(rqstp, xdr, fhp, &stat)) 449 return false; 450 451 return true; 452 453 no_post_op_attrs: 454 return xdr_stream_encode_item_absent(xdr) > 0; 455 } 456 457 /* 458 * Encode weak cache consistency data 459 */ 460 static bool 461 svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr, 462 const struct svc_fh *fhp) 463 { 464 struct dentry *dentry = fhp->fh_dentry; 465 466 if (!dentry || !d_really_is_positive(dentry) || !fhp->fh_post_saved) 467 goto neither; 468 469 /* before */ 470 if (!svcxdr_encode_pre_op_attr(xdr, fhp)) 471 return false; 472 473 /* after */ 474 if (xdr_stream_encode_item_present(xdr) < 0) 475 return false; 476 if (!svcxdr_encode_fattr3(rqstp, xdr, fhp, &fhp->fh_post_attr)) 477 return false; 478 479 return true; 480 481 neither: 482 if (xdr_stream_encode_item_absent(xdr) < 0) 483 return false; 484 if (!svcxdr_encode_post_op_attr(rqstp, xdr, fhp)) 485 return false; 486 487 return true; 488 } 489 490 static bool fs_supports_change_attribute(struct super_block *sb) 491 { 492 return sb->s_flags & SB_I_VERSION || sb->s_export_op->fetch_iversion; 493 } 494 495 /* 496 * Fill in the pre_op attr for the wcc data 497 */ 498 void fill_pre_wcc(struct svc_fh *fhp) 499 { 500 struct inode *inode; 501 struct kstat stat; 502 bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE); 503 504 if (fhp->fh_no_wcc || fhp->fh_pre_saved) 505 return; 506 inode = d_inode(fhp->fh_dentry); 507 if (fs_supports_change_attribute(inode->i_sb) || !v4) { 508 __be32 err = fh_getattr(fhp, &stat); 509 510 if (err) { 511 /* Grab the times from inode anyway */ 512 stat.mtime = inode->i_mtime; 513 stat.ctime = inode->i_ctime; 514 stat.size = inode->i_size; 515 } 516 fhp->fh_pre_mtime = stat.mtime; 517 fhp->fh_pre_ctime = stat.ctime; 518 fhp->fh_pre_size = stat.size; 519 } 520 if (v4) 521 fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode); 522 523 fhp->fh_pre_saved = true; 524 } 525 526 /* 527 * Fill in the post_op attr for the wcc data 528 */ 529 void fill_post_wcc(struct svc_fh *fhp) 530 { 531 bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE); 532 struct inode *inode = d_inode(fhp->fh_dentry); 533 534 if (fhp->fh_no_wcc) 535 return; 536 537 if (fhp->fh_post_saved) 538 printk("nfsd: inode locked twice during operation.\n"); 539 540 fhp->fh_post_saved = true; 541 542 if (fs_supports_change_attribute(inode->i_sb) || !v4) { 543 __be32 err = fh_getattr(fhp, &fhp->fh_post_attr); 544 545 if (err) { 546 fhp->fh_post_saved = false; 547 fhp->fh_post_attr.ctime = inode->i_ctime; 548 } 549 } 550 if (v4) 551 fhp->fh_post_change = 552 nfsd4_change_attribute(&fhp->fh_post_attr, inode); 553 } 554 555 /* 556 * XDR decode functions 557 */ 558 559 int 560 nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 561 { 562 struct nfsd_fhandle *args = rqstp->rq_argp; 563 564 return svcxdr_decode_nfs_fh3(xdr, &args->fh); 565 } 566 567 int 568 nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 569 { 570 struct nfsd3_sattrargs *args = rqstp->rq_argp; 571 572 return svcxdr_decode_nfs_fh3(xdr, &args->fh) && 573 svcxdr_decode_sattr3(rqstp, xdr, &args->attrs) && 574 svcxdr_decode_sattrguard3(xdr, args); 575 } 576 577 int 578 nfs3svc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 579 { 580 struct nfsd3_diropargs *args = rqstp->rq_argp; 581 582 return svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len); 583 } 584 585 int 586 nfs3svc_decode_accessargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 587 { 588 struct nfsd3_accessargs *args = rqstp->rq_argp; 589 590 if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) 591 return 0; 592 if (xdr_stream_decode_u32(xdr, &args->access) < 0) 593 return 0; 594 595 return 1; 596 } 597 598 int 599 nfs3svc_decode_readargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 600 { 601 struct nfsd3_readargs *args = rqstp->rq_argp; 602 603 if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) 604 return 0; 605 if (xdr_stream_decode_u64(xdr, &args->offset) < 0) 606 return 0; 607 if (xdr_stream_decode_u32(xdr, &args->count) < 0) 608 return 0; 609 610 return 1; 611 } 612 613 int 614 nfs3svc_decode_writeargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 615 { 616 struct nfsd3_writeargs *args = rqstp->rq_argp; 617 u32 max_blocksize = svc_max_payload(rqstp); 618 619 if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) 620 return 0; 621 if (xdr_stream_decode_u64(xdr, &args->offset) < 0) 622 return 0; 623 if (xdr_stream_decode_u32(xdr, &args->count) < 0) 624 return 0; 625 if (xdr_stream_decode_u32(xdr, &args->stable) < 0) 626 return 0; 627 628 /* opaque data */ 629 if (xdr_stream_decode_u32(xdr, &args->len) < 0) 630 return 0; 631 632 /* request sanity */ 633 if (args->count != args->len) 634 return 0; 635 if (args->count > max_blocksize) { 636 args->count = max_blocksize; 637 args->len = max_blocksize; 638 } 639 if (!xdr_stream_subsegment(xdr, &args->payload, args->count)) 640 return 0; 641 642 return 1; 643 } 644 645 int 646 nfs3svc_decode_createargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 647 { 648 struct nfsd3_createargs *args = rqstp->rq_argp; 649 650 if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len)) 651 return 0; 652 if (xdr_stream_decode_u32(xdr, &args->createmode) < 0) 653 return 0; 654 switch (args->createmode) { 655 case NFS3_CREATE_UNCHECKED: 656 case NFS3_CREATE_GUARDED: 657 return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); 658 case NFS3_CREATE_EXCLUSIVE: 659 args->verf = xdr_inline_decode(xdr, NFS3_CREATEVERFSIZE); 660 if (!args->verf) 661 return 0; 662 break; 663 default: 664 return 0; 665 } 666 return 1; 667 } 668 669 int 670 nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 671 { 672 struct nfsd3_createargs *args = rqstp->rq_argp; 673 674 return svcxdr_decode_diropargs3(xdr, &args->fh, 675 &args->name, &args->len) && 676 svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); 677 } 678 679 int 680 nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 681 { 682 struct nfsd3_symlinkargs *args = rqstp->rq_argp; 683 struct kvec *head = rqstp->rq_arg.head; 684 struct kvec *tail = rqstp->rq_arg.tail; 685 size_t remaining; 686 687 if (!svcxdr_decode_diropargs3(xdr, &args->ffh, &args->fname, &args->flen)) 688 return 0; 689 if (!svcxdr_decode_sattr3(rqstp, xdr, &args->attrs)) 690 return 0; 691 if (xdr_stream_decode_u32(xdr, &args->tlen) < 0) 692 return 0; 693 694 /* request sanity */ 695 remaining = head->iov_len + rqstp->rq_arg.page_len + tail->iov_len; 696 remaining -= xdr_stream_pos(xdr); 697 if (remaining < xdr_align_size(args->tlen)) 698 return 0; 699 700 args->first.iov_base = xdr->p; 701 args->first.iov_len = head->iov_len - xdr_stream_pos(xdr); 702 703 return 1; 704 } 705 706 int 707 nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 708 { 709 struct nfsd3_mknodargs *args = rqstp->rq_argp; 710 711 if (!svcxdr_decode_diropargs3(xdr, &args->fh, &args->name, &args->len)) 712 return 0; 713 if (xdr_stream_decode_u32(xdr, &args->ftype) < 0) 714 return 0; 715 switch (args->ftype) { 716 case NF3CHR: 717 case NF3BLK: 718 return svcxdr_decode_devicedata3(rqstp, xdr, args); 719 case NF3SOCK: 720 case NF3FIFO: 721 return svcxdr_decode_sattr3(rqstp, xdr, &args->attrs); 722 case NF3REG: 723 case NF3DIR: 724 case NF3LNK: 725 /* Valid XDR but illegal file types */ 726 break; 727 default: 728 return 0; 729 } 730 731 return 1; 732 } 733 734 int 735 nfs3svc_decode_renameargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 736 { 737 struct nfsd3_renameargs *args = rqstp->rq_argp; 738 739 return svcxdr_decode_diropargs3(xdr, &args->ffh, 740 &args->fname, &args->flen) && 741 svcxdr_decode_diropargs3(xdr, &args->tfh, 742 &args->tname, &args->tlen); 743 } 744 745 int 746 nfs3svc_decode_linkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 747 { 748 struct nfsd3_linkargs *args = rqstp->rq_argp; 749 750 return svcxdr_decode_nfs_fh3(xdr, &args->ffh) && 751 svcxdr_decode_diropargs3(xdr, &args->tfh, 752 &args->tname, &args->tlen); 753 } 754 755 int 756 nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 757 { 758 struct nfsd3_readdirargs *args = rqstp->rq_argp; 759 760 if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) 761 return 0; 762 if (xdr_stream_decode_u64(xdr, &args->cookie) < 0) 763 return 0; 764 args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); 765 if (!args->verf) 766 return 0; 767 if (xdr_stream_decode_u32(xdr, &args->count) < 0) 768 return 0; 769 770 return 1; 771 } 772 773 int 774 nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 775 { 776 struct nfsd3_readdirargs *args = rqstp->rq_argp; 777 u32 dircount; 778 779 if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) 780 return 0; 781 if (xdr_stream_decode_u64(xdr, &args->cookie) < 0) 782 return 0; 783 args->verf = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); 784 if (!args->verf) 785 return 0; 786 /* dircount is ignored */ 787 if (xdr_stream_decode_u32(xdr, &dircount) < 0) 788 return 0; 789 if (xdr_stream_decode_u32(xdr, &args->count) < 0) 790 return 0; 791 792 return 1; 793 } 794 795 int 796 nfs3svc_decode_commitargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) 797 { 798 struct nfsd3_commitargs *args = rqstp->rq_argp; 799 800 if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) 801 return 0; 802 if (xdr_stream_decode_u64(xdr, &args->offset) < 0) 803 return 0; 804 if (xdr_stream_decode_u32(xdr, &args->count) < 0) 805 return 0; 806 807 return 1; 808 } 809 810 /* 811 * XDR encode functions 812 */ 813 814 /* GETATTR */ 815 int 816 nfs3svc_encode_getattrres(struct svc_rqst *rqstp, __be32 *p) 817 { 818 struct xdr_stream *xdr = &rqstp->rq_res_stream; 819 struct nfsd3_attrstat *resp = rqstp->rq_resp; 820 821 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 822 return 0; 823 switch (resp->status) { 824 case nfs_ok: 825 lease_get_mtime(d_inode(resp->fh.fh_dentry), &resp->stat.mtime); 826 if (!svcxdr_encode_fattr3(rqstp, xdr, &resp->fh, &resp->stat)) 827 return 0; 828 break; 829 } 830 831 return 1; 832 } 833 834 /* SETATTR, REMOVE, RMDIR */ 835 int 836 nfs3svc_encode_wccstat(struct svc_rqst *rqstp, __be32 *p) 837 { 838 struct xdr_stream *xdr = &rqstp->rq_res_stream; 839 struct nfsd3_attrstat *resp = rqstp->rq_resp; 840 841 return svcxdr_encode_nfsstat3(xdr, resp->status) && 842 svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh); 843 } 844 845 /* LOOKUP */ 846 int nfs3svc_encode_lookupres(struct svc_rqst *rqstp, __be32 *p) 847 { 848 struct xdr_stream *xdr = &rqstp->rq_res_stream; 849 struct nfsd3_diropres *resp = rqstp->rq_resp; 850 851 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 852 return 0; 853 switch (resp->status) { 854 case nfs_ok: 855 if (!svcxdr_encode_nfs_fh3(xdr, &resp->fh)) 856 return 0; 857 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 858 return 0; 859 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) 860 return 0; 861 break; 862 default: 863 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) 864 return 0; 865 } 866 867 return 1; 868 } 869 870 /* ACCESS */ 871 int 872 nfs3svc_encode_accessres(struct svc_rqst *rqstp, __be32 *p) 873 { 874 struct xdr_stream *xdr = &rqstp->rq_res_stream; 875 struct nfsd3_accessres *resp = rqstp->rq_resp; 876 877 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 878 return 0; 879 switch (resp->status) { 880 case nfs_ok: 881 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 882 return 0; 883 if (xdr_stream_encode_u32(xdr, resp->access) < 0) 884 return 0; 885 break; 886 default: 887 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 888 return 0; 889 } 890 891 return 1; 892 } 893 894 /* READLINK */ 895 int 896 nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p) 897 { 898 struct xdr_stream *xdr = &rqstp->rq_res_stream; 899 struct nfsd3_readlinkres *resp = rqstp->rq_resp; 900 struct kvec *head = rqstp->rq_res.head; 901 902 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 903 return 0; 904 switch (resp->status) { 905 case nfs_ok: 906 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 907 return 0; 908 if (xdr_stream_encode_u32(xdr, resp->len) < 0) 909 return 0; 910 xdr_write_pages(xdr, resp->pages, 0, resp->len); 911 if (svc_encode_result_payload(rqstp, head->iov_len, resp->len) < 0) 912 return 0; 913 break; 914 default: 915 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 916 return 0; 917 } 918 919 return 1; 920 } 921 922 /* READ */ 923 int 924 nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p) 925 { 926 struct xdr_stream *xdr = &rqstp->rq_res_stream; 927 struct nfsd3_readres *resp = rqstp->rq_resp; 928 struct kvec *head = rqstp->rq_res.head; 929 930 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 931 return 0; 932 switch (resp->status) { 933 case nfs_ok: 934 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 935 return 0; 936 if (xdr_stream_encode_u32(xdr, resp->count) < 0) 937 return 0; 938 if (xdr_stream_encode_bool(xdr, resp->eof) < 0) 939 return 0; 940 if (xdr_stream_encode_u32(xdr, resp->count) < 0) 941 return 0; 942 xdr_write_pages(xdr, resp->pages, rqstp->rq_res.page_base, 943 resp->count); 944 if (svc_encode_result_payload(rqstp, head->iov_len, resp->count) < 0) 945 return 0; 946 break; 947 default: 948 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 949 return 0; 950 } 951 952 return 1; 953 } 954 955 /* WRITE */ 956 int 957 nfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p) 958 { 959 struct xdr_stream *xdr = &rqstp->rq_res_stream; 960 struct nfsd3_writeres *resp = rqstp->rq_resp; 961 962 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 963 return 0; 964 switch (resp->status) { 965 case nfs_ok: 966 if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) 967 return 0; 968 if (xdr_stream_encode_u32(xdr, resp->count) < 0) 969 return 0; 970 if (xdr_stream_encode_u32(xdr, resp->committed) < 0) 971 return 0; 972 if (!svcxdr_encode_writeverf3(xdr, resp->verf)) 973 return 0; 974 break; 975 default: 976 if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) 977 return 0; 978 } 979 980 return 1; 981 } 982 983 /* CREATE, MKDIR, SYMLINK, MKNOD */ 984 int 985 nfs3svc_encode_createres(struct svc_rqst *rqstp, __be32 *p) 986 { 987 struct xdr_stream *xdr = &rqstp->rq_res_stream; 988 struct nfsd3_diropres *resp = rqstp->rq_resp; 989 990 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 991 return 0; 992 switch (resp->status) { 993 case nfs_ok: 994 if (!svcxdr_encode_post_op_fh3(xdr, &resp->fh)) 995 return 0; 996 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 997 return 0; 998 if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh)) 999 return 0; 1000 break; 1001 default: 1002 if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->dirfh)) 1003 return 0; 1004 } 1005 1006 return 1; 1007 } 1008 1009 /* RENAME */ 1010 int 1011 nfs3svc_encode_renameres(struct svc_rqst *rqstp, __be32 *p) 1012 { 1013 struct xdr_stream *xdr = &rqstp->rq_res_stream; 1014 struct nfsd3_renameres *resp = rqstp->rq_resp; 1015 1016 return svcxdr_encode_nfsstat3(xdr, resp->status) && 1017 svcxdr_encode_wcc_data(rqstp, xdr, &resp->ffh) && 1018 svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh); 1019 } 1020 1021 /* LINK */ 1022 int 1023 nfs3svc_encode_linkres(struct svc_rqst *rqstp, __be32 *p) 1024 { 1025 struct xdr_stream *xdr = &rqstp->rq_res_stream; 1026 struct nfsd3_linkres *resp = rqstp->rq_resp; 1027 1028 return svcxdr_encode_nfsstat3(xdr, resp->status) && 1029 svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh) && 1030 svcxdr_encode_wcc_data(rqstp, xdr, &resp->tfh); 1031 } 1032 1033 /* READDIR */ 1034 int 1035 nfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p) 1036 { 1037 struct xdr_stream *xdr = &rqstp->rq_res_stream; 1038 struct nfsd3_readdirres *resp = rqstp->rq_resp; 1039 struct xdr_buf *dirlist = &resp->dirlist; 1040 1041 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 1042 return 0; 1043 switch (resp->status) { 1044 case nfs_ok: 1045 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 1046 return 0; 1047 if (!svcxdr_encode_cookieverf3(xdr, resp->verf)) 1048 return 0; 1049 xdr_write_pages(xdr, dirlist->pages, 0, dirlist->len); 1050 /* no more entries */ 1051 if (xdr_stream_encode_item_absent(xdr) < 0) 1052 return 0; 1053 if (xdr_stream_encode_bool(xdr, resp->common.err == nfserr_eof) < 0) 1054 return 0; 1055 break; 1056 default: 1057 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) 1058 return 0; 1059 } 1060 1061 return 1; 1062 } 1063 1064 static __be32 1065 compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp, 1066 const char *name, int namlen, u64 ino) 1067 { 1068 struct svc_export *exp; 1069 struct dentry *dparent, *dchild; 1070 __be32 rv = nfserr_noent; 1071 1072 dparent = cd->fh.fh_dentry; 1073 exp = cd->fh.fh_export; 1074 1075 if (isdotent(name, namlen)) { 1076 if (namlen == 2) { 1077 dchild = dget_parent(dparent); 1078 /* 1079 * Don't return filehandle for ".." if we're at 1080 * the filesystem or export root: 1081 */ 1082 if (dchild == dparent) 1083 goto out; 1084 if (dparent == exp->ex_path.dentry) 1085 goto out; 1086 } else 1087 dchild = dget(dparent); 1088 } else 1089 dchild = lookup_positive_unlocked(name, dparent, namlen); 1090 if (IS_ERR(dchild)) 1091 return rv; 1092 if (d_mountpoint(dchild)) 1093 goto out; 1094 if (dchild->d_inode->i_ino != ino) 1095 goto out; 1096 rv = fh_compose(fhp, exp, dchild, &cd->fh); 1097 out: 1098 dput(dchild); 1099 return rv; 1100 } 1101 1102 /** 1103 * nfs3svc_encode_cookie3 - Encode a directory offset cookie 1104 * @resp: readdir result context 1105 * @offset: offset cookie to encode 1106 * 1107 * The buffer space for the offset cookie has already been reserved 1108 * by svcxdr_encode_entry3_common(). 1109 */ 1110 void nfs3svc_encode_cookie3(struct nfsd3_readdirres *resp, u64 offset) 1111 { 1112 __be64 cookie = cpu_to_be64(offset); 1113 1114 if (!resp->cookie_offset) 1115 return; 1116 write_bytes_to_xdr_buf(&resp->dirlist, resp->cookie_offset, &cookie, 1117 sizeof(cookie)); 1118 resp->cookie_offset = 0; 1119 } 1120 1121 static bool 1122 svcxdr_encode_entry3_common(struct nfsd3_readdirres *resp, const char *name, 1123 int namlen, loff_t offset, u64 ino) 1124 { 1125 struct xdr_buf *dirlist = &resp->dirlist; 1126 struct xdr_stream *xdr = &resp->xdr; 1127 1128 if (xdr_stream_encode_item_present(xdr) < 0) 1129 return false; 1130 /* fileid */ 1131 if (xdr_stream_encode_u64(xdr, ino) < 0) 1132 return false; 1133 /* name */ 1134 if (xdr_stream_encode_opaque(xdr, name, min(namlen, NFS3_MAXNAMLEN)) < 0) 1135 return false; 1136 /* cookie */ 1137 resp->cookie_offset = dirlist->len; 1138 if (xdr_stream_encode_u64(xdr, NFS_OFFSET_MAX) < 0) 1139 return false; 1140 1141 return true; 1142 } 1143 1144 /** 1145 * nfs3svc_encode_entry3 - encode one NFSv3 READDIR entry 1146 * @data: directory context 1147 * @name: name of the object to be encoded 1148 * @namlen: length of that name, in bytes 1149 * @offset: the offset of the previous entry 1150 * @ino: the fileid of this entry 1151 * @d_type: unused 1152 * 1153 * Return values: 1154 * %0: Entry was successfully encoded. 1155 * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err 1156 * 1157 * On exit, the following fields are updated: 1158 * - resp->xdr 1159 * - resp->common.err 1160 * - resp->cookie_offset 1161 */ 1162 int nfs3svc_encode_entry3(void *data, const char *name, int namlen, 1163 loff_t offset, u64 ino, unsigned int d_type) 1164 { 1165 struct readdir_cd *ccd = data; 1166 struct nfsd3_readdirres *resp = container_of(ccd, 1167 struct nfsd3_readdirres, 1168 common); 1169 unsigned int starting_length = resp->dirlist.len; 1170 1171 /* The offset cookie for the previous entry */ 1172 nfs3svc_encode_cookie3(resp, offset); 1173 1174 if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino)) 1175 goto out_toosmall; 1176 1177 xdr_commit_encode(&resp->xdr); 1178 resp->common.err = nfs_ok; 1179 return 0; 1180 1181 out_toosmall: 1182 resp->cookie_offset = 0; 1183 resp->common.err = nfserr_toosmall; 1184 resp->dirlist.len = starting_length; 1185 return -EINVAL; 1186 } 1187 1188 static bool 1189 svcxdr_encode_entry3_plus(struct nfsd3_readdirres *resp, const char *name, 1190 int namlen, u64 ino) 1191 { 1192 struct xdr_stream *xdr = &resp->xdr; 1193 struct svc_fh *fhp = &resp->scratch; 1194 bool result; 1195 1196 result = false; 1197 fh_init(fhp, NFS3_FHSIZE); 1198 if (compose_entry_fh(resp, fhp, name, namlen, ino) != nfs_ok) 1199 goto out_noattrs; 1200 1201 if (!svcxdr_encode_post_op_attr(resp->rqstp, xdr, fhp)) 1202 goto out; 1203 if (!svcxdr_encode_post_op_fh3(xdr, fhp)) 1204 goto out; 1205 result = true; 1206 1207 out: 1208 fh_put(fhp); 1209 return result; 1210 1211 out_noattrs: 1212 if (xdr_stream_encode_item_absent(xdr) < 0) 1213 return false; 1214 if (xdr_stream_encode_item_absent(xdr) < 0) 1215 return false; 1216 return true; 1217 } 1218 1219 /** 1220 * nfs3svc_encode_entryplus3 - encode one NFSv3 READDIRPLUS entry 1221 * @data: directory context 1222 * @name: name of the object to be encoded 1223 * @namlen: length of that name, in bytes 1224 * @offset: the offset of the previous entry 1225 * @ino: the fileid of this entry 1226 * @d_type: unused 1227 * 1228 * Return values: 1229 * %0: Entry was successfully encoded. 1230 * %-EINVAL: An encoding problem occured, secondary status code in resp->common.err 1231 * 1232 * On exit, the following fields are updated: 1233 * - resp->xdr 1234 * - resp->common.err 1235 * - resp->cookie_offset 1236 */ 1237 int nfs3svc_encode_entryplus3(void *data, const char *name, int namlen, 1238 loff_t offset, u64 ino, unsigned int d_type) 1239 { 1240 struct readdir_cd *ccd = data; 1241 struct nfsd3_readdirres *resp = container_of(ccd, 1242 struct nfsd3_readdirres, 1243 common); 1244 unsigned int starting_length = resp->dirlist.len; 1245 1246 /* The offset cookie for the previous entry */ 1247 nfs3svc_encode_cookie3(resp, offset); 1248 1249 if (!svcxdr_encode_entry3_common(resp, name, namlen, offset, ino)) 1250 goto out_toosmall; 1251 if (!svcxdr_encode_entry3_plus(resp, name, namlen, ino)) 1252 goto out_toosmall; 1253 1254 xdr_commit_encode(&resp->xdr); 1255 resp->common.err = nfs_ok; 1256 return 0; 1257 1258 out_toosmall: 1259 resp->cookie_offset = 0; 1260 resp->common.err = nfserr_toosmall; 1261 resp->dirlist.len = starting_length; 1262 return -EINVAL; 1263 } 1264 1265 static bool 1266 svcxdr_encode_fsstat3resok(struct xdr_stream *xdr, 1267 const struct nfsd3_fsstatres *resp) 1268 { 1269 const struct kstatfs *s = &resp->stats; 1270 u64 bs = s->f_bsize; 1271 __be32 *p; 1272 1273 p = xdr_reserve_space(xdr, XDR_UNIT * 13); 1274 if (!p) 1275 return false; 1276 p = xdr_encode_hyper(p, bs * s->f_blocks); /* total bytes */ 1277 p = xdr_encode_hyper(p, bs * s->f_bfree); /* free bytes */ 1278 p = xdr_encode_hyper(p, bs * s->f_bavail); /* user available bytes */ 1279 p = xdr_encode_hyper(p, s->f_files); /* total inodes */ 1280 p = xdr_encode_hyper(p, s->f_ffree); /* free inodes */ 1281 p = xdr_encode_hyper(p, s->f_ffree); /* user available inodes */ 1282 *p = cpu_to_be32(resp->invarsec); /* mean unchanged time */ 1283 1284 return true; 1285 } 1286 1287 /* FSSTAT */ 1288 int 1289 nfs3svc_encode_fsstatres(struct svc_rqst *rqstp, __be32 *p) 1290 { 1291 struct xdr_stream *xdr = &rqstp->rq_res_stream; 1292 struct nfsd3_fsstatres *resp = rqstp->rq_resp; 1293 1294 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 1295 return 0; 1296 switch (resp->status) { 1297 case nfs_ok: 1298 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) 1299 return 0; 1300 if (!svcxdr_encode_fsstat3resok(xdr, resp)) 1301 return 0; 1302 break; 1303 default: 1304 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) 1305 return 0; 1306 } 1307 1308 return 1; 1309 } 1310 1311 static bool 1312 svcxdr_encode_fsinfo3resok(struct xdr_stream *xdr, 1313 const struct nfsd3_fsinfores *resp) 1314 { 1315 __be32 *p; 1316 1317 p = xdr_reserve_space(xdr, XDR_UNIT * 12); 1318 if (!p) 1319 return false; 1320 *p++ = cpu_to_be32(resp->f_rtmax); 1321 *p++ = cpu_to_be32(resp->f_rtpref); 1322 *p++ = cpu_to_be32(resp->f_rtmult); 1323 *p++ = cpu_to_be32(resp->f_wtmax); 1324 *p++ = cpu_to_be32(resp->f_wtpref); 1325 *p++ = cpu_to_be32(resp->f_wtmult); 1326 *p++ = cpu_to_be32(resp->f_dtpref); 1327 p = xdr_encode_hyper(p, resp->f_maxfilesize); 1328 p = encode_nfstime3(p, &nfs3svc_time_delta); 1329 *p = cpu_to_be32(resp->f_properties); 1330 1331 return true; 1332 } 1333 1334 /* FSINFO */ 1335 int 1336 nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p) 1337 { 1338 struct xdr_stream *xdr = &rqstp->rq_res_stream; 1339 struct nfsd3_fsinfores *resp = rqstp->rq_resp; 1340 1341 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 1342 return 0; 1343 switch (resp->status) { 1344 case nfs_ok: 1345 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) 1346 return 0; 1347 if (!svcxdr_encode_fsinfo3resok(xdr, resp)) 1348 return 0; 1349 break; 1350 default: 1351 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) 1352 return 0; 1353 } 1354 1355 return 1; 1356 } 1357 1358 static bool 1359 svcxdr_encode_pathconf3resok(struct xdr_stream *xdr, 1360 const struct nfsd3_pathconfres *resp) 1361 { 1362 __be32 *p; 1363 1364 p = xdr_reserve_space(xdr, XDR_UNIT * 6); 1365 if (!p) 1366 return false; 1367 *p++ = cpu_to_be32(resp->p_link_max); 1368 *p++ = cpu_to_be32(resp->p_name_max); 1369 p = xdr_encode_bool(p, resp->p_no_trunc); 1370 p = xdr_encode_bool(p, resp->p_chown_restricted); 1371 p = xdr_encode_bool(p, resp->p_case_insensitive); 1372 xdr_encode_bool(p, resp->p_case_preserving); 1373 1374 return true; 1375 } 1376 1377 /* PATHCONF */ 1378 int 1379 nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p) 1380 { 1381 struct xdr_stream *xdr = &rqstp->rq_res_stream; 1382 struct nfsd3_pathconfres *resp = rqstp->rq_resp; 1383 1384 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 1385 return 0; 1386 switch (resp->status) { 1387 case nfs_ok: 1388 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) 1389 return 0; 1390 if (!svcxdr_encode_pathconf3resok(xdr, resp)) 1391 return 0; 1392 break; 1393 default: 1394 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh)) 1395 return 0; 1396 } 1397 1398 return 1; 1399 } 1400 1401 /* COMMIT */ 1402 int 1403 nfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p) 1404 { 1405 struct xdr_stream *xdr = &rqstp->rq_res_stream; 1406 struct nfsd3_commitres *resp = rqstp->rq_resp; 1407 1408 if (!svcxdr_encode_nfsstat3(xdr, resp->status)) 1409 return 0; 1410 switch (resp->status) { 1411 case nfs_ok: 1412 if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) 1413 return 0; 1414 if (!svcxdr_encode_writeverf3(xdr, resp->verf)) 1415 return 0; 1416 break; 1417 default: 1418 if (!svcxdr_encode_wcc_data(rqstp, xdr, &resp->fh)) 1419 return 0; 1420 } 1421 1422 return 1; 1423 } 1424 1425 /* 1426 * XDR release functions 1427 */ 1428 void 1429 nfs3svc_release_fhandle(struct svc_rqst *rqstp) 1430 { 1431 struct nfsd3_attrstat *resp = rqstp->rq_resp; 1432 1433 fh_put(&resp->fh); 1434 } 1435 1436 void 1437 nfs3svc_release_fhandle2(struct svc_rqst *rqstp) 1438 { 1439 struct nfsd3_fhandle_pair *resp = rqstp->rq_resp; 1440 1441 fh_put(&resp->fh1); 1442 fh_put(&resp->fh2); 1443 } 1444