Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / kernel / fs / nfs / nfs4_srv_readdir.c
blob0b16e469751b7bb0e251796b74dc07b026e9286a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/stdbool.h>
34 #include <sys/systm.h>
35 #include <sys/cred.h>
36 #include <sys/buf.h>
37 #include <sys/vfs.h>
38 #include <sys/vnode.h>
39 #include <sys/uio.h>
40 #include <sys/errno.h>
41 #include <sys/sysmacros.h>
42 #include <sys/statvfs.h>
43 #include <sys/kmem.h>
44 #include <sys/dirent.h>
45 #include <rpc/types.h>
46 #include <rpc/auth.h>
47 #include <rpc/rpcsec_gss.h>
48 #include <rpc/svc.h>
49 #include <sys/strsubr.h>
50 #include <sys/strsun.h>
51 #include <sys/sdt.h>
53 #include <nfs/nfs.h>
54 #include <nfs/export.h>
55 #include <nfs/nfs4.h>
56 #include <nfs/nfs_cmd.h>
60 * RFS4_MINLEN_ENTRY4: XDR-encoded size of smallest possible dirent.
61 * This is used to return NFS4ERR_TOOSMALL when clients specify
62 * maxcount that isn't large enough to hold the smallest possible
63 * XDR encoded dirent.
65 * sizeof cookie (8 bytes) +
66 * sizeof name_len (4 bytes) +
67 * sizeof smallest (padded) name (4 bytes) +
68 * sizeof bitmap4_len (12 bytes) + NOTE: we always encode len=2 bm4
69 * sizeof attrlist4_len (4 bytes) +
70 * sizeof next boolean (4 bytes)
72 * RFS4_MINLEN_RDDIR4: XDR-encoded size of READDIR op reply containing
73 * the smallest possible entry4 (assumes no attrs requested).
74 * sizeof nfsstat4 (4 bytes) +
75 * sizeof verifier4 (8 bytes) +
76 * sizeof entsecond_to_ry4list bool (4 bytes) +
77 * sizeof entry4 (36 bytes) +
78 * sizeof eof bool (4 bytes)
80 * RFS4_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
81 * fop_readdir. Its value is the size of the maximum possible dirent
82 * for solaris. The DIRENT_RECLEN macro returns the size of dirent
83 * required for a given name length. MAXNAMELEN is the maximum
84 * filename length allowed in Solaris. The first two DIRENT_RECLEN()
85 * macros are to allow for . and .. entries -- just a minor tweak to try
86 * and guarantee that buffer we give to fop_readdir will be large enough
87 * to hold ., .., and the largest possible solaris dirent64.
89 #define RFS4_MINLEN_ENTRY4 36
90 #define RFS4_MINLEN_RDDIR4 (4 + NFS4_VERIFIER_SIZE + 4 + RFS4_MINLEN_ENTRY4 + 4)
91 #define RFS4_MINLEN_RDDIR_BUF \
92 (DIRENT_RECLEN(1) + DIRENT_RECLEN(2) + DIRENT_RECLEN(MAXNAMELEN))
95 #ifdef nextdp
96 #undef nextdp
97 #endif
98 #define nextdp(dp) ((struct dirent *)((char *)(dp) + (dp)->d_reclen))
100 verifier4 Readdir4verf = 0x0;
102 static nfs_ftype4 vt_to_nf4[] = {
103 0, NF4REG, NF4DIR, NF4BLK, NF4CHR, NF4LNK, NF4FIFO, 0, 0, NF4SOCK, 0
107 * RFC 7530 Section 8.3.2
108 * Supported attributes for READDIR for the root of an absent filesystem.
110 #define ABSENT_FS_ATTRS (FATTR4_FS_LOCATIONS_MASK | FATTR4_FSID_MASK | \
111 FATTR4_MOUNTED_ON_FILEID_MASK | FATTR4_RDATTR_ERROR_MASK)
114 nfs4_readdir_getvp(vnode_t *dvp, char *d_name, vnode_t **vpp,
115 struct exportinfo **exi, struct svc_req *req, struct compound_state *cs,
116 int expseudo, bool_t *migrated)
118 int error;
119 int ismntpt;
120 fid_t fid;
121 vnode_t *vp, *pre_tvp;
122 nfsstat4 status;
123 struct exportinfo *newexi, *saveexi;
124 cred_t *scr;
126 *vpp = vp = NULL;
128 if (error = fop_lookup(dvp, d_name, &vp, NULL, 0, NULL, cs->cr,
129 NULL, NULL, NULL))
130 return (error);
132 /* referral point ? */
133 if (vn_is_nfs_reparse(vp, cs->cr) && !client_is_downrev(req)) {
134 DTRACE_PROBE2(nfs4serv__func__referral__moved,
135 vnode_t *, vp, char *, "nfs4_readdir_getvp");
136 *migrated = TRUE;
137 *vpp = vp;
138 return (0);
141 /* Is this object mounted upon? */
142 ismntpt = vn_ismntpt(vp);
145 * Nothing more to do if object is not a mount point or
146 * a possible LOFS shadow of an LOFS mount (which won't
147 * have v_vfsmountedhere set)
149 if (ismntpt == 0 && dvp->v_vfsp == vp->v_vfsp && expseudo == 0) {
150 *vpp = vp;
151 return (0);
154 if (ismntpt) {
156 * Something is mounted here. Traverse and manage the
157 * namespace
159 pre_tvp = vp;
160 VN_HOLD(pre_tvp);
162 if ((error = traverse(&vp)) != 0) {
163 VN_RELE(vp);
164 VN_RELE(pre_tvp);
165 return (error);
169 bzero(&fid, sizeof (fid));
170 fid.fid_len = MAXFIDSZ;
173 * If fop_fid not supported by underlying fs (mntfs, procfs,
174 * etc.), then return attrs for stub instead of VROOT object.
175 * If it fails for any other reason, then return the error.
177 if (error = fop_fid(vp, &fid, NULL)) {
178 if (ismntpt == 0) {
179 VN_RELE(vp);
180 return (error);
183 if (error != ENOSYS && error != ENOTSUP) {
184 VN_RELE(vp);
185 VN_RELE(pre_tvp);
186 return (error);
188 /* go back to vnode that is "under" mount */
189 VN_RELE(vp);
190 *vpp = pre_tvp;
191 return (0);
194 newexi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid, vp);
195 if (newexi == NULL) {
196 if (ismntpt == 0) {
197 *vpp = vp;
198 } else {
199 VN_RELE(vp);
200 *vpp = pre_tvp;
202 return (0);
205 if (ismntpt)
206 VN_RELE(pre_tvp);
208 /* Save the exi and present the new one to checkauth4() */
209 saveexi = cs->exi;
210 cs->exi = newexi;
212 /* Get the right cred like lookup does */
213 scr = cs->cr;
214 cs->cr = crdup(cs->basecr);
216 status = call_checkauth4(cs, req);
218 crfree(cs->cr);
219 cs->cr = scr;
220 cs->exi = saveexi;
222 /* Reset what call_checkauth4() may have set */
223 *cs->statusp = NFS4_OK;
225 if (status != NFS4_OK) {
226 VN_RELE(vp);
227 if (status == NFS4ERR_DELAY)
228 status = NFS4ERR_ACCESS;
229 return (status);
231 *vpp = vp;
232 *exi = newexi;
234 return (0);
237 /* This is the set of pathconf data for vfs */
238 typedef struct {
239 uint64_t maxfilesize;
240 uint32_t maxlink;
241 uint32_t maxname;
242 } rfs4_pc_encode_t;
245 static int
246 rfs4_get_pc_encode(vnode_t *vp, rfs4_pc_encode_t *pce, bitmap4 ar, cred_t *cr)
248 int error;
249 ulong_t pc_val;
251 pce->maxfilesize = 0;
252 pce->maxlink = 0;
253 pce->maxname = 0;
255 if (ar & FATTR4_MAXFILESIZE_MASK) {
256 /* Maximum File Size */
257 error = fop_pathconf(vp, _PC_FILESIZEBITS, &pc_val, cr, NULL);
258 if (error)
259 return (error);
262 * If the underlying file system does not support
263 * _PC_FILESIZEBITS, return a reasonable default. Note that
264 * error code on fop_pathconf will be 0, even if the underlying
265 * file system does not support _PC_FILESIZEBITS.
267 if (pc_val == (ulong_t)-1) {
268 pce->maxfilesize = MAXOFF_T;
269 } else {
270 if (pc_val >= (sizeof (uint64_t) * 8))
271 pce->maxfilesize = INT64_MAX;
272 else
273 pce->maxfilesize = ((1LL << (pc_val - 1)) - 1);
277 if (ar & FATTR4_MAXLINK_MASK) {
278 /* Maximum Link Count */
279 error = fop_pathconf(vp, _PC_LINK_MAX, &pc_val, cr, NULL);
280 if (error)
281 return (error);
283 pce->maxlink = pc_val;
286 if (ar & FATTR4_MAXNAME_MASK) {
287 /* Maximum Name Length */
288 error = fop_pathconf(vp, _PC_NAME_MAX, &pc_val, cr, NULL);
289 if (error)
290 return (error);
292 pce->maxname = pc_val;
295 return (0);
298 /* This is the set of statvfs data that is ready for encoding */
299 typedef struct {
300 uint64_t space_avail;
301 uint64_t space_free;
302 uint64_t space_total;
303 u_longlong_t fa;
304 u_longlong_t ff;
305 u_longlong_t ft;
306 } rfs4_sb_encode_t;
308 static int
309 rfs4_get_sb_encode(vfs_t *vfsp, rfs4_sb_encode_t *psbe)
311 int error;
312 struct statvfs64 sb;
314 /* Grab the per filesystem info */
315 if (error = VFS_STATVFS(vfsp, &sb)) {
316 return (error);
319 /* Calculate space available */
320 if (sb.f_bavail != (fsblkcnt64_t)-1) {
321 psbe->space_avail =
322 (fattr4_space_avail) sb.f_frsize *
323 (fattr4_space_avail) sb.f_bavail;
324 } else {
325 psbe->space_avail =
326 (fattr4_space_avail) sb.f_bavail;
329 /* Calculate space free */
330 if (sb.f_bfree != (fsblkcnt64_t)-1) {
331 psbe->space_free =
332 (fattr4_space_free) sb.f_frsize *
333 (fattr4_space_free) sb.f_bfree;
334 } else {
335 psbe->space_free =
336 (fattr4_space_free) sb.f_bfree;
339 /* Calculate space total */
340 if (sb.f_blocks != (fsblkcnt64_t)-1) {
341 psbe->space_total =
342 (fattr4_space_total) sb.f_frsize *
343 (fattr4_space_total) sb.f_blocks;
344 } else {
345 psbe->space_total =
346 (fattr4_space_total) sb.f_blocks;
349 /* For use later on attr encode */
350 psbe->fa = sb.f_favail;
351 psbe->ff = sb.f_ffree;
352 psbe->ft = sb.f_files;
354 return (0);
357 extern void rfs4_free_fs_locations4(fs_locations4 *);
360 * If readdir only needs to return FILEID, we can take it from the
361 * dirent struct and save doing the lookup.
363 /* ARGSUSED */
364 void
365 rfs4_op_readdir(nfs_argop4 *argop, nfs_resop4 *resop, struct svc_req *req,
366 struct compound_state *cs)
368 READDIR4args *args = &argop->nfs_argop4_u.opreaddir;
369 READDIR4res *resp = &resop->nfs_resop4_u.opreaddir;
370 struct exportinfo *newexi = NULL;
371 int error;
372 mblk_t *mp;
373 uint_t mpcount;
374 int alloc_err = 0;
375 vnode_t *dvp = cs->vp;
376 vnode_t *vp;
377 vattr_t va;
378 struct dirent *dp;
379 rfs4_sb_encode_t dsbe, sbe;
380 int vfs_different;
381 int rddir_data_len, rddir_result_size;
382 caddr_t rddir_data;
383 offset_t rddir_next_offset;
384 int dircount;
385 int no_space;
386 int iseofdir;
387 uint_t eof;
388 struct iovec iov;
389 struct uio uio;
390 int tsize;
391 int check_visible;
392 struct exp_visible *visp;
394 uint32_t *ptr, *ptr_redzone;
395 uint32_t *beginning_ptr;
396 uint32_t *lastentry_ptr;
397 uint32_t *attrmask_ptr;
398 uint32_t *attr_offset_ptr;
399 uint32_t attr_length;
400 uint32_t rndup;
401 uint32_t namelen;
402 uint32_t rddirattr_error = 0;
403 int nents;
404 bitmap4 ar = args->attr_request & NFS4_SRV_RDDIR_SUPPORTED_ATTRS;
405 bitmap4 ae;
406 rfs4_pc_encode_t dpce, pce;
407 ulong_t pc_val;
408 uint64_t maxread;
409 uint64_t maxwrite;
410 uid_t lastuid;
411 gid_t lastgid;
412 int lu_set, lg_set;
413 utf8string owner, group;
414 int owner_error, group_error;
415 struct sockaddr *ca;
416 char *name = NULL;
417 nfsstat4 status = NFS4_OK;
419 DTRACE_NFSV4_2(op__readdir__start, struct compound_state *, cs,
420 READDIR4args *, args);
422 lu_set = lg_set = 0;
423 owner.utf8string_len = group.utf8string_len = 0;
424 owner.utf8string_val = group.utf8string_val = NULL;
426 resp->mblk = NULL;
428 /* Maximum read and write size */
429 maxread = maxwrite = rfs4_tsize(req);
431 if (dvp == NULL) {
432 *cs->statusp = resp->status = NFS4ERR_NOFILEHANDLE;
433 goto out;
437 * If there is an unshared filesystem mounted on this vnode,
438 * do not allow readdir in this directory.
440 if (vn_ismntpt(dvp)) {
441 *cs->statusp = resp->status = NFS4ERR_ACCESS;
442 goto out;
445 if (dvp->v_type != VDIR) {
446 *cs->statusp = resp->status = NFS4ERR_NOTDIR;
447 goto out;
450 if (args->maxcount <= RFS4_MINLEN_RDDIR4) {
451 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
452 goto out;
456 * If write-only attrs are requested, then fail the readdir op
458 if (args->attr_request &
459 (FATTR4_TIME_MODIFY_SET_MASK | FATTR4_TIME_ACCESS_SET_MASK)) {
460 *cs->statusp = resp->status = NFS4ERR_INVAL;
461 goto out;
464 error = fop_access(dvp, VREAD, 0, cs->cr, NULL);
465 if (error) {
466 *cs->statusp = resp->status = puterrno4(error);
467 goto out;
470 if (args->cookieverf != Readdir4verf) {
471 *cs->statusp = resp->status = NFS4ERR_NOT_SAME;
472 goto out;
475 /* Is there pseudo-fs work that is needed for this readdir? */
476 check_visible = PSEUDO(cs->exi) ||
477 ! is_exported_sec(cs->nfsflavor, cs->exi) ||
478 cs->access & CS_ACCESS_LIMITED;
480 /* Check the requested attributes and only do the work if needed */
482 if (ar & (FATTR4_MAXFILESIZE_MASK |
483 FATTR4_MAXLINK_MASK |
484 FATTR4_MAXNAME_MASK)) {
485 if (error = rfs4_get_pc_encode(cs->vp, &dpce, ar, cs->cr)) {
486 *cs->statusp = resp->status = puterrno4(error);
487 goto out;
489 pce = dpce;
492 /* If there is statvfs data requested, pick it up once */
493 if (ar &
494 (FATTR4_FILES_AVAIL_MASK |
495 FATTR4_FILES_FREE_MASK |
496 FATTR4_FILES_TOTAL_MASK |
497 FATTR4_FILES_AVAIL_MASK |
498 FATTR4_FILES_FREE_MASK |
499 FATTR4_FILES_TOTAL_MASK)) {
500 if (error = rfs4_get_sb_encode(dvp->v_vfsp, &dsbe)) {
501 *cs->statusp = resp->status = puterrno4(error);
502 goto out;
504 sbe = dsbe;
508 * Max transfer size of the server is the absolute limite.
509 * If the client has decided to max out with something really
510 * tiny, then return toosmall. Otherwise, move forward and
511 * see if a single entry can be encoded.
513 tsize = rfs4_tsize(req);
514 if (args->maxcount > tsize)
515 args->maxcount = tsize;
516 else if (args->maxcount < RFS4_MINLEN_RDDIR_BUF) {
517 if (args->maxcount < RFS4_MINLEN_ENTRY4) {
518 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
519 goto out;
524 * How large should the mblk be for outgoing encoding.
526 if (args->maxcount < MAXBSIZE)
527 mpcount = MAXBSIZE;
528 else
529 mpcount = args->maxcount;
532 * mp will contain the data to be sent out in the readdir reply.
533 * It will be freed after the reply has been sent.
534 * Let's roundup the data to a BYTES_PER_XDR_UNIX multiple,
535 * so that the call to xdrmblk_putmblk() never fails.
537 mp = allocb(RNDUP(mpcount), BPRI_MED);
539 if (mp == NULL) {
541 * The allocation of the client's requested size has
542 * failed. It may be that the size is too large for
543 * current system utilization; step down to a "common"
544 * size and wait for the allocation to occur.
546 if (mpcount > MAXBSIZE)
547 args->maxcount = mpcount = MAXBSIZE;
548 mp = allocb_wait(RNDUP(mpcount), BPRI_MED,
549 STR_NOSIG, &alloc_err);
552 ASSERT(mp != NULL);
553 ASSERT(alloc_err == 0);
555 resp->mblk = mp;
557 ptr = beginning_ptr = (uint32_t *)mp->b_datap->db_base;
560 * The "redzone" at the end of the encoding buffer is used
561 * to deal with xdr encoding length. Instead of checking
562 * each encoding of an attribute value before it is done,
563 * make the assumption that it will fit into the buffer and
564 * check occasionally.
566 * The largest block of attributes that are encoded without
567 * checking the redzone is 18 * BYTES_PER_XDR_UNIT (72 bytes)
568 * "round" to 128 as the redzone size.
570 if (args->maxcount < (mpcount - 128))
571 ptr_redzone =
572 (uint32_t *)(((char *)ptr) + RNDUP(args->maxcount));
573 else
574 ptr_redzone =
575 (uint32_t *)((((char *)ptr) + RNDUP(mpcount)) - 128);
578 * Set the dircount; this will be used as the size for the
579 * readdir of the underlying filesystem. First make sure
580 * that it is large enough to do a reasonable readdir (client
581 * may have short changed us - it is an advisory number);
582 * then make sure that it isn't too large.
583 * After all of that, if maxcount is "small" then just use
584 * that for the dircount number.
586 dircount = (args->dircount < MAXBSIZE) ? MAXBSIZE : args->dircount;
587 dircount = (dircount > tsize) ? tsize : dircount;
588 if (dircount > args->maxcount)
589 dircount = args->maxcount;
590 if (args->maxcount <= MAXBSIZE) {
591 if (args->maxcount < RFS4_MINLEN_RDDIR_BUF)
592 dircount = RFS4_MINLEN_RDDIR_BUF;
593 else
594 dircount = args->maxcount;
597 /* number of entries fully encoded in outgoing buffer */
598 nents = 0;
600 /* ENCODE READDIR4res.cookieverf */
601 IXDR_PUT_HYPER(ptr, Readdir4verf);
603 rddir_data_len = dircount;
604 rddir_data = kmem_alloc(rddir_data_len, KM_NOSLEEP);
605 if (rddir_data == NULL) {
606 /* The allocation failed; downsize and wait for it this time */
607 if (rddir_data_len > MAXBSIZE)
608 rddir_data_len = dircount = MAXBSIZE;
609 rddir_data = kmem_alloc(rddir_data_len, KM_SLEEP);
612 rddir_next_offset = (offset_t)args->cookie;
614 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
616 readagain:
618 no_space = FALSE;
619 iseofdir = FALSE;
621 vp = NULL;
623 /* Move on to reading the directory contents */
624 iov.iov_base = rddir_data;
625 iov.iov_len = rddir_data_len;
626 uio.uio_iov = &iov;
627 uio.uio_iovcnt = 1;
628 uio.uio_segflg = UIO_SYSSPACE;
629 uio.uio_extflg = UIO_COPY_CACHED;
630 uio.uio_loffset = rddir_next_offset;
631 uio.uio_resid = rddir_data_len;
633 (void) fop_rwlock(dvp, V_WRITELOCK_FALSE, NULL);
635 error = fop_readdir(dvp, &uio, cs->cr, &iseofdir, NULL, 0);
637 fop_rwunlock(dvp, V_WRITELOCK_FALSE, NULL);
639 if (error) {
640 kmem_free((caddr_t)rddir_data, rddir_data_len);
641 freeb(resp->mblk);
642 resp->mblk = NULL;
643 resp->data_len = 0;
644 *cs->statusp = resp->status = puterrno4(error);
645 goto out;
649 rddir_result_size = rddir_data_len - uio.uio_resid;
651 /* No data were read. Check if we reached the end of the directory. */
652 if (rddir_result_size == 0) {
653 /* encode the BOOLEAN marking no further entries */
654 IXDR_PUT_U_INT32(ptr, false);
655 /* encode the BOOLEAN signifying end of directory */
656 IXDR_PUT_U_INT32(ptr, iseofdir ? true : false);
657 resp->data_len = (char *)ptr - (char *)beginning_ptr;
658 resp->mblk->b_wptr += resp->data_len;
659 kmem_free((caddr_t)rddir_data, rddir_data_len);
660 *cs->statusp = resp->status = NFS4_OK;
661 goto out;
664 lastentry_ptr = ptr;
665 no_space = 0;
666 for (dp = (struct dirent *)rddir_data;
667 !no_space && rddir_result_size > 0; dp = nextdp(dp)) {
668 bool_t fs_migrated = FALSE;
670 /* reset visp */
671 visp = NULL;
673 if (vp) {
674 VN_RELE(vp);
675 vp = NULL;
678 if (newexi)
679 newexi = NULL;
681 rddir_result_size -= dp->d_reclen;
683 /* skip "." and ".." entries */
684 if (dp->d_ino == 0 || NFS_IS_DOTNAME(dp->d_name)) {
685 rddir_next_offset = dp->d_off;
686 continue;
689 if (check_visible &&
690 !nfs_visible_inode(cs->exi, dp->d_ino, &visp)) {
691 rddir_next_offset = dp->d_off;
692 continue;
696 * Only if the client requested attributes...
697 * If the fop_lookup fails ENOENT, then skip this entry
698 * for the readdir response. If there was another error,
699 * then set the rddirattr_error and the error will be
700 * encoded later in the "attributes" section.
702 ae = ar;
703 if (ar == 0)
704 goto reencode_attrs;
706 error = nfs4_readdir_getvp(dvp, dp->d_name,
707 &vp, &newexi, req, cs,
708 visp != NULL ? visp->vis_exported : 0, &fs_migrated);
709 if (error == ENOENT) {
710 rddir_next_offset = dp->d_off;
711 continue;
714 rddirattr_error = error;
717 * The vp obtained from above may be from a
718 * different filesystem mount and the vfs-like
719 * attributes should be obtained from that
720 * different vfs; only do this if appropriate.
722 if (vp &&
723 (vfs_different = (dvp->v_vfsp != vp->v_vfsp))) {
724 if (ae & (FATTR4_FILES_AVAIL_MASK |
725 FATTR4_FILES_FREE_MASK |
726 FATTR4_FILES_TOTAL_MASK |
727 FATTR4_FILES_AVAIL_MASK |
728 FATTR4_FILES_FREE_MASK |
729 FATTR4_FILES_TOTAL_MASK)) {
730 if (error =
731 rfs4_get_sb_encode(dvp->v_vfsp,
732 &sbe)) {
733 /* Remove attrs from encode */
734 ae &= ~(FATTR4_FILES_AVAIL_MASK |
735 FATTR4_FILES_FREE_MASK |
736 FATTR4_FILES_TOTAL_MASK |
737 FATTR4_FILES_AVAIL_MASK |
738 FATTR4_FILES_FREE_MASK |
739 FATTR4_FILES_TOTAL_MASK);
740 rddirattr_error = error;
743 if (ae & (FATTR4_MAXFILESIZE_MASK |
744 FATTR4_MAXLINK_MASK |
745 FATTR4_MAXNAME_MASK)) {
746 if (error = rfs4_get_pc_encode(cs->vp,
747 &pce, ae, cs->cr)) {
748 ae &= ~(FATTR4_MAXFILESIZE_MASK |
749 FATTR4_MAXLINK_MASK |
750 FATTR4_MAXNAME_MASK);
751 rddirattr_error = error;
756 reencode_attrs:
757 /* encode the BOOLEAN for the existence of the next entry */
758 IXDR_PUT_U_INT32(ptr, true);
759 /* encode the COOKIE for the entry */
760 IXDR_PUT_U_HYPER(ptr, dp->d_off);
762 name = nfscmd_convname(ca, cs->exi, dp->d_name,
763 NFSCMD_CONV_OUTBOUND, MAXPATHLEN + 1);
765 if (name == NULL) {
766 rddir_next_offset = dp->d_off;
767 continue;
769 /* Calculate the dirent name length */
770 namelen = strlen(name);
772 rndup = RNDUP(namelen) / BYTES_PER_XDR_UNIT;
774 /* room for LENGTH + string ? */
775 if ((ptr + (1 + rndup)) > ptr_redzone) {
776 no_space = TRUE;
777 continue;
780 /* encode the LENGTH of the name */
781 IXDR_PUT_U_INT32(ptr, namelen);
782 /* encode the RNDUP FILL first */
783 ptr[rndup - 1] = 0;
784 /* encode the NAME of the entry */
785 bcopy(name, (char *)ptr, namelen);
786 /* now bump the ptr after... */
787 ptr += rndup;
789 if (name != dp->d_name)
790 kmem_free(name, MAXPATHLEN + 1);
793 * Keep checking on the dircount to see if we have
794 * reached the limit; from the RFC, dircount is to be
795 * the XDR encoded limit of the cookie plus name.
796 * So the count is the name, XDR_UNIT of length for
797 * that name and 2 * XDR_UNIT bytes of cookie;
798 * However, use the regular DIRENT64 to match most
799 * client's APIs.
801 dircount -= DIRENT_RECLEN(namelen);
802 if (nents != 0 && dircount < 0) {
803 no_space = TRUE;
804 continue;
808 * Attributes requested?
809 * Gather up the attribute info and the previous fop_lookup()
810 * succeeded; if an error occurs on the fop_getattr() then
811 * return just the error (again if it is requested).
812 * Note that the previous fop_lookup() could have failed
813 * itself which leaves this code without anything for
814 * a fop_getattr().
815 * Also note that the readdir_attr_error is left in the
816 * encoding mask if requested and so is the mounted_on_fileid.
818 if (ae != 0) {
819 if (!vp) {
820 ae = ar & (FATTR4_RDATTR_ERROR_MASK |
821 FATTR4_MOUNTED_ON_FILEID_MASK);
822 } else if (fs_migrated) {
824 * RFC 7530 Section 8.3.2
825 * Restrict to actually available attributes in
826 * case of an absent filesystem.
828 ae &= ABSENT_FS_ATTRS;
830 if (!(ae & FATTR4_FS_LOCATIONS_MASK))
831 rddirattr_error = NFS4ERR_MOVED;
832 } else {
833 va.va_mask = VATTR_ALL;
834 rddirattr_error =
835 fop_getattr(vp, &va, 0, cs->cr, NULL);
836 if (rddirattr_error) {
837 ae = ae & (FATTR4_RDATTR_ERROR_MASK |
838 FATTR4_MOUNTED_ON_FILEID_MASK);
839 } else {
841 * We may lie about the object
842 * type for a referral
844 if (vn_is_nfs_reparse(vp, cs->cr) &&
845 client_is_downrev(req))
846 va.va_type = VLNK;
850 /* RFC 7530 Section 8.3.2 and 16.24.4 */
851 if (rddirattr_error != 0 &&
852 !(ae & FATTR4_RDATTR_ERROR_MASK)) {
853 status = puterrno4(rddirattr_error);
854 goto out_free;
858 /* START OF ATTRIBUTE ENCODING */
860 /* encode the LENGTH of the BITMAP4 array */
861 IXDR_PUT_U_INT32(ptr, 2);
862 /* encode the BITMAP4 */
863 attrmask_ptr = ptr;
864 IXDR_PUT_HYPER(ptr, ae);
865 attr_offset_ptr = ptr;
866 /* encode the default LENGTH of the attributes for entry */
867 IXDR_PUT_U_INT32(ptr, 0);
869 if (ptr > ptr_redzone) {
870 no_space = TRUE;
871 continue;
874 /* Check if any of the first 32 attributes are being encoded */
875 if (ae & 0xffffffff00000000) {
877 * Redzone check is done at the end of this section.
878 * This particular section will encode a maximum of
879 * 18 * BYTES_PER_XDR_UNIT of data
881 if (ae &
882 (FATTR4_SUPPORTED_ATTRS_MASK |
883 FATTR4_TYPE_MASK |
884 FATTR4_FH_EXPIRE_TYPE_MASK |
885 FATTR4_CHANGE_MASK |
886 FATTR4_SIZE_MASK |
887 FATTR4_LINK_SUPPORT_MASK |
888 FATTR4_SYMLINK_SUPPORT_MASK |
889 FATTR4_NAMED_ATTR_MASK |
890 FATTR4_FSID_MASK |
891 FATTR4_UNIQUE_HANDLES_MASK |
892 FATTR4_LEASE_TIME_MASK |
893 FATTR4_RDATTR_ERROR_MASK)) {
895 if (ae & FATTR4_SUPPORTED_ATTRS_MASK) {
896 IXDR_PUT_INT32(ptr, 2);
897 IXDR_PUT_HYPER(ptr,
898 rfs4_supported_attrs);
900 if (ae & FATTR4_TYPE_MASK) {
901 uint_t ftype = vt_to_nf4[va.va_type];
902 if (dvp->v_flag & V_XATTRDIR) {
903 if (va.va_type == VDIR)
904 ftype = NF4ATTRDIR;
905 else
906 ftype = NF4NAMEDATTR;
908 IXDR_PUT_U_INT32(ptr, ftype);
910 if (ae & FATTR4_FH_EXPIRE_TYPE_MASK) {
911 uint_t expire_type = FH4_PERSISTENT;
912 IXDR_PUT_U_INT32(ptr, expire_type);
914 if (ae & FATTR4_CHANGE_MASK) {
915 u_longlong_t change;
916 NFS4_SET_FATTR4_CHANGE(change,
917 va.va_ctime);
918 if (visp != NULL) {
919 u_longlong_t visch;
920 NFS4_SET_FATTR4_CHANGE(visch,
921 visp->vis_change);
922 if (visch > change)
923 change = visch;
925 IXDR_PUT_HYPER(ptr, change);
927 if (ae & FATTR4_SIZE_MASK) {
928 u_longlong_t size = va.va_size;
929 IXDR_PUT_HYPER(ptr, size);
931 if (ae & FATTR4_LINK_SUPPORT_MASK) {
932 IXDR_PUT_U_INT32(ptr, true);
934 if (ae & FATTR4_SYMLINK_SUPPORT_MASK) {
935 IXDR_PUT_U_INT32(ptr, true);
937 if (ae & FATTR4_NAMED_ATTR_MASK) {
938 uint_t isit;
939 pc_val = FALSE;
940 int sattr_error;
942 if (!(vp->v_vfsp->vfs_flag &
943 VFS_XATTR)) {
944 isit = FALSE;
945 } else {
946 sattr_error = fop_pathconf(vp,
947 _PC_SATTR_EXISTS,
948 &pc_val, cs->cr, NULL);
949 if (sattr_error || pc_val == 0)
950 (void) fop_pathconf(vp,
951 _PC_XATTR_EXISTS,
952 &pc_val,
953 cs->cr, NULL);
955 isit = (pc_val ? TRUE : FALSE);
956 IXDR_PUT_U_INT32(ptr, isit);
958 if (ae & FATTR4_FSID_MASK) {
959 u_longlong_t major, minor;
960 struct exportinfo *exi;
962 exi = newexi ? newexi : cs->exi;
963 if (fs_migrated) {
964 major = 1;
965 minor = 0;
966 } else if (exi->exi_volatile_dev) {
967 int *pmaj = (int *)&major;
969 pmaj[0] = exi->exi_fsid.val[0];
970 pmaj[1] = exi->exi_fsid.val[1];
971 minor = 0;
972 } else {
973 major = getmajor(va.va_fsid);
974 minor = getminor(va.va_fsid);
976 IXDR_PUT_HYPER(ptr, major);
977 IXDR_PUT_HYPER(ptr, minor);
979 if (ae & FATTR4_UNIQUE_HANDLES_MASK) {
980 IXDR_PUT_U_INT32(ptr, false);
982 if (ae & FATTR4_LEASE_TIME_MASK) {
983 uint_t lt = rfs4_lease_time;
984 IXDR_PUT_U_INT32(ptr, lt);
986 if (ae & FATTR4_RDATTR_ERROR_MASK) {
987 rddirattr_error =
988 (rddirattr_error == 0 ?
989 0 : puterrno4(rddirattr_error));
990 IXDR_PUT_U_INT32(ptr, rddirattr_error);
993 /* Check the redzone boundary */
994 if (ptr > ptr_redzone) {
995 no_space = TRUE;
996 break;
1000 * Redzone check is done at the end of this section.
1001 * This particular section will encode a maximum of
1002 * 4 * BYTES_PER_XDR_UNIT of data.
1003 * NOTE: that if ACLs are supported that the
1004 * redzone calculations will need to change.
1006 if (ae &
1007 (FATTR4_ACL_MASK |
1008 FATTR4_ACLSUPPORT_MASK |
1009 FATTR4_ARCHIVE_MASK |
1010 FATTR4_CANSETTIME_MASK |
1011 FATTR4_CASE_INSENSITIVE_MASK |
1012 FATTR4_CASE_PRESERVING_MASK |
1013 FATTR4_CHOWN_RESTRICTED_MASK)) {
1015 if (ae & FATTR4_ACL_MASK) {
1016 ASSERT(0);
1018 if (ae & FATTR4_ACLSUPPORT_MASK) {
1019 ASSERT(0);
1021 if (ae & FATTR4_ARCHIVE_MASK) {
1022 ASSERT(0);
1024 if (ae & FATTR4_CANSETTIME_MASK) {
1025 IXDR_PUT_U_INT32(ptr, true);
1027 if (ae & FATTR4_CASE_INSENSITIVE_MASK) {
1028 IXDR_PUT_U_INT32(ptr, false);
1030 if (ae & FATTR4_CASE_PRESERVING_MASK) {
1031 IXDR_PUT_U_INT32(ptr, true);
1033 if (ae & FATTR4_CHOWN_RESTRICTED_MASK) {
1034 uint_t isit;
1035 pc_val = FALSE;
1036 (void) fop_pathconf(vp,
1037 _PC_CHOWN_RESTRICTED,
1038 &pc_val, cs->cr, NULL);
1039 isit = (pc_val ? TRUE : FALSE);
1040 IXDR_PUT_U_INT32(ptr, isit);
1042 /* Check the redzone boundary */
1043 if (ptr > ptr_redzone) {
1044 no_space = TRUE;
1045 break;
1049 * Redzone check is done before the filehandle
1050 * is encoded.
1052 if (ae &
1053 (FATTR4_FILEHANDLE_MASK |
1054 FATTR4_FILEID_MASK)) {
1056 if (ae & FATTR4_FILEHANDLE_MASK) {
1057 struct {
1058 uint_t len;
1059 char *val;
1060 char fh[NFS_FH4_LEN];
1061 } fh;
1062 fh.len = 0;
1063 fh.val = fh.fh;
1064 (void) makefh4((nfs_fh4 *)&fh, vp,
1065 (newexi ? newexi : cs->exi));
1067 if (dvp->v_flag & V_XATTRDIR)
1068 set_fh4_flag((nfs_fh4 *)&fh,
1069 FH4_NAMEDATTR);
1071 if (!xdr_inline_encode_nfs_fh4(
1072 &ptr, ptr_redzone,
1073 (nfs_fh4_fmt_t *)fh.val)) {
1074 no_space = TRUE;
1075 break;
1078 if (ae & FATTR4_FILEID_MASK) {
1079 IXDR_PUT_HYPER(ptr, va.va_nodeid);
1081 /* Check the redzone boundary */
1082 if (ptr > ptr_redzone) {
1083 no_space = TRUE;
1084 break;
1089 * Redzone check is done at the end of this section.
1090 * This particular section will encode a maximum of
1091 * 6 * BYTES_PER_XDR_UNIT of data.
1093 if (ae &
1094 (FATTR4_FILES_AVAIL_MASK |
1095 FATTR4_FILES_FREE_MASK |
1096 FATTR4_FILES_TOTAL_MASK)) {
1098 if (ae & FATTR4_FILES_AVAIL_MASK) {
1099 IXDR_PUT_HYPER(ptr, sbe.fa);
1101 if (ae & FATTR4_FILES_FREE_MASK) {
1102 IXDR_PUT_HYPER(ptr, sbe.ff);
1104 if (ae & FATTR4_FILES_TOTAL_MASK) {
1105 IXDR_PUT_HYPER(ptr, sbe.ft);
1108 /* Check the redzone boundary */
1109 if (ptr > ptr_redzone) {
1110 no_space = TRUE;
1111 break;
1116 * Handle fs_locations separately.
1117 * This can be quite slow for referrals. Usually
1118 * clients don't use this attribute in readdir.
1120 if (ae & FATTR4_FS_LOCATIONS_MASK) {
1121 fs_locations4 *p;
1122 fs_locations4 fs;
1123 bool_t pushed;
1124 XDR xdr;
1126 (void) memset(&fs, 0, sizeof (fs_locations4));
1128 ASSERT(vp);
1129 p = fetch_referral(vp, cs->cr);
1130 if (p != NULL) {
1131 fs = *p;
1132 kmem_free(p, sizeof (fs_locations4));
1135 ASSERT(ptr_redzone >= ptr);
1136 ASSERT((uintptr_t)ptr_redzone - (uintptr_t)ptr
1137 <= UINT_MAX);
1138 xdrmem_create(&xdr, (caddr_t)ptr,
1139 (uintptr_t)ptr_redzone - (uintptr_t)ptr,
1140 XDR_ENCODE);
1142 pushed = xdr_fattr4_fs_locations(&xdr, &fs);
1143 if (pushed)
1144 ptr = (uint32_t *)((char *)ptr +
1145 xdr_getpos(&xdr));
1147 xdr_destroy(&xdr);
1148 rfs4_free_fs_locations4(&fs);
1150 if (!pushed || ptr > ptr_redzone) {
1151 no_space = TRUE;
1152 break;
1156 if (ae &
1157 (FATTR4_HIDDEN_MASK |
1158 FATTR4_HOMOGENEOUS_MASK |
1159 FATTR4_MAXFILESIZE_MASK |
1160 FATTR4_MAXLINK_MASK |
1161 FATTR4_MAXNAME_MASK |
1162 FATTR4_MAXREAD_MASK |
1163 FATTR4_MAXWRITE_MASK)) {
1165 if (ae & FATTR4_HIDDEN_MASK) {
1166 ASSERT(0);
1168 if (ae & FATTR4_HOMOGENEOUS_MASK) {
1169 IXDR_PUT_U_INT32(ptr, true);
1171 if (ae & FATTR4_MAXFILESIZE_MASK) {
1172 IXDR_PUT_HYPER(ptr, pce.maxfilesize);
1174 if (ae & FATTR4_MAXLINK_MASK) {
1175 IXDR_PUT_U_INT32(ptr, pce.maxlink);
1177 if (ae & FATTR4_MAXNAME_MASK) {
1178 IXDR_PUT_U_INT32(ptr, pce.maxname);
1180 if (ae & FATTR4_MAXREAD_MASK) {
1181 IXDR_PUT_HYPER(ptr, maxread);
1183 if (ae & FATTR4_MAXWRITE_MASK) {
1184 IXDR_PUT_HYPER(ptr, maxwrite);
1186 /* Check the redzone boundary */
1187 if (ptr > ptr_redzone) {
1188 no_space = TRUE;
1189 break;
1194 if (ae & 0x00000000ffffffff) {
1196 * Redzone check is done at the end of this section.
1197 * This particular section will encode a maximum of
1198 * 3 * BYTES_PER_XDR_UNIT of data.
1200 if (ae &
1201 (FATTR4_MIMETYPE_MASK |
1202 FATTR4_MODE_MASK |
1203 FATTR4_NO_TRUNC_MASK |
1204 FATTR4_NUMLINKS_MASK)) {
1206 if (ae & FATTR4_MIMETYPE_MASK) {
1207 ASSERT(0);
1209 if (ae & FATTR4_MODE_MASK) {
1210 uint_t m = va.va_mode;
1211 IXDR_PUT_U_INT32(ptr, m);
1213 if (ae & FATTR4_NO_TRUNC_MASK) {
1214 IXDR_PUT_U_INT32(ptr, true);
1216 if (ae & FATTR4_NUMLINKS_MASK) {
1217 IXDR_PUT_U_INT32(ptr, va.va_nlink);
1219 /* Check the redzone boundary */
1220 if (ptr > ptr_redzone) {
1221 no_space = TRUE;
1222 break;
1226 * Redzone check is done before the encoding of the
1227 * owner string since the length is indeterminate.
1229 if (ae & FATTR4_OWNER_MASK) {
1230 if (!lu_set) {
1231 owner_error = nfs_idmap_uid_str(
1232 va.va_uid, &owner, TRUE);
1233 if (!owner_error) {
1234 lu_set = TRUE;
1235 lastuid = va.va_uid;
1237 } else if (va.va_uid != lastuid) {
1238 if (owner.utf8string_len != 0) {
1239 kmem_free(owner.utf8string_val,
1240 owner.utf8string_len);
1241 owner.utf8string_len = 0;
1242 owner.utf8string_val = NULL;
1244 owner_error = nfs_idmap_uid_str(
1245 va.va_uid, &owner, TRUE);
1246 if (!owner_error) {
1247 lastuid = va.va_uid;
1248 } else {
1249 lu_set = FALSE;
1252 if (!owner_error) {
1253 if ((ptr +
1254 (owner.utf8string_len /
1255 BYTES_PER_XDR_UNIT)
1256 + 2) > ptr_redzone) {
1257 no_space = TRUE;
1258 break;
1260 /* encode the LENGTH of owner string */
1261 IXDR_PUT_U_INT32(ptr,
1262 owner.utf8string_len);
1263 /* encode the RNDUP FILL first */
1264 rndup = RNDUP(owner.utf8string_len) /
1265 BYTES_PER_XDR_UNIT;
1266 ptr[rndup - 1] = 0;
1267 /* encode the OWNER */
1268 bcopy(owner.utf8string_val, ptr,
1269 owner.utf8string_len);
1270 ptr += rndup;
1274 * Redzone check is done before the encoding of the
1275 * group string since the length is indeterminate.
1277 if (ae & FATTR4_OWNER_GROUP_MASK) {
1278 if (!lg_set) {
1279 group_error =
1280 nfs_idmap_gid_str(va.va_gid,
1281 &group, TRUE);
1282 if (!group_error) {
1283 lg_set = TRUE;
1284 lastgid = va.va_gid;
1286 } else if (va.va_gid != lastgid) {
1287 if (group.utf8string_len != 0) {
1288 kmem_free(
1289 group.utf8string_val,
1290 group.utf8string_len);
1291 group.utf8string_len = 0;
1292 group.utf8string_val = NULL;
1294 group_error =
1295 nfs_idmap_gid_str(va.va_gid,
1296 &group, TRUE);
1297 if (!group_error)
1298 lastgid = va.va_gid;
1299 else
1300 lg_set = FALSE;
1302 if (!group_error) {
1303 if ((ptr +
1304 (group.utf8string_len /
1305 BYTES_PER_XDR_UNIT)
1306 + 2) > ptr_redzone) {
1307 no_space = TRUE;
1308 break;
1310 /* encode the LENGTH of owner string */
1311 IXDR_PUT_U_INT32(ptr,
1312 group.utf8string_len);
1313 /* encode the RNDUP FILL first */
1314 rndup = RNDUP(group.utf8string_len) /
1315 BYTES_PER_XDR_UNIT;
1316 ptr[rndup - 1] = 0;
1317 /* encode the OWNER */
1318 bcopy(group.utf8string_val, ptr,
1319 group.utf8string_len);
1320 ptr += rndup;
1323 if (ae &
1324 (FATTR4_QUOTA_AVAIL_HARD_MASK |
1325 FATTR4_QUOTA_AVAIL_SOFT_MASK |
1326 FATTR4_QUOTA_USED_MASK)) {
1327 if (ae & FATTR4_QUOTA_AVAIL_HARD_MASK) {
1328 ASSERT(0);
1330 if (ae & FATTR4_QUOTA_AVAIL_SOFT_MASK) {
1331 ASSERT(0);
1333 if (ae & FATTR4_QUOTA_USED_MASK) {
1334 ASSERT(0);
1338 * Redzone check is done at the end of this section.
1339 * This particular section will encode a maximum of
1340 * 10 * BYTES_PER_XDR_UNIT of data.
1342 if (ae &
1343 (FATTR4_RAWDEV_MASK |
1344 FATTR4_SPACE_AVAIL_MASK |
1345 FATTR4_SPACE_FREE_MASK |
1346 FATTR4_SPACE_TOTAL_MASK |
1347 FATTR4_SPACE_USED_MASK |
1348 FATTR4_SYSTEM_MASK)) {
1350 if (ae & FATTR4_RAWDEV_MASK) {
1351 fattr4_rawdev rd;
1352 rd.specdata1 =
1353 (uint32)getmajor(va.va_rdev);
1354 rd.specdata2 =
1355 (uint32)getminor(va.va_rdev);
1356 IXDR_PUT_U_INT32(ptr, rd.specdata1);
1357 IXDR_PUT_U_INT32(ptr, rd.specdata2);
1359 if (ae & FATTR4_SPACE_AVAIL_MASK) {
1360 IXDR_PUT_HYPER(ptr, sbe.space_avail);
1362 if (ae & FATTR4_SPACE_FREE_MASK) {
1363 IXDR_PUT_HYPER(ptr, sbe.space_free);
1365 if (ae & FATTR4_SPACE_TOTAL_MASK) {
1366 IXDR_PUT_HYPER(ptr, sbe.space_total);
1368 if (ae & FATTR4_SPACE_USED_MASK) {
1369 u_longlong_t su;
1370 su = (fattr4_space_used) DEV_BSIZE *
1371 (fattr4_space_used) va.va_nblocks;
1372 IXDR_PUT_HYPER(ptr, su);
1374 if (ae & FATTR4_SYSTEM_MASK) {
1375 ASSERT(0);
1377 /* Check the redzone boundary */
1378 if (ptr > ptr_redzone) {
1379 no_space = TRUE;
1380 break;
1384 * Redzone check is done at the end of this section.
1385 * This particular section will encode a maximum of
1386 * 14 * BYTES_PER_XDR_UNIT of data.
1388 if (ae &
1389 (FATTR4_TIME_ACCESS_MASK |
1390 FATTR4_TIME_ACCESS_SET_MASK |
1391 FATTR4_TIME_BACKUP_MASK |
1392 FATTR4_TIME_CREATE_MASK |
1393 FATTR4_TIME_DELTA_MASK |
1394 FATTR4_TIME_METADATA_MASK |
1395 FATTR4_TIME_MODIFY_MASK |
1396 FATTR4_TIME_MODIFY_SET_MASK |
1397 FATTR4_MOUNTED_ON_FILEID_MASK)) {
1399 if (ae & FATTR4_TIME_ACCESS_MASK) {
1400 u_longlong_t sec =
1401 (u_longlong_t)va.va_atime.tv_sec;
1402 uint_t nsec =
1403 (uint_t)va.va_atime.tv_nsec;
1404 IXDR_PUT_HYPER(ptr, sec);
1405 IXDR_PUT_INT32(ptr, nsec);
1407 if (ae & FATTR4_TIME_ACCESS_SET_MASK) {
1408 ASSERT(0);
1410 if (ae & FATTR4_TIME_BACKUP_MASK) {
1411 ASSERT(0);
1413 if (ae & FATTR4_TIME_CREATE_MASK) {
1414 ASSERT(0);
1416 if (ae & FATTR4_TIME_DELTA_MASK) {
1417 u_longlong_t sec = 0;
1418 uint_t nsec = 1000;
1419 IXDR_PUT_HYPER(ptr, sec);
1420 IXDR_PUT_INT32(ptr, nsec);
1422 if (ae & FATTR4_TIME_METADATA_MASK) {
1423 u_longlong_t sec =
1424 (u_longlong_t)va.va_ctime.tv_sec;
1425 uint_t nsec =
1426 (uint_t)va.va_ctime.tv_nsec;
1427 IXDR_PUT_HYPER(ptr, sec);
1428 IXDR_PUT_INT32(ptr, nsec);
1430 if (ae & FATTR4_TIME_MODIFY_MASK) {
1431 u_longlong_t sec =
1432 (u_longlong_t)va.va_mtime.tv_sec;
1433 uint_t nsec =
1434 (uint_t)va.va_mtime.tv_nsec;
1435 IXDR_PUT_HYPER(ptr, sec);
1436 IXDR_PUT_INT32(ptr, nsec);
1438 if (ae & FATTR4_TIME_MODIFY_SET_MASK) {
1439 ASSERT(0);
1441 if (ae & FATTR4_MOUNTED_ON_FILEID_MASK) {
1442 IXDR_PUT_HYPER(ptr, dp->d_ino);
1444 /* Check the redzone boundary */
1445 if (ptr > ptr_redzone) {
1446 no_space = TRUE;
1447 break;
1452 /* Reset to directory's vfs info when encoding complete */
1453 if (vfs_different) {
1454 dsbe = sbe;
1455 dpce = pce;
1456 vfs_different = 0;
1459 /* "go back" and encode the attributes' length */
1460 attr_length =
1461 (char *)ptr -
1462 (char *)attr_offset_ptr -
1463 BYTES_PER_XDR_UNIT;
1464 IXDR_PUT_U_INT32(attr_offset_ptr, attr_length);
1467 * If there was trouble obtaining a mapping for either
1468 * the owner or group attributes, then remove them from
1469 * bitmap4 for this entry and reset the bitmap value
1470 * in the data stream.
1472 if (owner_error || group_error) {
1473 if (owner_error)
1474 ae &= ~FATTR4_OWNER_MASK;
1475 if (group_error)
1476 ae &= ~FATTR4_OWNER_GROUP_MASK;
1477 IXDR_PUT_HYPER(attrmask_ptr, ae);
1480 /* END OF ATTRIBUTE ENCODING */
1482 lastentry_ptr = ptr;
1483 nents++;
1484 rddir_next_offset = dp->d_off;
1488 * Check for the case that another fop_readdir() has to be done.
1489 * - no space encoding error
1490 * - no entry successfully encoded
1491 * - still more directory to read
1493 if (!no_space && nents == 0 && !iseofdir)
1494 goto readagain;
1497 * If no_space is set then we terminated prematurely,
1498 * rewind to the last entry and this can never be EOF.
1500 if (no_space) {
1501 ptr = lastentry_ptr;
1502 eof = FALSE; /* ended encoded prematurely */
1503 } else {
1504 eof = (iseofdir ? TRUE : FALSE);
1508 * If we have entries, always return them, otherwise only error
1509 * if we ran out of space.
1511 if (nents || !no_space) {
1512 ASSERT(ptr != NULL);
1513 /* encode the BOOLEAN marking no further entries */
1514 IXDR_PUT_U_INT32(ptr, false);
1515 /* encode the BOOLEAN signifying end of directory */
1516 IXDR_PUT_U_INT32(ptr, eof);
1518 resp->data_len = (char *)ptr - (char *)beginning_ptr;
1519 resp->mblk->b_wptr += resp->data_len;
1520 } else {
1521 status = NFS4ERR_TOOSMALL;
1524 out_free:
1525 if (status != NFS4_OK) {
1526 freeb(mp);
1527 resp->mblk = NULL;
1528 resp->data_len = 0;
1531 *cs->statusp = resp->status = status;
1533 kmem_free((caddr_t)rddir_data, rddir_data_len);
1534 if (vp)
1535 VN_RELE(vp);
1536 if (owner.utf8string_len != 0)
1537 kmem_free(owner.utf8string_val, owner.utf8string_len);
1538 if (group.utf8string_len != 0)
1539 kmem_free(group.utf8string_val, group.utf8string_len);
1541 out:
1542 DTRACE_NFSV4_2(op__readdir__done, struct compound_state *, cs,
1543 READDIR4res *, resp);