dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / kernel / fs / nfs / nfs4_srv_readdir.c
blob7719c70e7cf233d08cd0d5da375ab8d1f5f1fcda
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 DIRENT64_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 DIRENT64_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 (DIRENT64_RECLEN(1) + DIRENT64_RECLEN(2) + DIRENT64_RECLEN(MAXNAMELEN))
95 #ifdef nextdp
96 #undef nextdp
97 #endif
98 #define nextdp(dp) ((struct dirent64 *)((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 nfs4_readdir_getvp(vnode_t *dvp, char *d_name, vnode_t **vpp,
108 struct exportinfo **exi, struct svc_req *req, struct compound_state *cs,
109 int expseudo)
111 int error;
112 int ismntpt;
113 fid_t fid;
114 vnode_t *vp, *pre_tvp;
115 nfsstat4 status;
116 struct exportinfo *newexi, *saveexi;
117 cred_t *scr;
119 *vpp = vp = NULL;
121 if (error = fop_lookup(dvp, d_name, &vp, NULL, 0, NULL, cs->cr,
122 NULL, NULL, NULL))
123 return (error);
126 * If the directory is a referral point, don't return the
127 * attrs, instead set rdattr_error to MOVED.
129 if (vn_is_nfs_reparse(vp, cs->cr) && !client_is_downrev(req)) {
130 VN_RELE(vp);
131 DTRACE_PROBE2(nfs4serv__func__referral__moved,
132 vnode_t *, vp, char *, "nfs4_readdir_getvp");
133 return (NFS4ERR_MOVED);
136 /* Is this object mounted upon? */
137 ismntpt = vn_ismntpt(vp);
140 * Nothing more to do if object is not a mount point or
141 * a possible LOFS shadow of an LOFS mount (which won't
142 * have v_vfsmountedhere set)
144 if (ismntpt == 0 && dvp->v_vfsp == vp->v_vfsp && expseudo == 0) {
145 *vpp = vp;
146 return (0);
149 if (ismntpt) {
151 * Something is mounted here. Traverse and manage the
152 * namespace
154 pre_tvp = vp;
155 VN_HOLD(pre_tvp);
157 if ((error = traverse(&vp)) != 0) {
158 VN_RELE(vp);
159 VN_RELE(pre_tvp);
160 return (error);
162 if (vn_is_nfs_reparse(vp, cs->cr)) {
163 VN_RELE(vp);
164 VN_RELE(pre_tvp);
165 DTRACE_PROBE2(nfs4serv__func__referral__moved,
166 vnode_t *, vp, char *, "nfs4_readdir_getvp");
167 return (NFS4ERR_MOVED);
171 bzero(&fid, sizeof (fid));
172 fid.fid_len = MAXFIDSZ;
175 * If fop_fid not supported by underlying fs (mntfs, procfs,
176 * etc.), then return attrs for stub instead of VROOT object.
177 * If it fails for any other reason, then return the error.
179 if (error = fop_fid(vp, &fid, NULL)) {
180 if (ismntpt == 0) {
181 VN_RELE(vp);
182 return (error);
185 if (error != ENOSYS && error != ENOTSUP) {
186 VN_RELE(vp);
187 VN_RELE(pre_tvp);
188 return (error);
190 /* go back to vnode that is "under" mount */
191 VN_RELE(vp);
192 *vpp = pre_tvp;
193 return (0);
196 newexi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid, vp);
197 if (newexi == NULL) {
198 if (ismntpt == 0) {
199 *vpp = vp;
200 } else {
201 VN_RELE(vp);
202 *vpp = pre_tvp;
204 return (0);
207 if (ismntpt)
208 VN_RELE(pre_tvp);
210 /* Save the exi and present the new one to checkauth4() */
211 saveexi = cs->exi;
212 cs->exi = newexi;
214 /* Get the right cred like lookup does */
215 scr = cs->cr;
216 cs->cr = crdup(cs->basecr);
218 status = call_checkauth4(cs, req);
220 crfree(cs->cr);
221 cs->cr = scr;
222 cs->exi = saveexi;
224 /* Reset what call_checkauth4() may have set */
225 *cs->statusp = NFS4_OK;
227 if (status != NFS4_OK) {
228 VN_RELE(vp);
229 if (status == NFS4ERR_DELAY)
230 status = NFS4ERR_ACCESS;
231 return (status);
233 *vpp = vp;
234 *exi = newexi;
236 return (0);
239 /* This is the set of pathconf data for vfs */
240 typedef struct {
241 uint64_t maxfilesize;
242 uint32_t maxlink;
243 uint32_t maxname;
244 } rfs4_pc_encode_t;
247 static int
248 rfs4_get_pc_encode(vnode_t *vp, rfs4_pc_encode_t *pce, bitmap4 ar, cred_t *cr)
250 int error;
251 ulong_t pc_val;
253 pce->maxfilesize = 0;
254 pce->maxlink = 0;
255 pce->maxname = 0;
257 if (ar & FATTR4_MAXFILESIZE_MASK) {
258 /* Maximum File Size */
259 error = fop_pathconf(vp, _PC_FILESIZEBITS, &pc_val, cr, NULL);
260 if (error)
261 return (error);
264 * If the underlying file system does not support
265 * _PC_FILESIZEBITS, return a reasonable default. Note that
266 * error code on fop_pathconf will be 0, even if the underlying
267 * file system does not support _PC_FILESIZEBITS.
269 if (pc_val == (ulong_t)-1) {
270 pce->maxfilesize = MAXOFF32_T;
271 } else {
272 if (pc_val >= (sizeof (uint64_t) * 8))
273 pce->maxfilesize = INT64_MAX;
274 else
275 pce->maxfilesize = ((1LL << (pc_val - 1)) - 1);
279 if (ar & FATTR4_MAXLINK_MASK) {
280 /* Maximum Link Count */
281 error = fop_pathconf(vp, _PC_LINK_MAX, &pc_val, cr, NULL);
282 if (error)
283 return (error);
285 pce->maxlink = pc_val;
288 if (ar & FATTR4_MAXNAME_MASK) {
289 /* Maximum Name Length */
290 error = fop_pathconf(vp, _PC_NAME_MAX, &pc_val, cr, NULL);
291 if (error)
292 return (error);
294 pce->maxname = pc_val;
297 return (0);
300 /* This is the set of statvfs data that is ready for encoding */
301 typedef struct {
302 uint64_t space_avail;
303 uint64_t space_free;
304 uint64_t space_total;
305 u_longlong_t fa;
306 u_longlong_t ff;
307 u_longlong_t ft;
308 } rfs4_sb_encode_t;
310 static int
311 rfs4_get_sb_encode(vfs_t *vfsp, rfs4_sb_encode_t *psbe)
313 int error;
314 struct statvfs64 sb;
316 /* Grab the per filesystem info */
317 if (error = VFS_STATVFS(vfsp, &sb)) {
318 return (error);
321 /* Calculate space available */
322 if (sb.f_bavail != (fsblkcnt64_t)-1) {
323 psbe->space_avail =
324 (fattr4_space_avail) sb.f_frsize *
325 (fattr4_space_avail) sb.f_bavail;
326 } else {
327 psbe->space_avail =
328 (fattr4_space_avail) sb.f_bavail;
331 /* Calculate space free */
332 if (sb.f_bfree != (fsblkcnt64_t)-1) {
333 psbe->space_free =
334 (fattr4_space_free) sb.f_frsize *
335 (fattr4_space_free) sb.f_bfree;
336 } else {
337 psbe->space_free =
338 (fattr4_space_free) sb.f_bfree;
341 /* Calculate space total */
342 if (sb.f_blocks != (fsblkcnt64_t)-1) {
343 psbe->space_total =
344 (fattr4_space_total) sb.f_frsize *
345 (fattr4_space_total) sb.f_blocks;
346 } else {
347 psbe->space_total =
348 (fattr4_space_total) sb.f_blocks;
351 /* For use later on attr encode */
352 psbe->fa = sb.f_favail;
353 psbe->ff = sb.f_ffree;
354 psbe->ft = sb.f_files;
356 return (0);
360 * Macros to handle if we have don't have enough space for the requested
361 * attributes and this is the first entry and the
362 * requested attributes are more than the minimal useful
363 * set, reset the attributes to the minimal set and
364 * retry the encoding. If the client has asked for both
365 * mounted_on_fileid and fileid, prefer mounted_on_fileid.
367 #define MINIMAL_RD_ATTRS \
368 (FATTR4_MOUNTED_ON_FILEID_MASK| \
369 FATTR4_FILEID_MASK| \
370 FATTR4_RDATTR_ERROR_MASK)
372 #define MINIMIZE_ATTR_MASK(m) { \
373 if ((m) & FATTR4_MOUNTED_ON_FILEID_MASK) \
374 (m) &= FATTR4_RDATTR_ERROR_MASK|FATTR4_MOUNTED_ON_FILEID_MASK;\
375 else \
376 (m) &= FATTR4_RDATTR_ERROR_MASK|FATTR4_FILEID_MASK; \
379 #define IS_MIN_ATTR_MASK(m) (((m) & ~MINIMAL_RD_ATTRS) == 0)
381 * If readdir only needs to return FILEID, we can take it from the
382 * dirent struct and save doing the lookup.
384 /* ARGSUSED */
385 void
386 rfs4_op_readdir(nfs_argop4 *argop, nfs_resop4 *resop, struct svc_req *req,
387 struct compound_state *cs)
389 READDIR4args *args = &argop->nfs_argop4_u.opreaddir;
390 READDIR4res *resp = &resop->nfs_resop4_u.opreaddir;
391 struct exportinfo *newexi = NULL;
392 int error;
393 mblk_t *mp;
394 uint_t mpcount;
395 int alloc_err = 0;
396 vnode_t *dvp = cs->vp;
397 vnode_t *vp;
398 vattr_t va;
399 struct dirent64 *dp;
400 rfs4_sb_encode_t dsbe, sbe;
401 int vfs_different;
402 int rddir_data_len, rddir_result_size;
403 caddr_t rddir_data;
404 offset_t rddir_next_offset;
405 int dircount;
406 int no_space;
407 int iseofdir;
408 uint_t eof;
409 struct iovec iov;
410 struct uio uio;
411 int tsize;
412 int check_visible;
413 struct exp_visible *visp;
415 uint32_t *ptr, *ptr_redzone;
416 uint32_t *beginning_ptr;
417 uint32_t *lastentry_ptr;
418 uint32_t *attrmask_ptr;
419 uint32_t *attr_offset_ptr;
420 uint32_t attr_length;
421 uint32_t rndup;
422 uint32_t namelen;
423 uint32_t rddirattr_error = 0;
424 int nents;
425 bitmap4 ar = args->attr_request & NFS4_SRV_RDDIR_SUPPORTED_ATTRS;
426 bitmap4 ae;
427 rfs4_pc_encode_t dpce, pce;
428 ulong_t pc_val;
429 uint64_t maxread;
430 uint64_t maxwrite;
431 uid_t lastuid;
432 gid_t lastgid;
433 int lu_set, lg_set;
434 utf8string owner, group;
435 int owner_error, group_error;
436 struct sockaddr *ca;
437 char *name = NULL;
439 DTRACE_NFSV4_2(op__readdir__start, struct compound_state *, cs,
440 READDIR4args *, args);
442 lu_set = lg_set = 0;
443 owner.utf8string_len = group.utf8string_len = 0;
444 owner.utf8string_val = group.utf8string_val = NULL;
446 resp->mblk = NULL;
448 /* Maximum read and write size */
449 maxread = maxwrite = rfs4_tsize(req);
451 if (dvp == NULL) {
452 *cs->statusp = resp->status = NFS4ERR_NOFILEHANDLE;
453 goto out;
457 * If there is an unshared filesystem mounted on this vnode,
458 * do not allow readdir in this directory.
460 if (vn_ismntpt(dvp)) {
461 *cs->statusp = resp->status = NFS4ERR_ACCESS;
462 goto out;
465 if (dvp->v_type != VDIR) {
466 *cs->statusp = resp->status = NFS4ERR_NOTDIR;
467 goto out;
470 if (args->maxcount <= RFS4_MINLEN_RDDIR4) {
471 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
472 goto out;
476 * If write-only attrs are requested, then fail the readdir op
478 if (args->attr_request &
479 (FATTR4_TIME_MODIFY_SET_MASK | FATTR4_TIME_ACCESS_SET_MASK)) {
480 *cs->statusp = resp->status = NFS4ERR_INVAL;
481 goto out;
484 error = fop_access(dvp, VREAD, 0, cs->cr, NULL);
485 if (error) {
486 *cs->statusp = resp->status = puterrno4(error);
487 goto out;
490 if (args->cookieverf != Readdir4verf) {
491 *cs->statusp = resp->status = NFS4ERR_NOT_SAME;
492 goto out;
495 /* Is there pseudo-fs work that is needed for this readdir? */
496 check_visible = PSEUDO(cs->exi) ||
497 ! is_exported_sec(cs->nfsflavor, cs->exi) ||
498 cs->access & CS_ACCESS_LIMITED;
500 /* Check the requested attributes and only do the work if needed */
502 if (ar & (FATTR4_MAXFILESIZE_MASK |
503 FATTR4_MAXLINK_MASK |
504 FATTR4_MAXNAME_MASK)) {
505 if (error = rfs4_get_pc_encode(cs->vp, &dpce, ar, cs->cr)) {
506 *cs->statusp = resp->status = puterrno4(error);
507 goto out;
509 pce = dpce;
512 /* If there is statvfs data requested, pick it up once */
513 if (ar &
514 (FATTR4_FILES_AVAIL_MASK |
515 FATTR4_FILES_FREE_MASK |
516 FATTR4_FILES_TOTAL_MASK |
517 FATTR4_FILES_AVAIL_MASK |
518 FATTR4_FILES_FREE_MASK |
519 FATTR4_FILES_TOTAL_MASK)) {
520 if (error = rfs4_get_sb_encode(dvp->v_vfsp, &dsbe)) {
521 *cs->statusp = resp->status = puterrno4(error);
522 goto out;
524 sbe = dsbe;
528 * Max transfer size of the server is the absolute limite.
529 * If the client has decided to max out with something really
530 * tiny, then return toosmall. Otherwise, move forward and
531 * see if a single entry can be encoded.
533 tsize = rfs4_tsize(req);
534 if (args->maxcount > tsize)
535 args->maxcount = tsize;
536 else if (args->maxcount < RFS4_MINLEN_RDDIR_BUF) {
537 if (args->maxcount < RFS4_MINLEN_ENTRY4) {
538 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
539 goto out;
544 * How large should the mblk be for outgoing encoding.
546 if (args->maxcount < MAXBSIZE)
547 mpcount = MAXBSIZE;
548 else
549 mpcount = args->maxcount;
552 * mp will contain the data to be sent out in the readdir reply.
553 * It will be freed after the reply has been sent.
554 * Let's roundup the data to a BYTES_PER_XDR_UNIX multiple,
555 * so that the call to xdrmblk_putmblk() never fails.
557 mp = allocb(RNDUP(mpcount), BPRI_MED);
559 if (mp == NULL) {
561 * The allocation of the client's requested size has
562 * failed. It may be that the size is too large for
563 * current system utilization; step down to a "common"
564 * size and wait for the allocation to occur.
566 if (mpcount > MAXBSIZE)
567 args->maxcount = mpcount = MAXBSIZE;
568 mp = allocb_wait(RNDUP(mpcount), BPRI_MED,
569 STR_NOSIG, &alloc_err);
572 ASSERT(mp != NULL);
573 ASSERT(alloc_err == 0);
575 resp->mblk = mp;
577 ptr = beginning_ptr = (uint32_t *)mp->b_datap->db_base;
580 * The "redzone" at the end of the encoding buffer is used
581 * to deal with xdr encoding length. Instead of checking
582 * each encoding of an attribute value before it is done,
583 * make the assumption that it will fit into the buffer and
584 * check occasionally.
586 * The largest block of attributes that are encoded without
587 * checking the redzone is 18 * BYTES_PER_XDR_UNIT (72 bytes)
588 * "round" to 128 as the redzone size.
590 if (args->maxcount < (mpcount - 128))
591 ptr_redzone =
592 (uint32_t *)(((char *)ptr) + RNDUP(args->maxcount));
593 else
594 ptr_redzone =
595 (uint32_t *)((((char *)ptr) + RNDUP(mpcount)) - 128);
598 * Set the dircount; this will be used as the size for the
599 * readdir of the underlying filesystem. First make sure
600 * that it is large enough to do a reasonable readdir (client
601 * may have short changed us - it is an advisory number);
602 * then make sure that it isn't too large.
603 * After all of that, if maxcount is "small" then just use
604 * that for the dircount number.
606 dircount = (args->dircount < MAXBSIZE) ? MAXBSIZE : args->dircount;
607 dircount = (dircount > tsize) ? tsize : dircount;
608 if (dircount > args->maxcount)
609 dircount = args->maxcount;
610 if (args->maxcount <= MAXBSIZE) {
611 if (args->maxcount < RFS4_MINLEN_RDDIR_BUF)
612 dircount = RFS4_MINLEN_RDDIR_BUF;
613 else
614 dircount = args->maxcount;
617 /* number of entries fully encoded in outgoing buffer */
618 nents = 0;
620 /* ENCODE READDIR4res.cookieverf */
621 IXDR_PUT_HYPER(ptr, Readdir4verf);
623 rddir_data_len = dircount;
624 rddir_data = kmem_alloc(rddir_data_len, KM_NOSLEEP);
625 if (rddir_data == NULL) {
626 /* The allocation failed; downsize and wait for it this time */
627 if (rddir_data_len > MAXBSIZE)
628 rddir_data_len = dircount = MAXBSIZE;
629 rddir_data = kmem_alloc(rddir_data_len, KM_SLEEP);
632 rddir_next_offset = (offset_t)args->cookie;
634 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
636 readagain:
638 no_space = FALSE;
639 iseofdir = FALSE;
641 vp = NULL;
643 /* Move on to reading the directory contents */
644 iov.iov_base = rddir_data;
645 iov.iov_len = rddir_data_len;
646 uio.uio_iov = &iov;
647 uio.uio_iovcnt = 1;
648 uio.uio_segflg = UIO_SYSSPACE;
649 uio.uio_extflg = UIO_COPY_CACHED;
650 uio.uio_loffset = rddir_next_offset;
651 uio.uio_resid = rddir_data_len;
653 (void) fop_rwlock(dvp, V_WRITELOCK_FALSE, NULL);
655 error = fop_readdir(dvp, &uio, cs->cr, &iseofdir, NULL, 0);
657 fop_rwunlock(dvp, V_WRITELOCK_FALSE, NULL);
659 if (error) {
660 kmem_free((caddr_t)rddir_data, rddir_data_len);
661 freeb(resp->mblk);
662 resp->mblk = NULL;
663 resp->data_len = 0;
664 *cs->statusp = resp->status = puterrno4(error);
665 goto out;
669 rddir_result_size = rddir_data_len - uio.uio_resid;
671 /* No data were read. Check if we reached the end of the directory. */
672 if (rddir_result_size == 0) {
673 /* encode the BOOLEAN marking no further entries */
674 IXDR_PUT_U_INT32(ptr, false);
675 /* encode the BOOLEAN signifying end of directory */
676 IXDR_PUT_U_INT32(ptr, iseofdir ? true : false);
677 resp->data_len = (char *)ptr - (char *)beginning_ptr;
678 resp->mblk->b_wptr += resp->data_len;
679 kmem_free((caddr_t)rddir_data, rddir_data_len);
680 *cs->statusp = resp->status = NFS4_OK;
681 goto out;
684 lastentry_ptr = ptr;
685 no_space = 0;
686 for (dp = (struct dirent64 *)rddir_data;
687 !no_space && rddir_result_size > 0; dp = nextdp(dp)) {
689 /* reset visp */
690 visp = NULL;
692 if (vp) {
693 VN_RELE(vp);
694 vp = NULL;
697 if (newexi)
698 newexi = NULL;
700 rddir_result_size -= dp->d_reclen;
702 /* skip "." and ".." entries */
703 if (dp->d_ino == 0 || NFS_IS_DOTNAME(dp->d_name)) {
704 rddir_next_offset = dp->d_off;
705 continue;
708 if (check_visible &&
709 !nfs_visible_inode(cs->exi, dp->d_ino, &visp)) {
710 rddir_next_offset = dp->d_off;
711 continue;
715 * Only if the client requested attributes...
716 * If the fop_lookup fails ENOENT, then skip this entry
717 * for the readdir response. If there was another error,
718 * then set the rddirattr_error and the error will be
719 * encoded later in the "attributes" section.
721 ae = ar;
722 if (ar == 0)
723 goto reencode_attrs;
725 error = nfs4_readdir_getvp(dvp, dp->d_name,
726 &vp, &newexi, req, cs,
727 visp != NULL ? visp->vis_exported : 0);
728 if (error == ENOENT) {
729 rddir_next_offset = dp->d_off;
730 continue;
733 rddirattr_error = error;
736 * The vp obtained from above may be from a
737 * different filesystem mount and the vfs-like
738 * attributes should be obtained from that
739 * different vfs; only do this if appropriate.
741 if (vp &&
742 (vfs_different = (dvp->v_vfsp != vp->v_vfsp))) {
743 if (ar & (FATTR4_FILES_AVAIL_MASK |
744 FATTR4_FILES_FREE_MASK |
745 FATTR4_FILES_TOTAL_MASK |
746 FATTR4_FILES_AVAIL_MASK |
747 FATTR4_FILES_FREE_MASK |
748 FATTR4_FILES_TOTAL_MASK)) {
749 if (error =
750 rfs4_get_sb_encode(dvp->v_vfsp,
751 &sbe)) {
752 /* Remove attrs from encode */
753 ae &= ~(FATTR4_FILES_AVAIL_MASK |
754 FATTR4_FILES_FREE_MASK |
755 FATTR4_FILES_TOTAL_MASK |
756 FATTR4_FILES_AVAIL_MASK |
757 FATTR4_FILES_FREE_MASK |
758 FATTR4_FILES_TOTAL_MASK);
759 rddirattr_error = error;
762 if (ar & (FATTR4_MAXFILESIZE_MASK |
763 FATTR4_MAXLINK_MASK |
764 FATTR4_MAXNAME_MASK)) {
765 if (error = rfs4_get_pc_encode(cs->vp,
766 &pce, ar, cs->cr)) {
767 ar &= ~(FATTR4_MAXFILESIZE_MASK |
768 FATTR4_MAXLINK_MASK |
769 FATTR4_MAXNAME_MASK);
770 rddirattr_error = error;
775 reencode_attrs:
776 /* encode the BOOLEAN for the existence of the next entry */
777 IXDR_PUT_U_INT32(ptr, true);
778 /* encode the COOKIE for the entry */
779 IXDR_PUT_U_HYPER(ptr, dp->d_off);
781 name = nfscmd_convname(ca, cs->exi, dp->d_name,
782 NFSCMD_CONV_OUTBOUND, MAXPATHLEN + 1);
784 if (name == NULL) {
785 rddir_next_offset = dp->d_off;
786 continue;
788 /* Calculate the dirent name length */
789 namelen = strlen(name);
791 rndup = RNDUP(namelen) / BYTES_PER_XDR_UNIT;
793 /* room for LENGTH + string ? */
794 if ((ptr + (1 + rndup)) > ptr_redzone) {
795 no_space = TRUE;
796 continue;
799 /* encode the LENGTH of the name */
800 IXDR_PUT_U_INT32(ptr, namelen);
801 /* encode the RNDUP FILL first */
802 ptr[rndup - 1] = 0;
803 /* encode the NAME of the entry */
804 bcopy(name, (char *)ptr, namelen);
805 /* now bump the ptr after... */
806 ptr += rndup;
808 if (name != dp->d_name)
809 kmem_free(name, MAXPATHLEN + 1);
812 * Keep checking on the dircount to see if we have
813 * reached the limit; from the RFC, dircount is to be
814 * the XDR encoded limit of the cookie plus name.
815 * So the count is the name, XDR_UNIT of length for
816 * that name and 2 * XDR_UNIT bytes of cookie;
817 * However, use the regular DIRENT64 to match most
818 * client's APIs.
820 dircount -= DIRENT64_RECLEN(namelen);
821 if (nents != 0 && dircount < 0) {
822 no_space = TRUE;
823 continue;
827 * Attributes requested?
828 * Gather up the attribute info and the previous fop_lookup()
829 * succeeded; if an error occurs on the fop_getattr() then
830 * return just the error (again if it is requested).
831 * Note that the previous fop_lookup() could have failed
832 * itself which leaves this code without anything for
833 * a fop_getattr().
834 * Also note that the readdir_attr_error is left in the
835 * encoding mask if requested and so is the mounted_on_fileid.
837 if (ae != 0) {
838 if (!vp) {
839 ae = ar & (FATTR4_RDATTR_ERROR_MASK |
840 FATTR4_MOUNTED_ON_FILEID_MASK);
841 } else {
842 va.va_mask = AT_ALL;
843 rddirattr_error =
844 fop_getattr(vp, &va, 0, cs->cr, NULL);
845 if (rddirattr_error) {
846 ae = ar & (FATTR4_RDATTR_ERROR_MASK |
847 FATTR4_MOUNTED_ON_FILEID_MASK);
848 } else {
850 * We may lie about the object
851 * type for a referral
853 if (vn_is_nfs_reparse(vp, cs->cr) &&
854 client_is_downrev(req))
855 va.va_type = VLNK;
860 /* START OF ATTRIBUTE ENCODING */
862 /* encode the LENGTH of the BITMAP4 array */
863 IXDR_PUT_U_INT32(ptr, 2);
864 /* encode the BITMAP4 */
865 attrmask_ptr = ptr;
866 IXDR_PUT_HYPER(ptr, ae);
867 attr_offset_ptr = ptr;
868 /* encode the default LENGTH of the attributes for entry */
869 IXDR_PUT_U_INT32(ptr, 0);
871 if (ptr > ptr_redzone) {
872 no_space = TRUE;
873 continue;
876 /* Check if any of the first 32 attributes are being encoded */
877 if (ae & 0xffffffff00000000) {
879 * Redzone check is done at the end of this section.
880 * This particular section will encode a maximum of
881 * 18 * BYTES_PER_XDR_UNIT of data
883 if (ae &
884 (FATTR4_SUPPORTED_ATTRS_MASK |
885 FATTR4_TYPE_MASK |
886 FATTR4_FH_EXPIRE_TYPE_MASK |
887 FATTR4_CHANGE_MASK |
888 FATTR4_SIZE_MASK |
889 FATTR4_LINK_SUPPORT_MASK |
890 FATTR4_SYMLINK_SUPPORT_MASK |
891 FATTR4_NAMED_ATTR_MASK |
892 FATTR4_FSID_MASK |
893 FATTR4_UNIQUE_HANDLES_MASK |
894 FATTR4_LEASE_TIME_MASK |
895 FATTR4_RDATTR_ERROR_MASK)) {
897 if (ae & FATTR4_SUPPORTED_ATTRS_MASK) {
898 IXDR_PUT_INT32(ptr, 2);
899 IXDR_PUT_HYPER(ptr,
900 rfs4_supported_attrs);
902 if (ae & FATTR4_TYPE_MASK) {
903 uint_t ftype = vt_to_nf4[va.va_type];
904 if (dvp->v_flag & V_XATTRDIR) {
905 if (va.va_type == VDIR)
906 ftype = NF4ATTRDIR;
907 else
908 ftype = NF4NAMEDATTR;
910 IXDR_PUT_U_INT32(ptr, ftype);
912 if (ae & FATTR4_FH_EXPIRE_TYPE_MASK) {
913 uint_t expire_type = FH4_PERSISTENT;
914 IXDR_PUT_U_INT32(ptr, expire_type);
916 if (ae & FATTR4_CHANGE_MASK) {
917 u_longlong_t change;
918 NFS4_SET_FATTR4_CHANGE(change,
919 va.va_ctime);
920 if (visp != NULL) {
921 u_longlong_t visch;
922 NFS4_SET_FATTR4_CHANGE(visch,
923 visp->vis_change);
924 if (visch > change)
925 change = visch;
927 IXDR_PUT_HYPER(ptr, change);
929 if (ae & FATTR4_SIZE_MASK) {
930 u_longlong_t size = va.va_size;
931 IXDR_PUT_HYPER(ptr, size);
933 if (ae & FATTR4_LINK_SUPPORT_MASK) {
934 IXDR_PUT_U_INT32(ptr, true);
936 if (ae & FATTR4_SYMLINK_SUPPORT_MASK) {
937 IXDR_PUT_U_INT32(ptr, true);
939 if (ae & FATTR4_NAMED_ATTR_MASK) {
940 uint_t isit;
941 pc_val = FALSE;
942 int sattr_error;
944 if (!(vp->v_vfsp->vfs_flag &
945 VFS_XATTR)) {
946 isit = FALSE;
947 } else {
948 sattr_error = fop_pathconf(vp,
949 _PC_SATTR_EXISTS,
950 &pc_val, cs->cr, NULL);
951 if (sattr_error || pc_val == 0)
952 (void) fop_pathconf(vp,
953 _PC_XATTR_EXISTS,
954 &pc_val,
955 cs->cr, NULL);
957 isit = (pc_val ? TRUE : FALSE);
958 IXDR_PUT_U_INT32(ptr, isit);
960 if (ae & FATTR4_FSID_MASK) {
961 u_longlong_t major, minor;
962 struct exportinfo *exi;
964 exi = newexi ? newexi : cs->exi;
965 if (exi->exi_volatile_dev) {
966 int *pmaj = (int *)&major;
968 pmaj[0] = exi->exi_fsid.val[0];
969 pmaj[1] = exi->exi_fsid.val[1];
970 minor = 0;
971 } else {
972 major = getmajor(va.va_fsid);
973 minor = getminor(va.va_fsid);
975 IXDR_PUT_HYPER(ptr, major);
976 IXDR_PUT_HYPER(ptr, minor);
978 if (ae & FATTR4_UNIQUE_HANDLES_MASK) {
979 IXDR_PUT_U_INT32(ptr, false);
981 if (ae & FATTR4_LEASE_TIME_MASK) {
982 uint_t lt = rfs4_lease_time;
983 IXDR_PUT_U_INT32(ptr, lt);
985 if (ae & FATTR4_RDATTR_ERROR_MASK) {
986 rddirattr_error =
987 (rddirattr_error == 0 ?
988 0 : puterrno4(rddirattr_error));
989 IXDR_PUT_U_INT32(ptr, rddirattr_error);
992 /* Check the redzone boundary */
993 if (ptr > ptr_redzone) {
994 if (nents || IS_MIN_ATTR_MASK(ar)) {
995 no_space = TRUE;
996 continue;
998 MINIMIZE_ATTR_MASK(ar);
999 ae = ar;
1000 ptr = lastentry_ptr;
1001 goto reencode_attrs;
1005 * Redzone check is done at the end of this section.
1006 * This particular section will encode a maximum of
1007 * 4 * BYTES_PER_XDR_UNIT of data.
1008 * NOTE: that if ACLs are supported that the
1009 * redzone calculations will need to change.
1011 if (ae &
1012 (FATTR4_ACL_MASK |
1013 FATTR4_ACLSUPPORT_MASK |
1014 FATTR4_ARCHIVE_MASK |
1015 FATTR4_CANSETTIME_MASK |
1016 FATTR4_CASE_INSENSITIVE_MASK |
1017 FATTR4_CASE_PRESERVING_MASK |
1018 FATTR4_CHOWN_RESTRICTED_MASK)) {
1020 if (ae & FATTR4_ACL_MASK) {
1021 ASSERT(0);
1023 if (ae & FATTR4_ACLSUPPORT_MASK) {
1024 ASSERT(0);
1026 if (ae & FATTR4_ARCHIVE_MASK) {
1027 ASSERT(0);
1029 if (ae & FATTR4_CANSETTIME_MASK) {
1030 IXDR_PUT_U_INT32(ptr, true);
1032 if (ae & FATTR4_CASE_INSENSITIVE_MASK) {
1033 IXDR_PUT_U_INT32(ptr, false);
1035 if (ae & FATTR4_CASE_PRESERVING_MASK) {
1036 IXDR_PUT_U_INT32(ptr, true);
1038 if (ae & FATTR4_CHOWN_RESTRICTED_MASK) {
1039 uint_t isit;
1040 pc_val = FALSE;
1041 (void) fop_pathconf(vp,
1042 _PC_CHOWN_RESTRICTED,
1043 &pc_val, cs->cr, NULL);
1044 isit = (pc_val ? TRUE : FALSE);
1045 IXDR_PUT_U_INT32(ptr, isit);
1047 /* Check the redzone boundary */
1048 if (ptr > ptr_redzone) {
1049 if (nents || IS_MIN_ATTR_MASK(ar)) {
1050 no_space = TRUE;
1051 continue;
1053 MINIMIZE_ATTR_MASK(ar);
1054 ae = ar;
1055 ptr = lastentry_ptr;
1056 goto reencode_attrs;
1060 * Redzone check is done before the filehandle
1061 * is encoded.
1063 if (ae &
1064 (FATTR4_FILEHANDLE_MASK |
1065 FATTR4_FILEID_MASK)) {
1067 if (ae & FATTR4_FILEHANDLE_MASK) {
1068 struct {
1069 uint_t len;
1070 char *val;
1071 char fh[NFS_FH4_LEN];
1072 } fh;
1073 fh.len = 0;
1074 fh.val = fh.fh;
1075 (void) makefh4((nfs_fh4 *)&fh, vp,
1076 (newexi ? newexi : cs->exi));
1078 if (dvp->v_flag & V_XATTRDIR)
1079 set_fh4_flag((nfs_fh4 *)&fh,
1080 FH4_NAMEDATTR);
1082 if (!xdr_inline_encode_nfs_fh4(
1083 &ptr, ptr_redzone,
1084 (nfs_fh4_fmt_t *)fh.val)) {
1085 if (nents ||
1086 IS_MIN_ATTR_MASK(ar)) {
1087 no_space = TRUE;
1088 continue;
1090 MINIMIZE_ATTR_MASK(ar);
1091 ae = ar;
1092 ptr = lastentry_ptr;
1093 goto reencode_attrs;
1096 if (ae & FATTR4_FILEID_MASK) {
1097 IXDR_PUT_HYPER(ptr, va.va_nodeid);
1099 /* Check the redzone boundary */
1100 if (ptr > ptr_redzone) {
1101 if (nents || IS_MIN_ATTR_MASK(ar)) {
1102 no_space = TRUE;
1103 continue;
1105 MINIMIZE_ATTR_MASK(ar);
1106 ae = ar;
1107 ptr = lastentry_ptr;
1108 goto reencode_attrs;
1112 * Redzone check is done at the end of this section.
1113 * This particular section will encode a maximum of
1114 * 15 * BYTES_PER_XDR_UNIT of data.
1116 if (ae &
1117 (FATTR4_FILES_AVAIL_MASK |
1118 FATTR4_FILES_FREE_MASK |
1119 FATTR4_FILES_TOTAL_MASK |
1120 FATTR4_FS_LOCATIONS_MASK |
1121 FATTR4_HIDDEN_MASK |
1122 FATTR4_HOMOGENEOUS_MASK |
1123 FATTR4_MAXFILESIZE_MASK |
1124 FATTR4_MAXLINK_MASK |
1125 FATTR4_MAXNAME_MASK |
1126 FATTR4_MAXREAD_MASK |
1127 FATTR4_MAXWRITE_MASK)) {
1129 if (ae & FATTR4_FILES_AVAIL_MASK) {
1130 IXDR_PUT_HYPER(ptr, sbe.fa);
1132 if (ae & FATTR4_FILES_FREE_MASK) {
1133 IXDR_PUT_HYPER(ptr, sbe.ff);
1135 if (ae & FATTR4_FILES_TOTAL_MASK) {
1136 IXDR_PUT_HYPER(ptr, sbe.ft);
1138 if (ae & FATTR4_FS_LOCATIONS_MASK) {
1139 ASSERT(0);
1141 if (ae & FATTR4_HIDDEN_MASK) {
1142 ASSERT(0);
1144 if (ae & FATTR4_HOMOGENEOUS_MASK) {
1145 IXDR_PUT_U_INT32(ptr, true);
1147 if (ae & FATTR4_MAXFILESIZE_MASK) {
1148 IXDR_PUT_HYPER(ptr, pce.maxfilesize);
1150 if (ae & FATTR4_MAXLINK_MASK) {
1151 IXDR_PUT_U_INT32(ptr, pce.maxlink);
1153 if (ae & FATTR4_MAXNAME_MASK) {
1154 IXDR_PUT_U_INT32(ptr, pce.maxname);
1156 if (ae & FATTR4_MAXREAD_MASK) {
1157 IXDR_PUT_HYPER(ptr, maxread);
1159 if (ae & FATTR4_MAXWRITE_MASK) {
1160 IXDR_PUT_HYPER(ptr, maxwrite);
1162 /* Check the redzone boundary */
1163 if (ptr > ptr_redzone) {
1164 if (nents || IS_MIN_ATTR_MASK(ar)) {
1165 no_space = TRUE;
1166 continue;
1168 MINIMIZE_ATTR_MASK(ar);
1169 ae = ar;
1170 ptr = lastentry_ptr;
1171 goto reencode_attrs;
1175 if (ae & 0x00000000ffffffff) {
1177 * Redzone check is done at the end of this section.
1178 * This particular section will encode a maximum of
1179 * 3 * BYTES_PER_XDR_UNIT of data.
1181 if (ae &
1182 (FATTR4_MIMETYPE_MASK |
1183 FATTR4_MODE_MASK |
1184 FATTR4_NO_TRUNC_MASK |
1185 FATTR4_NUMLINKS_MASK)) {
1187 if (ae & FATTR4_MIMETYPE_MASK) {
1188 ASSERT(0);
1190 if (ae & FATTR4_MODE_MASK) {
1191 uint_t m = va.va_mode;
1192 IXDR_PUT_U_INT32(ptr, m);
1194 if (ae & FATTR4_NO_TRUNC_MASK) {
1195 IXDR_PUT_U_INT32(ptr, true);
1197 if (ae & FATTR4_NUMLINKS_MASK) {
1198 IXDR_PUT_U_INT32(ptr, va.va_nlink);
1200 /* Check the redzone boundary */
1201 if (ptr > ptr_redzone) {
1202 if (nents || IS_MIN_ATTR_MASK(ar)) {
1203 no_space = TRUE;
1204 continue;
1206 MINIMIZE_ATTR_MASK(ar);
1207 ae = ar;
1208 ptr = lastentry_ptr;
1209 goto reencode_attrs;
1213 * Redzone check is done before the encoding of the
1214 * owner string since the length is indeterminate.
1216 if (ae & FATTR4_OWNER_MASK) {
1217 if (!lu_set) {
1218 owner_error = nfs_idmap_uid_str(
1219 va.va_uid, &owner, TRUE);
1220 if (!owner_error) {
1221 lu_set = TRUE;
1222 lastuid = va.va_uid;
1224 } else if (va.va_uid != lastuid) {
1225 if (owner.utf8string_len != 0) {
1226 kmem_free(owner.utf8string_val,
1227 owner.utf8string_len);
1228 owner.utf8string_len = 0;
1229 owner.utf8string_val = NULL;
1231 owner_error = nfs_idmap_uid_str(
1232 va.va_uid, &owner, TRUE);
1233 if (!owner_error) {
1234 lastuid = va.va_uid;
1235 } else {
1236 lu_set = FALSE;
1239 if (!owner_error) {
1240 if ((ptr +
1241 (owner.utf8string_len /
1242 BYTES_PER_XDR_UNIT)
1243 + 2) > ptr_redzone) {
1244 if (nents ||
1245 IS_MIN_ATTR_MASK(ar)) {
1246 no_space = TRUE;
1247 continue;
1249 MINIMIZE_ATTR_MASK(ar);
1250 ae = ar;
1251 ptr = lastentry_ptr;
1252 goto reencode_attrs;
1254 /* encode the LENGTH of owner string */
1255 IXDR_PUT_U_INT32(ptr,
1256 owner.utf8string_len);
1257 /* encode the RNDUP FILL first */
1258 rndup = RNDUP(owner.utf8string_len) /
1259 BYTES_PER_XDR_UNIT;
1260 ptr[rndup - 1] = 0;
1261 /* encode the OWNER */
1262 bcopy(owner.utf8string_val, ptr,
1263 owner.utf8string_len);
1264 ptr += rndup;
1268 * Redzone check is done before the encoding of the
1269 * group string since the length is indeterminate.
1271 if (ae & FATTR4_OWNER_GROUP_MASK) {
1272 if (!lg_set) {
1273 group_error =
1274 nfs_idmap_gid_str(va.va_gid,
1275 &group, TRUE);
1276 if (!group_error) {
1277 lg_set = TRUE;
1278 lastgid = va.va_gid;
1280 } else if (va.va_gid != lastgid) {
1281 if (group.utf8string_len != 0) {
1282 kmem_free(
1283 group.utf8string_val,
1284 group.utf8string_len);
1285 group.utf8string_len = 0;
1286 group.utf8string_val = NULL;
1288 group_error =
1289 nfs_idmap_gid_str(va.va_gid,
1290 &group, TRUE);
1291 if (!group_error)
1292 lastgid = va.va_gid;
1293 else
1294 lg_set = FALSE;
1296 if (!group_error) {
1297 if ((ptr +
1298 (group.utf8string_len /
1299 BYTES_PER_XDR_UNIT)
1300 + 2) > ptr_redzone) {
1301 if (nents ||
1302 IS_MIN_ATTR_MASK(ar)) {
1303 no_space = TRUE;
1304 continue;
1306 MINIMIZE_ATTR_MASK(ar);
1307 ae = ar;
1308 ptr = lastentry_ptr;
1309 goto reencode_attrs;
1311 /* encode the LENGTH of owner string */
1312 IXDR_PUT_U_INT32(ptr,
1313 group.utf8string_len);
1314 /* encode the RNDUP FILL first */
1315 rndup = RNDUP(group.utf8string_len) /
1316 BYTES_PER_XDR_UNIT;
1317 ptr[rndup - 1] = 0;
1318 /* encode the OWNER */
1319 bcopy(group.utf8string_val, ptr,
1320 group.utf8string_len);
1321 ptr += rndup;
1324 if (ae &
1325 (FATTR4_QUOTA_AVAIL_HARD_MASK |
1326 FATTR4_QUOTA_AVAIL_SOFT_MASK |
1327 FATTR4_QUOTA_USED_MASK)) {
1328 if (ae & FATTR4_QUOTA_AVAIL_HARD_MASK) {
1329 ASSERT(0);
1331 if (ae & FATTR4_QUOTA_AVAIL_SOFT_MASK) {
1332 ASSERT(0);
1334 if (ae & FATTR4_QUOTA_USED_MASK) {
1335 ASSERT(0);
1339 * Redzone check is done at the end of this section.
1340 * This particular section will encode a maximum of
1341 * 10 * BYTES_PER_XDR_UNIT of data.
1343 if (ae &
1344 (FATTR4_RAWDEV_MASK |
1345 FATTR4_SPACE_AVAIL_MASK |
1346 FATTR4_SPACE_FREE_MASK |
1347 FATTR4_SPACE_TOTAL_MASK |
1348 FATTR4_SPACE_USED_MASK |
1349 FATTR4_SYSTEM_MASK)) {
1351 if (ae & FATTR4_RAWDEV_MASK) {
1352 fattr4_rawdev rd;
1353 rd.specdata1 =
1354 (uint32)getmajor(va.va_rdev);
1355 rd.specdata2 =
1356 (uint32)getminor(va.va_rdev);
1357 IXDR_PUT_U_INT32(ptr, rd.specdata1);
1358 IXDR_PUT_U_INT32(ptr, rd.specdata2);
1360 if (ae & FATTR4_SPACE_AVAIL_MASK) {
1361 IXDR_PUT_HYPER(ptr, sbe.space_avail);
1363 if (ae & FATTR4_SPACE_FREE_MASK) {
1364 IXDR_PUT_HYPER(ptr, sbe.space_free);
1366 if (ae & FATTR4_SPACE_TOTAL_MASK) {
1367 IXDR_PUT_HYPER(ptr, sbe.space_total);
1369 if (ae & FATTR4_SPACE_USED_MASK) {
1370 u_longlong_t su;
1371 su = (fattr4_space_used) DEV_BSIZE *
1372 (fattr4_space_used) va.va_nblocks;
1373 IXDR_PUT_HYPER(ptr, su);
1375 if (ae & FATTR4_SYSTEM_MASK) {
1376 ASSERT(0);
1378 /* Check the redzone boundary */
1379 if (ptr > ptr_redzone) {
1380 if (nents || IS_MIN_ATTR_MASK(ar)) {
1381 no_space = TRUE;
1382 continue;
1384 MINIMIZE_ATTR_MASK(ar);
1385 ae = ar;
1386 ptr = lastentry_ptr;
1387 goto reencode_attrs;
1391 * Redzone check is done at the end of this section.
1392 * This particular section will encode a maximum of
1393 * 14 * BYTES_PER_XDR_UNIT of data.
1395 if (ae &
1396 (FATTR4_TIME_ACCESS_MASK |
1397 FATTR4_TIME_ACCESS_SET_MASK |
1398 FATTR4_TIME_BACKUP_MASK |
1399 FATTR4_TIME_CREATE_MASK |
1400 FATTR4_TIME_DELTA_MASK |
1401 FATTR4_TIME_METADATA_MASK |
1402 FATTR4_TIME_MODIFY_MASK |
1403 FATTR4_TIME_MODIFY_SET_MASK |
1404 FATTR4_MOUNTED_ON_FILEID_MASK)) {
1406 if (ae & FATTR4_TIME_ACCESS_MASK) {
1407 u_longlong_t sec =
1408 (u_longlong_t)va.va_atime.tv_sec;
1409 uint_t nsec =
1410 (uint_t)va.va_atime.tv_nsec;
1411 IXDR_PUT_HYPER(ptr, sec);
1412 IXDR_PUT_INT32(ptr, nsec);
1414 if (ae & FATTR4_TIME_ACCESS_SET_MASK) {
1415 ASSERT(0);
1417 if (ae & FATTR4_TIME_BACKUP_MASK) {
1418 ASSERT(0);
1420 if (ae & FATTR4_TIME_CREATE_MASK) {
1421 ASSERT(0);
1423 if (ae & FATTR4_TIME_DELTA_MASK) {
1424 u_longlong_t sec = 0;
1425 uint_t nsec = 1000;
1426 IXDR_PUT_HYPER(ptr, sec);
1427 IXDR_PUT_INT32(ptr, nsec);
1429 if (ae & FATTR4_TIME_METADATA_MASK) {
1430 u_longlong_t sec =
1431 (u_longlong_t)va.va_ctime.tv_sec;
1432 uint_t nsec =
1433 (uint_t)va.va_ctime.tv_nsec;
1434 IXDR_PUT_HYPER(ptr, sec);
1435 IXDR_PUT_INT32(ptr, nsec);
1437 if (ae & FATTR4_TIME_MODIFY_MASK) {
1438 u_longlong_t sec =
1439 (u_longlong_t)va.va_mtime.tv_sec;
1440 uint_t nsec =
1441 (uint_t)va.va_mtime.tv_nsec;
1442 IXDR_PUT_HYPER(ptr, sec);
1443 IXDR_PUT_INT32(ptr, nsec);
1445 if (ae & FATTR4_TIME_MODIFY_SET_MASK) {
1446 ASSERT(0);
1448 if (ae & FATTR4_MOUNTED_ON_FILEID_MASK) {
1449 IXDR_PUT_HYPER(ptr, dp->d_ino);
1451 /* Check the redzone boundary */
1452 if (ptr > ptr_redzone) {
1453 if (nents || IS_MIN_ATTR_MASK(ar)) {
1454 no_space = TRUE;
1455 continue;
1457 MINIMIZE_ATTR_MASK(ar);
1458 ae = ar;
1459 ptr = lastentry_ptr;
1460 goto reencode_attrs;
1465 /* Reset to directory's vfs info when encoding complete */
1466 if (vfs_different) {
1467 dsbe = sbe;
1468 dpce = pce;
1469 vfs_different = 0;
1472 /* "go back" and encode the attributes' length */
1473 attr_length =
1474 (char *)ptr -
1475 (char *)attr_offset_ptr -
1476 BYTES_PER_XDR_UNIT;
1477 IXDR_PUT_U_INT32(attr_offset_ptr, attr_length);
1480 * If there was trouble obtaining a mapping for either
1481 * the owner or group attributes, then remove them from
1482 * bitmap4 for this entry and reset the bitmap value
1483 * in the data stream.
1485 if (owner_error || group_error) {
1486 if (owner_error)
1487 ae &= ~FATTR4_OWNER_MASK;
1488 if (group_error)
1489 ae &= ~FATTR4_OWNER_GROUP_MASK;
1490 IXDR_PUT_HYPER(attrmask_ptr, ae);
1493 /* END OF ATTRIBUTE ENCODING */
1495 lastentry_ptr = ptr;
1496 nents++;
1497 rddir_next_offset = dp->d_off;
1501 * Check for the case that another fop_readdir() has to be done.
1502 * - no space encoding error
1503 * - no entry successfully encoded
1504 * - still more directory to read
1506 if (!no_space && nents == 0 && !iseofdir)
1507 goto readagain;
1509 *cs->statusp = resp->status = NFS4_OK;
1512 * If no_space is set then we terminated prematurely,
1513 * rewind to the last entry and this can never be EOF.
1515 if (no_space) {
1516 ptr = lastentry_ptr;
1517 eof = FALSE; /* ended encoded prematurely */
1518 } else {
1519 eof = (iseofdir ? TRUE : FALSE);
1523 * If we have entries, always return them, otherwise only error
1524 * if we ran out of space.
1526 if (nents || !no_space) {
1527 ASSERT(ptr != NULL);
1528 /* encode the BOOLEAN marking no further entries */
1529 IXDR_PUT_U_INT32(ptr, false);
1530 /* encode the BOOLEAN signifying end of directory */
1531 IXDR_PUT_U_INT32(ptr, eof);
1533 resp->data_len = (char *)ptr - (char *)beginning_ptr;
1534 resp->mblk->b_wptr += resp->data_len;
1535 } else {
1536 freeb(mp);
1537 resp->mblk = NULL;
1538 resp->data_len = 0;
1539 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
1542 kmem_free((caddr_t)rddir_data, rddir_data_len);
1543 if (vp)
1544 VN_RELE(vp);
1545 if (owner.utf8string_len != 0)
1546 kmem_free(owner.utf8string_val, owner.utf8string_len);
1547 if (group.utf8string_len != 0)
1548 kmem_free(group.utf8string_val, group.utf8string_len);
1550 out:
1551 DTRACE_NFSV4_2(op__readdir__done, struct compound_state *, cs,
1552 READDIR4res *, resp);