0
|
1 |
/*
|
|
2 |
* CDDL HEADER START
|
|
3 |
*
|
|
4 |
* The contents of this file are subject to the terms of the
|
|
5 |
* Common Development and Distribution License, Version 1.0 only
|
|
6 |
* (the "License"). You may not use this file except in compliance
|
|
7 |
* with the License.
|
|
8 |
*
|
|
9 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
10 |
* or http://www.opensolaris.org/os/licensing.
|
|
11 |
* See the License for the specific language governing permissions
|
|
12 |
* and limitations under the License.
|
|
13 |
*
|
|
14 |
* When distributing Covered Code, include this CDDL HEADER in each
|
|
15 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
16 |
* If applicable, add the following below this CDDL HEADER, with the
|
|
17 |
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
18 |
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
19 |
*
|
|
20 |
* CDDL HEADER END
|
|
21 |
*/
|
|
22 |
/*
|
|
23 |
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
|
|
24 |
* Use is subject to license terms.
|
|
25 |
*/
|
|
26 |
|
|
27 |
#pragma ident "%Z%%M% %I% %E% SMI"
|
|
28 |
|
|
29 |
#include <sys/param.h>
|
|
30 |
#include <sys/types.h>
|
|
31 |
#include <sys/systm.h>
|
|
32 |
#include <sys/cred.h>
|
|
33 |
#include <sys/buf.h>
|
|
34 |
#include <sys/vfs.h>
|
|
35 |
#include <sys/vnode.h>
|
|
36 |
#include <sys/uio.h>
|
|
37 |
#include <sys/errno.h>
|
|
38 |
#include <sys/sysmacros.h>
|
|
39 |
#include <sys/statvfs.h>
|
|
40 |
#include <sys/kmem.h>
|
|
41 |
#include <sys/dirent.h>
|
|
42 |
#include <rpc/types.h>
|
|
43 |
#include <rpc/auth.h>
|
|
44 |
#include <rpc/rpcsec_gss.h>
|
|
45 |
#include <rpc/svc.h>
|
|
46 |
#include <sys/strsubr.h>
|
|
47 |
#include <sys/strsun.h>
|
|
48 |
#include <sys/sdt.h>
|
|
49 |
|
|
50 |
#include <nfs/nfs.h>
|
|
51 |
#include <nfs/export.h>
|
|
52 |
#include <nfs/nfs4.h>
|
|
53 |
|
|
54 |
|
|
55 |
/*
|
|
56 |
* RFS4_MINLEN_ENTRY4: XDR-encoded size of smallest possible dirent.
|
|
57 |
* This is used to return NFS4ERR_TOOSMALL when clients specify
|
|
58 |
* maxcount that isn't large enough to hold the smallest possible
|
|
59 |
* XDR encoded dirent.
|
|
60 |
*
|
|
61 |
* sizeof cookie (8 bytes) +
|
|
62 |
* sizeof name_len (4 bytes) +
|
|
63 |
* sizeof smallest (padded) name (4 bytes) +
|
|
64 |
* sizeof bitmap4_len (12 bytes) + NOTE: we always encode len=2 bm4
|
|
65 |
* sizeof attrlist4_len (4 bytes) +
|
|
66 |
* sizeof next boolean (4 bytes)
|
|
67 |
*
|
|
68 |
* RFS4_MINLEN_RDDIR4: XDR-encoded size of READDIR op reply containing
|
|
69 |
* the smallest possible entry4 (assumes no attrs requested).
|
|
70 |
* sizeof nfsstat4 (4 bytes) +
|
|
71 |
* sizeof verifier4 (8 bytes) +
|
|
72 |
* sizeof entsecond_to_ry4list bool (4 bytes) +
|
|
73 |
* sizeof entry4 (36 bytes) +
|
|
74 |
* sizeof eof bool (4 bytes)
|
|
75 |
*
|
|
76 |
* RFS4_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
|
|
77 |
* VOP_READDIR. Its value is the size of the maximum possible dirent
|
|
78 |
* for solaris. The DIRENT64_RECLEN macro returns the size of dirent
|
|
79 |
* required for a given name length. MAXNAMELEN is the maximum
|
|
80 |
* filename length allowed in Solaris. The first two DIRENT64_RECLEN()
|
|
81 |
* macros are to allow for . and .. entries -- just a minor tweak to try
|
|
82 |
* and guarantee that buffer we give to VOP_READDIR will be large enough
|
|
83 |
* to hold ., .., and the largest possible solaris dirent64.
|
|
84 |
*/
|
|
85 |
#define RFS4_MINLEN_ENTRY4 36
|
|
86 |
#define RFS4_MINLEN_RDDIR4 (4 + NFS4_VERIFIER_SIZE + 4 + RFS4_MINLEN_ENTRY4 + 4)
|
|
87 |
#define RFS4_MINLEN_RDDIR_BUF \
|
|
88 |
(DIRENT64_RECLEN(1) + DIRENT64_RECLEN(2) + DIRENT64_RECLEN(MAXNAMELEN))
|
|
89 |
|
|
90 |
|
|
91 |
#ifdef nextdp
|
|
92 |
#undef nextdp
|
|
93 |
#endif
|
|
94 |
#define nextdp(dp) ((struct dirent64 *)((char *)(dp) + (dp)->d_reclen))
|
|
95 |
|
|
96 |
verifier4 Readdir4verf = 0x0;
|
|
97 |
|
|
98 |
static nfs_ftype4 vt_to_nf4[] = {
|
|
99 |
0, NF4REG, NF4DIR, NF4BLK, NF4CHR, NF4LNK, NF4FIFO, 0, 0, NF4SOCK, 0
|
|
100 |
};
|
|
101 |
|
|
102 |
|
|
103 |
int
|
|
104 |
nfs4_readdir_getvp(vnode_t *dvp, char *d_name, vnode_t **vpp,
|
|
105 |
struct exportinfo **exi, struct svc_req *req,
|
|
106 |
struct compound_state *cs, int expseudo)
|
|
107 |
{
|
|
108 |
int error;
|
|
109 |
int ismntpt;
|
|
110 |
fid_t fid;
|
|
111 |
vnode_t *vp, *pre_tvp;
|
|
112 |
nfsstat4 status;
|
|
113 |
struct exportinfo *newexi, *saveexi;
|
|
114 |
cred_t *scr;
|
|
115 |
|
|
116 |
*vpp = vp = NULL;
|
|
117 |
|
|
118 |
if (error = VOP_LOOKUP(dvp, d_name, &vp, NULL, 0, NULL, cs->cr))
|
|
119 |
return (error);
|
|
120 |
|
|
121 |
/* Is this object mounted upon? */
|
|
122 |
ismntpt = vn_ismntpt(vp);
|
|
123 |
/*
|
|
124 |
* Nothing more to do if object is not a mount point or
|
|
125 |
* a possible LOFS shadow of an LOFS mount (which won't
|
|
126 |
* have v_vfsmountedhere set)
|
|
127 |
*/
|
|
128 |
if (ismntpt == 0 && dvp->v_vfsp == vp->v_vfsp && expseudo == 0) {
|
|
129 |
*vpp = vp;
|
|
130 |
return (0);
|
|
131 |
}
|
|
132 |
|
|
133 |
if (ismntpt) {
|
|
134 |
/*
|
|
135 |
* Something is mounted here. Traverse and manage the
|
|
136 |
* namespace
|
|
137 |
*/
|
|
138 |
pre_tvp = vp;
|
|
139 |
VN_HOLD(pre_tvp);
|
|
140 |
|
|
141 |
if ((error = traverse(&vp)) != 0) {
|
|
142 |
VN_RELE(pre_tvp);
|
|
143 |
return (error);
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
bzero(&fid, sizeof (fid));
|
|
148 |
fid.fid_len = MAXFIDSZ;
|
|
149 |
|
|
150 |
/*
|
|
151 |
* If VOP_FID not supported by underlying fs (mntfs, procfs,
|
|
152 |
* etc.), then return attrs for stub instead of VROOT object.
|
|
153 |
* If it fails for any other reason, then return the error.
|
|
154 |
*/
|
|
155 |
if (error = VOP_FID(vp, &fid)) {
|
|
156 |
if (ismntpt == 0) {
|
|
157 |
VN_RELE(vp);
|
|
158 |
return (error);
|
|
159 |
}
|
|
160 |
|
|
161 |
if (error != ENOSYS && error != ENOTSUP) {
|
|
162 |
VN_RELE(vp);
|
|
163 |
VN_RELE(pre_tvp);
|
|
164 |
return (error);
|
|
165 |
}
|
|
166 |
/* go back to vnode that is "under" mount */
|
|
167 |
VN_RELE(vp);
|
|
168 |
*vpp = pre_tvp;
|
|
169 |
return (0);
|
|
170 |
}
|
|
171 |
|
|
172 |
newexi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid, vp);
|
|
173 |
if (newexi == NULL) {
|
|
174 |
if (ismntpt == 0) {
|
|
175 |
*vpp = vp;
|
|
176 |
} else {
|
|
177 |
VN_RELE(vp);
|
|
178 |
*vpp = pre_tvp;
|
|
179 |
}
|
|
180 |
return (0);
|
|
181 |
}
|
|
182 |
|
|
183 |
if (ismntpt)
|
|
184 |
VN_RELE(pre_tvp);
|
|
185 |
|
|
186 |
/* Save the exi and present the new one to checkauth4() */
|
|
187 |
saveexi = cs->exi;
|
|
188 |
cs->exi = newexi;
|
|
189 |
|
|
190 |
/* Get the right cred like lookup does */
|
|
191 |
scr = cs->cr;
|
|
192 |
cs->cr = crdup(cs->basecr);
|
|
193 |
|
|
194 |
status = call_checkauth4(cs, req);
|
|
195 |
|
|
196 |
crfree(cs->cr);
|
|
197 |
cs->cr = scr;
|
|
198 |
cs->exi = saveexi;
|
|
199 |
|
|
200 |
/* Reset what call_checkauth4() may have set */
|
|
201 |
*cs->statusp = NFS4_OK;
|
|
202 |
|
|
203 |
if (status != NFS4_OK) {
|
|
204 |
VN_RELE(vp);
|
|
205 |
if (status == NFS4ERR_DELAY)
|
|
206 |
status = NFS4ERR_ACCESS;
|
|
207 |
return (status);
|
|
208 |
}
|
|
209 |
*vpp = vp;
|
|
210 |
*exi = newexi;
|
|
211 |
|
|
212 |
return (0);
|
|
213 |
}
|
|
214 |
|
|
215 |
/* This is the set of pathconf data for vfs */
|
|
216 |
typedef struct {
|
|
217 |
uint64_t maxfilesize;
|
|
218 |
uint32_t maxlink;
|
|
219 |
uint32_t maxname;
|
|
220 |
} rfs4_pc_encode_t;
|
|
221 |
|
|
222 |
|
|
223 |
static int
|
|
224 |
rfs4_get_pc_encode(vnode_t *vp, rfs4_pc_encode_t *pce, bitmap4 ar, cred_t *cr)
|
|
225 |
{
|
|
226 |
int error;
|
|
227 |
ulong_t pc_val;
|
|
228 |
|
|
229 |
pce->maxfilesize = 0;
|
|
230 |
pce->maxlink = 0;
|
|
231 |
pce->maxname = 0;
|
|
232 |
|
|
233 |
if (ar & FATTR4_MAXFILESIZE_MASK) {
|
|
234 |
/* Maximum File Size */
|
|
235 |
if (error = VOP_PATHCONF(vp, _PC_FILESIZEBITS, &pc_val, cr))
|
|
236 |
return (error);
|
|
237 |
|
|
238 |
if (pc_val >= (sizeof (uint64_t) * 8))
|
|
239 |
pce->maxfilesize = UINT64_MAX;
|
|
240 |
else
|
|
241 |
pce->maxfilesize = ((1LL << pc_val) - 1);
|
|
242 |
}
|
|
243 |
|
|
244 |
if (ar & FATTR4_MAXLINK_MASK) {
|
|
245 |
/* Maximum Link Count */
|
|
246 |
if (error = VOP_PATHCONF(vp, _PC_LINK_MAX, &pc_val, cr))
|
|
247 |
return (error);
|
|
248 |
|
|
249 |
pce->maxlink = pc_val;
|
|
250 |
}
|
|
251 |
|
|
252 |
if (ar & FATTR4_MAXNAME_MASK) {
|
|
253 |
/* Maximum Name Length */
|
|
254 |
if (error = VOP_PATHCONF(vp, _PC_NAME_MAX, &pc_val, cr))
|
|
255 |
return (error);
|
|
256 |
|
|
257 |
pce->maxname = pc_val;
|
|
258 |
}
|
|
259 |
|
|
260 |
return (0);
|
|
261 |
}
|
|
262 |
|
|
263 |
/* This is the set of statvfs data that is ready for encoding */
|
|
264 |
typedef struct {
|
|
265 |
uint64_t space_avail;
|
|
266 |
uint64_t space_free;
|
|
267 |
uint64_t space_total;
|
|
268 |
u_longlong_t fa;
|
|
269 |
u_longlong_t ff;
|
|
270 |
u_longlong_t ft;
|
|
271 |
} rfs4_sb_encode_t;
|
|
272 |
|
|
273 |
static int
|
|
274 |
rfs4_get_sb_encode(vfs_t *vfsp, rfs4_sb_encode_t *psbe)
|
|
275 |
{
|
|
276 |
int error;
|
|
277 |
struct statvfs64 sb;
|
|
278 |
|
|
279 |
/* Grab the per filesystem info */
|
|
280 |
if (error = VFS_STATVFS(vfsp, &sb)) {
|
|
281 |
return (error);
|
|
282 |
}
|
|
283 |
|
|
284 |
/* Calculate space available */
|
|
285 |
if (sb.f_bavail != (fsblkcnt64_t)-1) {
|
|
286 |
psbe->space_avail =
|
|
287 |
(fattr4_space_avail) sb.f_frsize *
|
|
288 |
(fattr4_space_avail) sb.f_bavail;
|
|
289 |
} else {
|
|
290 |
psbe->space_avail =
|
|
291 |
(fattr4_space_avail) sb.f_bavail;
|
|
292 |
}
|
|
293 |
|
|
294 |
/* Calculate space free */
|
|
295 |
if (sb.f_bfree != (fsblkcnt64_t)-1) {
|
|
296 |
psbe->space_free =
|
|
297 |
(fattr4_space_free) sb.f_frsize *
|
|
298 |
(fattr4_space_free) sb.f_bfree;
|
|
299 |
} else {
|
|
300 |
psbe->space_free =
|
|
301 |
(fattr4_space_free) sb.f_bfree;
|
|
302 |
}
|
|
303 |
|
|
304 |
/* Calculate space total */
|
|
305 |
if (sb.f_blocks != (fsblkcnt64_t)-1) {
|
|
306 |
psbe->space_total =
|
|
307 |
(fattr4_space_total) sb.f_frsize *
|
|
308 |
(fattr4_space_total) sb.f_blocks;
|
|
309 |
} else {
|
|
310 |
psbe->space_total =
|
|
311 |
(fattr4_space_total) sb.f_blocks;
|
|
312 |
}
|
|
313 |
|
|
314 |
/* For use later on attr encode */
|
|
315 |
psbe->fa = sb.f_favail;
|
|
316 |
psbe->ff = sb.f_ffree;
|
|
317 |
psbe->ft = sb.f_files;
|
|
318 |
|
|
319 |
return (0);
|
|
320 |
}
|
|
321 |
|
|
322 |
/*
|
|
323 |
* Macros to handle if we have don't have enough space for the requested
|
|
324 |
* attributes and this is the first entry and the
|
|
325 |
* requested attributes are more than the minimal useful
|
|
326 |
* set, reset the attributes to the minimal set and
|
|
327 |
* retry the encoding. If the client has asked for both
|
|
328 |
* mounted_on_fileid and fileid, prefer mounted_on_fileid.
|
|
329 |
*/
|
|
330 |
#define MINIMAL_RD_ATTRS \
|
|
331 |
(FATTR4_MOUNTED_ON_FILEID_MASK| \
|
|
332 |
FATTR4_FILEID_MASK| \
|
|
333 |
FATTR4_RDATTR_ERROR_MASK)
|
|
334 |
|
|
335 |
#define MINIMIZE_ATTR_MASK(m) { \
|
|
336 |
if ((m) & FATTR4_MOUNTED_ON_FILEID_MASK) \
|
|
337 |
(m) &= FATTR4_RDATTR_ERROR_MASK|FATTR4_MOUNTED_ON_FILEID_MASK;\
|
|
338 |
else \
|
|
339 |
(m) &= FATTR4_RDATTR_ERROR_MASK|FATTR4_FILEID_MASK; \
|
|
340 |
}
|
|
341 |
|
|
342 |
#define IS_MIN_ATTR_MASK(m) (((m) & ~MINIMAL_RD_ATTRS) == 0)
|
|
343 |
/*
|
|
344 |
* If readdir only needs to return FILEID, we can take it from the
|
|
345 |
* dirent struct and save doing the lookup.
|
|
346 |
*/
|
|
347 |
/* ARGSUSED */
|
|
348 |
void
|
|
349 |
rfs4_op_readdir(nfs_argop4 *argop, nfs_resop4 *resop,
|
|
350 |
struct svc_req *req, struct compound_state *cs)
|
|
351 |
{
|
|
352 |
READDIR4args *args = &argop->nfs_argop4_u.opreaddir;
|
|
353 |
READDIR4res *resp = &resop->nfs_resop4_u.opreaddir;
|
|
354 |
struct exportinfo *newexi = NULL;
|
|
355 |
int error;
|
|
356 |
mblk_t *mp;
|
|
357 |
uint_t mpcount;
|
|
358 |
int alloc_err = 0;
|
|
359 |
vnode_t *dvp = cs->vp;
|
|
360 |
vnode_t *vp;
|
|
361 |
vattr_t va;
|
|
362 |
struct dirent64 *dp;
|
|
363 |
rfs4_sb_encode_t dsbe, sbe;
|
|
364 |
int vfs_different;
|
|
365 |
int rddir_data_len, rddir_result_size;
|
|
366 |
caddr_t rddir_data;
|
|
367 |
offset_t rddir_next_offset;
|
|
368 |
int dircount;
|
|
369 |
int no_space;
|
|
370 |
int iseofdir;
|
|
371 |
uint_t eof;
|
|
372 |
struct iovec iov;
|
|
373 |
struct uio uio;
|
|
374 |
int tsize;
|
|
375 |
int check_visible;
|
|
376 |
int expseudo = 0;
|
|
377 |
|
|
378 |
uint32_t *ptr, *ptr_redzone;
|
|
379 |
uint32_t *beginning_ptr;
|
|
380 |
uint32_t *lastentry_ptr;
|
|
381 |
uint32_t *attrmask_ptr;
|
|
382 |
uint32_t *attr_offset_ptr;
|
|
383 |
uint32_t attr_length;
|
|
384 |
uint32_t rndup;
|
|
385 |
uint32_t namelen;
|
|
386 |
uint32_t rddirattr_error = 0;
|
|
387 |
int nents;
|
|
388 |
bitmap4 ar = args->attr_request & NFS4_SRV_RDDIR_SUPPORTED_ATTRS;
|
|
389 |
bitmap4 ae;
|
|
390 |
rfs4_pc_encode_t dpce, pce;
|
|
391 |
ulong_t pc_val;
|
|
392 |
uint64_t maxread;
|
|
393 |
uint64_t maxwrite;
|
|
394 |
uint_t true = TRUE;
|
|
395 |
uint_t false = FALSE;
|
|
396 |
uid_t lastuid;
|
|
397 |
gid_t lastgid;
|
|
398 |
int lu_set, lg_set;
|
|
399 |
utf8string owner, group;
|
|
400 |
int owner_error, group_error;
|
|
401 |
|
|
402 |
lu_set = lg_set = 0;
|
|
403 |
owner.utf8string_len = group.utf8string_len = 0;
|
|
404 |
owner.utf8string_val = group.utf8string_val = NULL;
|
|
405 |
|
|
406 |
resp->mblk = NULL;
|
|
407 |
|
|
408 |
/* Maximum read and write size */
|
|
409 |
maxread = maxwrite = rfs4_tsize(req);
|
|
410 |
|
|
411 |
if (dvp == NULL) {
|
|
412 |
*cs->statusp = resp->status = NFS4ERR_NOFILEHANDLE;
|
|
413 |
return;
|
|
414 |
}
|
|
415 |
|
|
416 |
/*
|
|
417 |
* If there is an unshared filesystem mounted on this vnode,
|
|
418 |
* do not allow readdir in this directory.
|
|
419 |
*/
|
|
420 |
if (vn_ismntpt(dvp)) {
|
|
421 |
*cs->statusp = resp->status = NFS4ERR_ACCESS;
|
|
422 |
return;
|
|
423 |
}
|
|
424 |
|
|
425 |
if (dvp->v_type != VDIR) {
|
|
426 |
*cs->statusp = resp->status = NFS4ERR_NOTDIR;
|
|
427 |
return;
|
|
428 |
}
|
|
429 |
|
|
430 |
if (args->maxcount <= RFS4_MINLEN_RDDIR4) {
|
|
431 |
*cs->statusp = resp->status = NFS4ERR_TOOSMALL;
|
|
432 |
return;
|
|
433 |
}
|
|
434 |
|
|
435 |
/*
|
|
436 |
* If write-only attrs are requested, then fail the readdir op
|
|
437 |
*/
|
|
438 |
if (args->attr_request &
|
|
439 |
(FATTR4_TIME_MODIFY_SET_MASK | FATTR4_TIME_ACCESS_SET_MASK)) {
|
|
440 |
*cs->statusp = resp->status = NFS4ERR_INVAL;
|
|
441 |
return;
|
|
442 |
}
|
|
443 |
|
|
444 |
error = VOP_ACCESS(dvp, VREAD, 0, cs->cr);
|
|
445 |
if (error) {
|
|
446 |
*cs->statusp = resp->status = puterrno4(error);
|
|
447 |
return;
|
|
448 |
}
|
|
449 |
|
|
450 |
if (args->cookieverf != Readdir4verf) {
|
|
451 |
*cs->statusp = resp->status = NFS4ERR_NOT_SAME;
|
|
452 |
return;
|
|
453 |
}
|
|
454 |
|
|
455 |
/* Is there pseudo-fs work that is needed for this readdir? */
|
|
456 |
check_visible = PSEUDO(cs->exi) ||
|
|
457 |
! is_exported_sec(cs->nfsflavor, cs->exi) ||
|
|
458 |
cs->access & CS_ACCESS_LIMITED;
|
|
459 |
|
|
460 |
/* Check the requested attributes and only do the work if needed */
|
|
461 |
|
|
462 |
if (ar & (FATTR4_MAXFILESIZE_MASK |
|
|
463 |
FATTR4_MAXLINK_MASK |
|
|
464 |
FATTR4_MAXNAME_MASK)) {
|
|
465 |
if (error = rfs4_get_pc_encode(cs->vp, &dpce, ar, cs->cr)) {
|
|
466 |
*cs->statusp = resp->status = puterrno4(error);
|
|
467 |
return;
|
|
468 |
}
|
|
469 |
pce = dpce;
|
|
470 |
}
|
|
471 |
|
|
472 |
/* If there is statvfs data requested, pick it up once */
|
|
473 |
if (ar &
|
|
474 |
(FATTR4_FILES_AVAIL_MASK |
|
|
475 |
FATTR4_FILES_FREE_MASK |
|
|
476 |
FATTR4_FILES_TOTAL_MASK |
|
|
477 |
FATTR4_FILES_AVAIL_MASK |
|
|
478 |
FATTR4_FILES_FREE_MASK |
|
|
479 |
FATTR4_FILES_TOTAL_MASK)) {
|
|
480 |
if (error = rfs4_get_sb_encode(dvp->v_vfsp, &dsbe)) {
|
|
481 |
*cs->statusp = resp->status = puterrno4(error);
|
|
482 |
return;
|
|
483 |
}
|
|
484 |
sbe = dsbe;
|
|
485 |
}
|
|
486 |
|
|
487 |
/*
|
|
488 |
* Max transfer size of the server is the absolute limite.
|
|
489 |
* If the client has decided to max out with something really
|
|
490 |
* tiny, then return toosmall. Otherwise, move forward and
|
|
491 |
* see if a single entry can be encoded.
|
|
492 |
*/
|
|
493 |
tsize = rfs4_tsize(req);
|
|
494 |
if (args->maxcount > tsize)
|
|
495 |
args->maxcount = tsize;
|
|
496 |
else if (args->maxcount < RFS4_MINLEN_RDDIR_BUF) {
|
|
497 |
if (args->maxcount < RFS4_MINLEN_ENTRY4) {
|
|
498 |
*cs->statusp = resp->status = NFS4ERR_TOOSMALL;
|
|
499 |
return;
|
|
500 |
}
|
|
501 |
}
|
|
502 |
|
|
503 |
/*
|
|
504 |
* How large should the mblk be for outgoing encoding.
|
|
505 |
*/
|
|
506 |
if (args->maxcount < MAXBSIZE)
|
|
507 |
mpcount = MAXBSIZE;
|
|
508 |
else
|
|
509 |
mpcount = args->maxcount;
|
|
510 |
|
|
511 |
/*
|
|
512 |
* mp will contain the data to be sent out in the readdir reply.
|
|
513 |
* It will be freed after the reply has been sent.
|
|
514 |
* Let's roundup the data to a BYTES_PER_XDR_UNIX multiple,
|
|
515 |
* so that the call to xdrmblk_putmblk() never fails.
|
|
516 |
*/
|
|
517 |
mp = allocb(RNDUP(mpcount), BPRI_MED);
|
|
518 |
|
|
519 |
if (mp == NULL) {
|
|
520 |
/*
|
|
521 |
* The allocation of the client's requested size has
|
|
522 |
* failed. It may be that the size is too large for
|
|
523 |
* current system utilization; step down to a "common"
|
|
524 |
* size and wait for the allocation to occur.
|
|
525 |
*/
|
|
526 |
if (mpcount > MAXBSIZE)
|
|
527 |
args->maxcount = mpcount = MAXBSIZE;
|
|
528 |
mp = allocb_wait(RNDUP(mpcount), BPRI_MED,
|
|
529 |
STR_NOSIG, &alloc_err);
|
|
530 |
}
|
|
531 |
|
|
532 |
ASSERT(mp != NULL);
|
|
533 |
ASSERT(alloc_err == 0);
|
|
534 |
|
|
535 |
resp->mblk = mp;
|
|
536 |
|
|
537 |
ptr = beginning_ptr = (uint32_t *)mp->b_datap->db_base;
|
|
538 |
|
|
539 |
/*
|
|
540 |
* The "redzone" at the end of the encoding buffer is used
|
|
541 |
* to deal with xdr encoding length. Instead of checking
|
|
542 |
* each encoding of an attribute value before it is done,
|
|
543 |
* make the assumption that it will fit into the buffer and
|
|
544 |
* check occasionally.
|
|
545 |
*
|
|
546 |
* The largest block of attributes that are encoded without
|
|
547 |
* checking the redzone is 18 * BYTES_PER_XDR_UNIT (72 bytes)
|
|
548 |
* "round" to 128 as the redzone size.
|
|
549 |
*/
|
|
550 |
if (args->maxcount < (mpcount - 128))
|
|
551 |
ptr_redzone =
|
|
552 |
(uint32_t *)(((char *)ptr) + RNDUP(args->maxcount));
|
|
553 |
else
|
|
554 |
ptr_redzone =
|
|
555 |
(uint32_t *)((((char *)ptr) + RNDUP(mpcount)) - 128);
|
|
556 |
|
|
557 |
/*
|
|
558 |
* Set the dircount; this will be used as the size for the
|
|
559 |
* readdir of the underlying filesystem. First make sure
|
|
560 |
* that it is large enough to do a reasonable readdir (client
|
|
561 |
* may have short changed us - it is an advisory number);
|
|
562 |
* then make sure that it isn't too large.
|
|
563 |
* After all of that, if maxcount is "small" then just use
|
|
564 |
* that for the dircount number.
|
|
565 |
*/
|
|
566 |
dircount = (args->dircount < MAXBSIZE) ? MAXBSIZE : args->dircount;
|
|
567 |
dircount = (dircount > tsize) ? tsize : dircount;
|
|
568 |
if (dircount > args->maxcount)
|
|
569 |
dircount = args->maxcount;
|
|
570 |
if (args->maxcount <= MAXBSIZE) {
|
|
571 |
if (args->maxcount < RFS4_MINLEN_RDDIR_BUF)
|
|
572 |
dircount = RFS4_MINLEN_RDDIR_BUF;
|
|
573 |
else
|
|
574 |
dircount = args->maxcount;
|
|
575 |
}
|
|
576 |
|
|
577 |
/* number of entries fully encoded in outgoing buffer */
|
|
578 |
nents = 0;
|
|
579 |
|
|
580 |
/* ENCODE READDIR4res.cookieverf */
|
|
581 |
IXDR_PUT_HYPER(ptr, Readdir4verf);
|
|
582 |
|
|
583 |
rddir_data_len = dircount;
|
|
584 |
rddir_data = kmem_alloc(rddir_data_len, KM_NOSLEEP);
|
|
585 |
if (rddir_data == NULL) {
|
|
586 |
/* The allocation failed; downsize and wait for it this time */
|
|
587 |
if (rddir_data_len > MAXBSIZE)
|
|
588 |
rddir_data_len = dircount = MAXBSIZE;
|
|
589 |
rddir_data = kmem_alloc(rddir_data_len, KM_SLEEP);
|
|
590 |
}
|
|
591 |
|
|
592 |
rddir_next_offset = (offset_t)args->cookie;
|
|
593 |
|
|
594 |
readagain:
|
|
595 |
|
|
596 |
no_space = FALSE;
|
|
597 |
iseofdir = FALSE;
|
|
598 |
|
|
599 |
vp = NULL;
|
|
600 |
|
|
601 |
/* Move on to reading the directory contents */
|
|
602 |
iov.iov_base = rddir_data;
|
|
603 |
iov.iov_len = rddir_data_len;
|
|
604 |
uio.uio_iov = &iov;
|
|
605 |
uio.uio_iovcnt = 1;
|
|
606 |
uio.uio_segflg = UIO_SYSSPACE;
|
|
607 |
uio.uio_extflg = UIO_COPY_CACHED;
|
|
608 |
uio.uio_loffset = rddir_next_offset;
|
|
609 |
uio.uio_resid = rddir_data_len;
|
|
610 |
|
|
611 |
(void) VOP_RWLOCK(dvp, V_WRITELOCK_FALSE, NULL);
|
|
612 |
|
|
613 |
error = VOP_READDIR(dvp, &uio, cs->cr, &iseofdir);
|
|
614 |
|
|
615 |
VOP_RWUNLOCK(dvp, V_WRITELOCK_FALSE, NULL);
|
|
616 |
|
|
617 |
if (error) {
|
|
618 |
kmem_free((caddr_t)rddir_data, rddir_data_len);
|
|
619 |
freeb(resp->mblk);
|
|
620 |
resp->mblk = NULL;
|
|
621 |
resp->data_len = 0;
|
|
622 |
*cs->statusp = resp->status = puterrno4(error);
|
|
623 |
return;
|
|
624 |
}
|
|
625 |
|
|
626 |
|
|
627 |
rddir_result_size = rddir_data_len - uio.uio_resid;
|
|
628 |
|
|
629 |
/* Reading at the end of the directory */
|
|
630 |
if (iseofdir && (rddir_result_size == 0)) {
|
|
631 |
/* encode the BOOLEAN marking no further entries */
|
|
632 |
IXDR_PUT_U_INT32(ptr, false);
|
|
633 |
/* encode the BOOLEAN signifying end of directory */
|
|
634 |
IXDR_PUT_U_INT32(ptr, true);
|
|
635 |
resp->data_len = (char *)ptr - (char *)beginning_ptr;
|
|
636 |
resp->mblk->b_wptr += resp->data_len;
|
|
637 |
kmem_free((caddr_t)rddir_data, rddir_data_len);
|
|
638 |
*cs->statusp = resp->status = NFS4_OK;
|
|
639 |
return;
|
|
640 |
}
|
|
641 |
|
|
642 |
lastentry_ptr = ptr;
|
|
643 |
no_space = 0;
|
|
644 |
for (dp = (struct dirent64 *)rddir_data;
|
|
645 |
!no_space && rddir_result_size > 0; dp = nextdp(dp)) {
|
|
646 |
|
|
647 |
/* reset expseudo */
|
|
648 |
expseudo = 0;
|
|
649 |
|
|
650 |
if (vp) {
|
|
651 |
VN_RELE(vp);
|
|
652 |
vp = NULL;
|
|
653 |
}
|
|
654 |
|
|
655 |
if (newexi)
|
|
656 |
newexi = NULL;
|
|
657 |
|
|
658 |
rddir_result_size -= dp->d_reclen;
|
|
659 |
|
|
660 |
/* skip "." and ".." entries */
|
|
661 |
if (dp->d_ino == 0 || NFS_IS_DOTNAME(dp->d_name)) {
|
|
662 |
rddir_next_offset = dp->d_off;
|
|
663 |
continue;
|
|
664 |
}
|
|
665 |
|
|
666 |
if (check_visible &&
|
|
667 |
!nfs_visible_inode(cs->exi, dp->d_ino, &expseudo)) {
|
|
668 |
rddir_next_offset = dp->d_off;
|
|
669 |
continue;
|
|
670 |
}
|
|
671 |
|
|
672 |
/*
|
|
673 |
* Only if the client requested attributes...
|
|
674 |
* If the VOP_LOOKUP fails ENOENT, then skip this entry
|
|
675 |
* for the readdir response. If there was another error,
|
|
676 |
* then set the rddirattr_error and the error will be
|
|
677 |
* encoded later in the "attributes" section.
|
|
678 |
*/
|
|
679 |
ae = ar;
|
|
680 |
if (ar != 0) {
|
|
681 |
error = nfs4_readdir_getvp(dvp, dp->d_name,
|
|
682 |
&vp, &newexi, req, cs,
|
|
683 |
expseudo);
|
|
684 |
if (error == ENOENT) {
|
|
685 |
rddir_next_offset = dp->d_off;
|
|
686 |
continue;
|
|
687 |
}
|
|
688 |
|
|
689 |
rddirattr_error = error;
|
|
690 |
|
|
691 |
/*
|
|
692 |
* The vp obtained from above may be from a
|
|
693 |
* different filesystem mount and the vfs-like
|
|
694 |
* attributes should be obtained from that
|
|
695 |
* different vfs; only do this if appropriate.
|
|
696 |
*/
|
|
697 |
if (vp &&
|
|
698 |
(vfs_different = (dvp->v_vfsp != vp->v_vfsp))) {
|
|
699 |
if (ar & (FATTR4_FILES_AVAIL_MASK |
|
|
700 |
FATTR4_FILES_FREE_MASK |
|
|
701 |
FATTR4_FILES_TOTAL_MASK |
|
|
702 |
FATTR4_FILES_AVAIL_MASK |
|
|
703 |
FATTR4_FILES_FREE_MASK |
|
|
704 |
FATTR4_FILES_TOTAL_MASK)) {
|
|
705 |
if (error =
|
|
706 |
rfs4_get_sb_encode(dvp->v_vfsp, &sbe)) {
|
|
707 |
/* Remove attrs from encode */
|
|
708 |
ae &= ~(FATTR4_FILES_AVAIL_MASK |
|
|
709 |
FATTR4_FILES_FREE_MASK |
|
|
710 |
FATTR4_FILES_TOTAL_MASK |
|
|
711 |
FATTR4_FILES_AVAIL_MASK |
|
|
712 |
FATTR4_FILES_FREE_MASK |
|
|
713 |
FATTR4_FILES_TOTAL_MASK);
|
|
714 |
rddirattr_error = error;
|
|
715 |
}
|
|
716 |
}
|
|
717 |
if (ar & (FATTR4_MAXFILESIZE_MASK |
|
|
718 |
FATTR4_MAXLINK_MASK |
|
|
719 |
FATTR4_MAXNAME_MASK)) {
|
|
720 |
if (error =
|
|
721 |
rfs4_get_pc_encode(cs->vp,
|
|
722 |
&pce, ar, cs->cr)) {
|
|
723 |
ar &= ~(FATTR4_MAXFILESIZE_MASK |
|
|
724 |
FATTR4_MAXLINK_MASK |
|
|
725 |
FATTR4_MAXNAME_MASK);
|
|
726 |
rddirattr_error = error;
|
|
727 |
}
|
|
728 |
}
|
|
729 |
}
|
|
730 |
}
|
|
731 |
|
|
732 |
reencode_attrs:
|
|
733 |
/* encode the BOOLEAN for the existence of the next entry */
|
|
734 |
IXDR_PUT_U_INT32(ptr, true);
|
|
735 |
/* encode the COOKIE for the entry */
|
|
736 |
IXDR_PUT_U_HYPER(ptr, dp->d_off);
|
|
737 |
|
|
738 |
/* Calculate the dirent name length */
|
|
739 |
namelen = strlen(dp->d_name);
|
|
740 |
|
|
741 |
rndup = RNDUP(namelen) / BYTES_PER_XDR_UNIT;
|
|
742 |
|
|
743 |
/* room for LENGTH + string ? */
|
|
744 |
if ((ptr + (1 + rndup)) > ptr_redzone) {
|
|
745 |
no_space = TRUE;
|
|
746 |
continue;
|
|
747 |
}
|
|
748 |
|
|
749 |
/* encode the LENGTH of the name */
|
|
750 |
IXDR_PUT_U_INT32(ptr, namelen);
|
|
751 |
/* encode the RNDUP FILL first */
|
|
752 |
ptr[rndup - 1] = 0;
|
|
753 |
/* encode the NAME of the entry */
|
|
754 |
bcopy(dp->d_name, (char *)ptr, namelen);
|
|
755 |
/* now bump the ptr after... */
|
|
756 |
ptr += rndup;
|
|
757 |
|
|
758 |
/*
|
|
759 |
* Keep checking on the dircount to see if we have
|
|
760 |
* reached the limit; from the RFC, dircount is to be
|
|
761 |
* the XDR encoded limit of the cookie plus name.
|
|
762 |
* So the count is the name, XDR_UNIT of length for
|
|
763 |
* that name and 2 * XDR_UNIT bytes of cookie;
|
|
764 |
* However, use the regular DIRENT64 to match most
|
|
765 |
* client's APIs.
|
|
766 |
*/
|
|
767 |
dircount -= DIRENT64_RECLEN(namelen);
|
|
768 |
if (nents != 0 && dircount < 0) {
|
|
769 |
no_space = TRUE;
|
|
770 |
continue;
|
|
771 |
}
|
|
772 |
|
|
773 |
/*
|
|
774 |
* Attributes requested?
|
|
775 |
* Gather up the attribute info and the previous VOP_LOOKUP()
|
|
776 |
* succeeded; if an error occurs on the VOP_GETATTR() then
|
|
777 |
* return just the error (again if it is requested).
|
|
778 |
* Note that the previous VOP_LOOKUP() could have failed
|
|
779 |
* itself which leaves this code without anything for
|
|
780 |
* a VOP_GETATTR().
|
|
781 |
* Also note that the readdir_attr_error is left in the
|
|
782 |
* encoding mask if requested and so is the mounted_on_fileid.
|
|
783 |
*/
|
|
784 |
if (ae != 0) {
|
|
785 |
if (!vp) {
|
|
786 |
ae = ar & (FATTR4_RDATTR_ERROR_MASK |
|
|
787 |
FATTR4_MOUNTED_ON_FILEID_MASK);
|
|
788 |
} else {
|
|
789 |
va.va_mask = AT_ALL;
|
|
790 |
rddirattr_error =
|
|
791 |
VOP_GETATTR(vp, &va, 0, cs->cr);
|
|
792 |
if (rddirattr_error)
|
|
793 |
ae = ar & (FATTR4_RDATTR_ERROR_MASK |
|
|
794 |
FATTR4_MOUNTED_ON_FILEID_MASK);
|
|
795 |
}
|
|
796 |
}
|
|
797 |
|
|
798 |
/* START OF ATTRIBUTE ENCODING */
|
|
799 |
|
|
800 |
/* encode the LENGTH of the BITMAP4 array */
|
|
801 |
IXDR_PUT_U_INT32(ptr, 2);
|
|
802 |
/* encode the BITMAP4 */
|
|
803 |
attrmask_ptr = ptr;
|
|
804 |
IXDR_PUT_HYPER(ptr, ae);
|
|
805 |
attr_offset_ptr = ptr;
|
|
806 |
/* encode the default LENGTH of the attributes for entry */
|
|
807 |
IXDR_PUT_U_INT32(ptr, 0);
|
|
808 |
|
|
809 |
if (ptr > ptr_redzone) {
|
|
810 |
no_space = TRUE;
|
|
811 |
continue;
|
|
812 |
}
|
|
813 |
|
|
814 |
/* Check if any of the first 32 attributes are being encoded */
|
|
815 |
if (ae & 0xffffffff00000000) {
|
|
816 |
/*
|
|
817 |
* Redzone check is done at the end of this section.
|
|
818 |
* This particular section will encode a maximum of
|
|
819 |
* 18 * BYTES_PER_XDR_UNIT of data
|
|
820 |
*/
|
|
821 |
if (ae &
|
|
822 |
(FATTR4_SUPPORTED_ATTRS_MASK |
|
|
823 |
FATTR4_TYPE_MASK |
|
|
824 |
FATTR4_FH_EXPIRE_TYPE_MASK |
|
|
825 |
FATTR4_CHANGE_MASK |
|
|
826 |
FATTR4_SIZE_MASK |
|
|
827 |
FATTR4_LINK_SUPPORT_MASK |
|
|
828 |
FATTR4_SYMLINK_SUPPORT_MASK |
|
|
829 |
FATTR4_NAMED_ATTR_MASK |
|
|
830 |
FATTR4_FSID_MASK |
|
|
831 |
FATTR4_UNIQUE_HANDLES_MASK |
|
|
832 |
FATTR4_LEASE_TIME_MASK |
|
|
833 |
FATTR4_RDATTR_ERROR_MASK)) {
|
|
834 |
|
|
835 |
if (ae & FATTR4_SUPPORTED_ATTRS_MASK) {
|
|
836 |
IXDR_PUT_INT32(ptr, 2);
|
|
837 |
IXDR_PUT_HYPER(ptr,
|
|
838 |
rfs4_supported_attrs);
|
|
839 |
}
|
|
840 |
if (ae & FATTR4_TYPE_MASK) {
|
|
841 |
uint_t ftype = vt_to_nf4[va.va_type];
|
|
842 |
if (dvp->v_flag & V_XATTRDIR) {
|
|
843 |
if (va.va_type == VDIR)
|
|
844 |
ftype = NF4ATTRDIR;
|
|
845 |
else
|
|
846 |
ftype = NF4NAMEDATTR;
|
|
847 |
}
|
|
848 |
IXDR_PUT_U_INT32(ptr, ftype);
|
|
849 |
}
|
|
850 |
if (ae & FATTR4_FH_EXPIRE_TYPE_MASK) {
|
|
851 |
uint_t expire_type = FH4_PERSISTENT;
|
|
852 |
IXDR_PUT_U_INT32(ptr, expire_type);
|
|
853 |
}
|
|
854 |
if (ae & FATTR4_CHANGE_MASK) {
|
|
855 |
u_longlong_t change;
|
|
856 |
NFS4_SET_FATTR4_CHANGE(change,
|
|
857 |
va.va_ctime);
|
|
858 |
IXDR_PUT_HYPER(ptr, change);
|
|
859 |
}
|
|
860 |
if (ae & FATTR4_SIZE_MASK) {
|
|
861 |
u_longlong_t size = va.va_size;
|
|
862 |
IXDR_PUT_HYPER(ptr, size);
|
|
863 |
}
|
|
864 |
if (ae & FATTR4_LINK_SUPPORT_MASK) {
|
|
865 |
IXDR_PUT_U_INT32(ptr, true);
|
|
866 |
}
|
|
867 |
if (ae & FATTR4_SYMLINK_SUPPORT_MASK) {
|
|
868 |
IXDR_PUT_U_INT32(ptr, true);
|
|
869 |
}
|
|
870 |
if (ae & FATTR4_NAMED_ATTR_MASK) {
|
|
871 |
uint_t isit;
|
|
872 |
pc_val = FALSE;
|
|
873 |
|
|
874 |
if (!(vp->v_vfsp->vfs_flag &
|
|
875 |
VFS_XATTR)) {
|
|
876 |
isit = FALSE;
|
|
877 |
} else {
|
|
878 |
(void) VOP_PATHCONF(vp,
|
|
879 |
_PC_XATTR_EXISTS,
|
|
880 |
&pc_val, cs->cr);
|
|
881 |
}
|
|
882 |
isit = (pc_val ? TRUE : FALSE);
|
|
883 |
IXDR_PUT_U_INT32(ptr, isit);
|
|
884 |
}
|
|
885 |
if (ae & FATTR4_FSID_MASK) {
|
|
886 |
u_longlong_t major, minor;
|
|
887 |
struct exportinfo *exi;
|
|
888 |
|
|
889 |
exi = newexi ? newexi : cs->exi;
|
|
890 |
if (exi->exi_volatile_dev) {
|
|
891 |
int *pmaj = (int *)&major;
|
|
892 |
|
|
893 |
pmaj[0] = exi->exi_fsid.val[0];
|
|
894 |
pmaj[1] = exi->exi_fsid.val[1];
|
|
895 |
minor = 0;
|
|
896 |
} else {
|
|
897 |
major = getmajor(va.va_fsid);
|
|
898 |
minor = getminor(va.va_fsid);
|
|
899 |
}
|
|
900 |
IXDR_PUT_HYPER(ptr, major);
|
|
901 |
IXDR_PUT_HYPER(ptr, minor);
|
|
902 |
}
|
|
903 |
if (ae & FATTR4_UNIQUE_HANDLES_MASK) {
|
|
904 |
IXDR_PUT_U_INT32(ptr, false);
|
|
905 |
}
|
|
906 |
if (ae & FATTR4_LEASE_TIME_MASK) {
|
|
907 |
uint_t lt = rfs4_lease_time;
|
|
908 |
IXDR_PUT_U_INT32(ptr, lt);
|
|
909 |
}
|
|
910 |
if (ae & FATTR4_RDATTR_ERROR_MASK) {
|
|
911 |
rddirattr_error =
|
|
912 |
(rddirattr_error == 0 ?
|
|
913 |
0 : puterrno4(rddirattr_error));
|
|
914 |
IXDR_PUT_U_INT32(ptr, rddirattr_error);
|
|
915 |
}
|
|
916 |
|
|
917 |
/* Check the redzone boundary */
|
|
918 |
if (ptr > ptr_redzone) {
|
|
919 |
if (nents || IS_MIN_ATTR_MASK(ar)) {
|
|
920 |
no_space = TRUE;
|
|
921 |
continue;
|
|
922 |
}
|
|
923 |
MINIMIZE_ATTR_MASK(ar);
|
|
924 |
ae = ar;
|
|
925 |
ptr = lastentry_ptr;
|
|
926 |
goto reencode_attrs;
|
|
927 |
}
|
|
928 |
}
|
|
929 |
/*
|
|
930 |
* Redzone check is done at the end of this section.
|
|
931 |
* This particular section will encode a maximum of
|
|
932 |
* 4 * BYTES_PER_XDR_UNIT of data.
|
|
933 |
* NOTE: that if ACLs are supported that the
|
|
934 |
* redzone calculations will need to change.
|
|
935 |
*/
|
|
936 |
if (ae &
|
|
937 |
(FATTR4_ACL_MASK |
|
|
938 |
FATTR4_ACLSUPPORT_MASK |
|
|
939 |
FATTR4_ARCHIVE_MASK |
|
|
940 |
FATTR4_CANSETTIME_MASK |
|
|
941 |
FATTR4_CASE_INSENSITIVE_MASK |
|
|
942 |
FATTR4_CASE_PRESERVING_MASK |
|
|
943 |
FATTR4_CHOWN_RESTRICTED_MASK)) {
|
|
944 |
|
|
945 |
if (ae & FATTR4_ACL_MASK) {
|
|
946 |
ASSERT(0);
|
|
947 |
}
|
|
948 |
if (ae & FATTR4_ACLSUPPORT_MASK) {
|
|
949 |
ASSERT(0);
|
|
950 |
}
|
|
951 |
if (ae & FATTR4_ARCHIVE_MASK) {
|
|
952 |
ASSERT(0);
|
|
953 |
}
|
|
954 |
if (ae & FATTR4_CANSETTIME_MASK) {
|
|
955 |
IXDR_PUT_U_INT32(ptr, true);
|
|
956 |
}
|
|
957 |
if (ae & FATTR4_CASE_INSENSITIVE_MASK) {
|
|
958 |
IXDR_PUT_U_INT32(ptr, false);
|
|
959 |
}
|
|
960 |
if (ae & FATTR4_CASE_PRESERVING_MASK) {
|
|
961 |
IXDR_PUT_U_INT32(ptr, true);
|
|
962 |
}
|
|
963 |
if (ae & FATTR4_CHOWN_RESTRICTED_MASK) {
|
|
964 |
uint_t isit;
|
|
965 |
pc_val = FALSE;
|
|
966 |
(void) VOP_PATHCONF(vp,
|
|
967 |
_PC_CHOWN_RESTRICTED,
|
|
968 |
&pc_val, cs->cr);
|
|
969 |
isit = (pc_val ? TRUE : FALSE);
|
|
970 |
IXDR_PUT_U_INT32(ptr, isit);
|
|
971 |
}
|
|
972 |
/* Check the redzone boundary */
|
|
973 |
if (ptr > ptr_redzone) {
|
|
974 |
if (nents || IS_MIN_ATTR_MASK(ar)) {
|
|
975 |
no_space = TRUE;
|
|
976 |
continue;
|
|
977 |
}
|
|
978 |
MINIMIZE_ATTR_MASK(ar);
|
|
979 |
ae = ar;
|
|
980 |
ptr = lastentry_ptr;
|
|
981 |
goto reencode_attrs;
|
|
982 |
}
|
|
983 |
}
|
|
984 |
/*
|
|
985 |
* Redzone check is done before the filehandle
|
|
986 |
* is encoded.
|
|
987 |
*/
|
|
988 |
if (ae &
|
|
989 |
(FATTR4_FILEHANDLE_MASK |
|
|
990 |
FATTR4_FILEID_MASK)) {
|
|
991 |
|
|
992 |
if (ae & FATTR4_FILEHANDLE_MASK) {
|
806
|
993 |
bool_t fh_error;
|
0
|
994 |
struct {
|
|
995 |
uint_t len;
|
|
996 |
char *val;
|
|
997 |
char fh[NFS_FH4_LEN];
|
|
998 |
} fh;
|
|
999 |
fh.len = 0;
|
|
1000 |
fh.val = fh.fh;
|
|
1001 |
(void) makefh4((nfs_fh4 *)&fh, vp,
|
806
|
1002 |
(newexi ? newexi : cs->exi));
|
0
|
1003 |
|
806
|
1004 |
fh_error = xdr_inline_encode_nfs_fh4(
|
|
1005 |
&ptr, ptr_redzone,
|
|
1006 |
(nfs_fh4_fmt_t *)fh.val);
|
|
1007 |
if (fh_error) {
|
0
|
1008 |
if (nents ||
|
|
1009 |
IS_MIN_ATTR_MASK(ar)) {
|
|
1010 |
no_space = TRUE;
|
|
1011 |
continue;
|
|
1012 |
}
|
|
1013 |
MINIMIZE_ATTR_MASK(ar);
|
|
1014 |
ae = ar;
|
|
1015 |
ptr = lastentry_ptr;
|
|
1016 |
goto reencode_attrs;
|
|
1017 |
}
|
|
1018 |
}
|
|
1019 |
if (ae & FATTR4_FILEID_MASK) {
|
|
1020 |
IXDR_PUT_HYPER(ptr, va.va_nodeid);
|
|
1021 |
}
|
|
1022 |
/* Check the redzone boundary */
|
|
1023 |
if (ptr > ptr_redzone) {
|
|
1024 |
if (nents || IS_MIN_ATTR_MASK(ar)) {
|
|
1025 |
no_space = TRUE;
|
|
1026 |
continue;
|
|
1027 |
}
|
|
1028 |
MINIMIZE_ATTR_MASK(ar);
|
|
1029 |
ae = ar;
|
|
1030 |
ptr = lastentry_ptr;
|
|
1031 |
goto reencode_attrs;
|
|
1032 |
}
|
|
1033 |
}
|
|
1034 |
/*
|
|
1035 |
* Redzone check is done at the end of this section.
|
|
1036 |
* This particular section will encode a maximum of
|
|
1037 |
* 15 * BYTES_PER_XDR_UNIT of data.
|
|
1038 |
*/
|
|
1039 |
if (ae &
|
|
1040 |
(FATTR4_FILES_AVAIL_MASK |
|
|
1041 |
FATTR4_FILES_FREE_MASK |
|
|
1042 |
FATTR4_FILES_TOTAL_MASK |
|
|
1043 |
FATTR4_FS_LOCATIONS_MASK |
|
|
1044 |
FATTR4_HIDDEN_MASK |
|
|
1045 |
FATTR4_HOMOGENEOUS_MASK |
|
|
1046 |
FATTR4_MAXFILESIZE_MASK |
|
|
1047 |
FATTR4_MAXLINK_MASK |
|
|
1048 |
FATTR4_MAXNAME_MASK |
|
|
1049 |
FATTR4_MAXREAD_MASK |
|
|
1050 |
FATTR4_MAXWRITE_MASK)) {
|
|
1051 |
|
|
1052 |
if (ae & FATTR4_FILES_AVAIL_MASK) {
|
|
1053 |
IXDR_PUT_HYPER(ptr, sbe.fa);
|
|
1054 |
}
|
|
1055 |
if (ae & FATTR4_FILES_FREE_MASK) {
|
|
1056 |
IXDR_PUT_HYPER(ptr, sbe.ff);
|
|
1057 |
}
|
|
1058 |
if (ae & FATTR4_FILES_TOTAL_MASK) {
|
|
1059 |
IXDR_PUT_HYPER(ptr, sbe.ft);
|
|
1060 |
}
|
|
1061 |
if (ae & FATTR4_FS_LOCATIONS_MASK) {
|
|
1062 |
ASSERT(0);
|
|
1063 |
}
|
|
1064 |
if (ae & FATTR4_HIDDEN_MASK) {
|
|
1065 |
ASSERT(0);
|
|
1066 |
}
|
|
1067 |
if (ae & FATTR4_HOMOGENEOUS_MASK) {
|
|
1068 |
IXDR_PUT_U_INT32(ptr, true);
|
|
1069 |
}
|
|
1070 |
if (ae & FATTR4_MAXFILESIZE_MASK) {
|
|
1071 |
IXDR_PUT_HYPER(ptr, pce.maxfilesize);
|
|
1072 |
}
|
|
1073 |
if (ae & FATTR4_MAXLINK_MASK) {
|
|
1074 |
IXDR_PUT_U_INT32(ptr, pce.maxlink);
|
|
1075 |
}
|
|
1076 |
if (ae & FATTR4_MAXNAME_MASK) {
|
|
1077 |
IXDR_PUT_U_INT32(ptr, pce.maxname);
|
|
1078 |
}
|
|
1079 |
if (ae & FATTR4_MAXREAD_MASK) {
|
|
1080 |
IXDR_PUT_HYPER(ptr, maxread);
|
|
1081 |
}
|
|
1082 |
if (ae & FATTR4_MAXWRITE_MASK) {
|
|
1083 |
IXDR_PUT_HYPER(ptr, maxwrite);
|
|
1084 |
}
|
|
1085 |
/* Check the redzone boundary */
|
|
1086 |
if (ptr > ptr_redzone) {
|
|
1087 |
if (nents || IS_MIN_ATTR_MASK(ar)) {
|
|
1088 |
no_space = TRUE;
|
|
1089 |
continue;
|
|
1090 |
}
|
|
1091 |
MINIMIZE_ATTR_MASK(ar);
|
|
1092 |
ae = ar;
|
|
1093 |
ptr = lastentry_ptr;
|
|
1094 |
goto reencode_attrs;
|
|
1095 |
}
|
|
1096 |
}
|
|
1097 |
}
|
|
1098 |
if (ae & 0x00000000ffffffff) {
|
|
1099 |
/*
|
|
1100 |
* Redzone check is done at the end of this section.
|
|
1101 |
* This particular section will encode a maximum of
|
|
1102 |
* 3 * BYTES_PER_XDR_UNIT of data.
|
|
1103 |
*/
|
|
1104 |
if (ae &
|
|
1105 |
(FATTR4_MIMETYPE_MASK |
|
|
1106 |
FATTR4_MODE_MASK |
|
|
1107 |
FATTR4_NO_TRUNC_MASK |
|
|
1108 |
FATTR4_NUMLINKS_MASK)) {
|
|
1109 |
|
|
1110 |
if (ae & FATTR4_MIMETYPE_MASK) {
|
|
1111 |
ASSERT(0);
|
|
1112 |
}
|
|
1113 |
if (ae & FATTR4_MODE_MASK) {
|
|
1114 |
uint_t m = va.va_mode;
|
|
1115 |
IXDR_PUT_U_INT32(ptr, m);
|
|
1116 |
}
|
|
1117 |
if (ae & FATTR4_NO_TRUNC_MASK) {
|
|
1118 |
IXDR_PUT_U_INT32(ptr, true);
|
|
1119 |
}
|
|
1120 |
if (ae & FATTR4_NUMLINKS_MASK) {
|
|
1121 |
IXDR_PUT_U_INT32(ptr, va.va_nlink);
|
|
1122 |
}
|
|
1123 |
/* Check the redzone boundary */
|
|
1124 |
if (ptr > ptr_redzone) {
|
|
1125 |
if (nents || IS_MIN_ATTR_MASK(ar)) {
|
|
1126 |
no_space = TRUE;
|
|
1127 |
continue;
|
|
1128 |
}
|
|
1129 |
MINIMIZE_ATTR_MASK(ar);
|
|
1130 |
ae = ar;
|
|
1131 |
ptr = lastentry_ptr;
|
|
1132 |
goto reencode_attrs;
|
|
1133 |
}
|
|
1134 |
}
|
|
1135 |
/*
|
|
1136 |
* Redzone check is done before the encoding of the
|
|
1137 |
* owner string since the length is indeterminate.
|
|
1138 |
*/
|
|
1139 |
if (ae & FATTR4_OWNER_MASK) {
|
|
1140 |
if (!lu_set) {
|
|
1141 |
owner_error = nfs_idmap_uid_str(va.va_uid,
|
|
1142 |
&owner, TRUE);
|
|
1143 |
if (!owner_error) {
|
|
1144 |
lu_set = TRUE;
|
|
1145 |
lastuid = va.va_uid;
|
|
1146 |
}
|
|
1147 |
} else {
|
|
1148 |
if (va.va_uid != lastuid) {
|
|
1149 |
if (owner.utf8string_len != 0) {
|
|
1150 |
kmem_free(owner.utf8string_val,
|
|
1151 |
owner.utf8string_len);
|
|
1152 |
owner.utf8string_len = 0;
|
|
1153 |
owner.utf8string_val = NULL;
|
|
1154 |
}
|
|
1155 |
owner_error = nfs_idmap_uid_str(
|
|
1156 |
va.va_uid,
|
|
1157 |
&owner, TRUE);
|
|
1158 |
if (!owner_error) {
|
|
1159 |
lastuid = va.va_uid;
|
|
1160 |
} else {
|
|
1161 |
lu_set = FALSE;
|
|
1162 |
}
|
|
1163 |
}
|
|
1164 |
}
|
|
1165 |
if (!owner_error) {
|
|
1166 |
if ((ptr +
|
|
1167 |
(owner.utf8string_len /
|
|
1168 |
BYTES_PER_XDR_UNIT)
|
|
1169 |
+ 2) > ptr_redzone) {
|
|
1170 |
if (nents ||
|
|
1171 |
IS_MIN_ATTR_MASK(ar)) {
|
|
1172 |
no_space = TRUE;
|
|
1173 |
continue;
|
|
1174 |
}
|
|
1175 |
MINIMIZE_ATTR_MASK(ar);
|
|
1176 |
ae = ar;
|
|
1177 |
ptr = lastentry_ptr;
|
|
1178 |
goto reencode_attrs;
|
|
1179 |
}
|
|
1180 |
/* encode the LENGTH of owner string */
|
|
1181 |
IXDR_PUT_U_INT32(ptr,
|
|
1182 |
owner.utf8string_len);
|
|
1183 |
/* encode the RNDUP FILL first */
|
|
1184 |
rndup = RNDUP(owner.utf8string_len) /
|
|
1185 |
BYTES_PER_XDR_UNIT;
|
|
1186 |
ptr[rndup - 1] = 0;
|
|
1187 |
/* encode the OWNER */
|
|
1188 |
bcopy(owner.utf8string_val, ptr,
|
|
1189 |
owner.utf8string_len);
|
|
1190 |
ptr += rndup;
|
|
1191 |
}
|
|
1192 |
}
|
|
1193 |
/*
|
|
1194 |
* Redzone check is done before the encoding of the
|
|
1195 |
* group string since the length is indeterminate.
|
|
1196 |
*/
|
|
1197 |
if (ae & FATTR4_OWNER_GROUP_MASK) {
|
|
1198 |
if (!lg_set) {
|
|
1199 |
group_error =
|
|
1200 |
nfs_idmap_gid_str(va.va_gid,
|
|
1201 |
&group, TRUE);
|
|
1202 |
if (!group_error) {
|
|
1203 |
lg_set = TRUE;
|
|
1204 |
lastgid = va.va_gid;
|
|
1205 |
}
|
|
1206 |
} else {
|
|
1207 |
if (va.va_gid != lastgid) {
|
|
1208 |
if (group.utf8string_len != 0) {
|
|
1209 |
kmem_free(group.utf8string_val,
|
|
1210 |
group.utf8string_len);
|
|
1211 |
group.utf8string_len = 0;
|
|
1212 |
group.utf8string_val = NULL;
|
|
1213 |
}
|
|
1214 |
group_error =
|
|
1215 |
nfs_idmap_gid_str(va.va_gid,
|
|
1216 |
&group, TRUE);
|
|
1217 |
if (!group_error)
|
|
1218 |
lastgid = va.va_gid;
|
|
1219 |
else
|
|
1220 |
lg_set = FALSE;
|
|
1221 |
}
|
|
1222 |
}
|
|
1223 |
if (!group_error) {
|
|
1224 |
if ((ptr +
|
|
1225 |
(group.utf8string_len /
|
|
1226 |
BYTES_PER_XDR_UNIT)
|
|
1227 |
+ 2) > ptr_redzone) {
|
|
1228 |
if (nents ||
|
|
1229 |
IS_MIN_ATTR_MASK(ar)) {
|
|
1230 |
no_space = TRUE;
|
|
1231 |
continue;
|
|
1232 |
}
|
|
1233 |
MINIMIZE_ATTR_MASK(ar);
|
|
1234 |
ae = ar;
|
|
1235 |
ptr = lastentry_ptr;
|
|
1236 |
goto reencode_attrs;
|
|
1237 |
}
|
|
1238 |
/* encode the LENGTH of owner string */
|
|
1239 |
IXDR_PUT_U_INT32(ptr,
|
|
1240 |
group.utf8string_len);
|
|
1241 |
/* encode the RNDUP FILL first */
|
|
1242 |
rndup = RNDUP(group.utf8string_len) /
|
|
1243 |
BYTES_PER_XDR_UNIT;
|
|
1244 |
ptr[rndup - 1] = 0;
|
|
1245 |
/* encode the OWNER */
|
|
1246 |
bcopy(group.utf8string_val, ptr,
|
|
1247 |
group.utf8string_len);
|
|
1248 |
ptr += rndup;
|
|
1249 |
}
|
|
1250 |
}
|
|
1251 |
if (ae &
|
|
1252 |
(FATTR4_QUOTA_AVAIL_HARD_MASK |
|
|
1253 |
FATTR4_QUOTA_AVAIL_SOFT_MASK |
|
|
1254 |
FATTR4_QUOTA_USED_MASK)) {
|
|
1255 |
if (ae & FATTR4_QUOTA_AVAIL_HARD_MASK) {
|
|
1256 |
ASSERT(0);
|
|
1257 |
}
|
|
1258 |
if (ae & FATTR4_QUOTA_AVAIL_SOFT_MASK) {
|
|
1259 |
ASSERT(0);
|
|
1260 |
}
|
|
1261 |
if (ae & FATTR4_QUOTA_USED_MASK) {
|
|
1262 |
ASSERT(0);
|
|
1263 |
}
|
|
1264 |
}
|
|
1265 |
/*
|
|
1266 |
* Redzone check is done at the end of this section.
|
|
1267 |
* This particular section will encode a maximum of
|
|
1268 |
* 10 * BYTES_PER_XDR_UNIT of data.
|
|
1269 |
*/
|
|
1270 |
if (ae &
|
|
1271 |
(FATTR4_RAWDEV_MASK |
|
|
1272 |
FATTR4_SPACE_AVAIL_MASK |
|
|
1273 |
FATTR4_SPACE_FREE_MASK |
|
|
1274 |
FATTR4_SPACE_TOTAL_MASK |
|
|
1275 |
FATTR4_SPACE_USED_MASK |
|
|
1276 |
FATTR4_SYSTEM_MASK)) {
|
|
1277 |
|
|
1278 |
if (ae & FATTR4_RAWDEV_MASK) {
|
|
1279 |
fattr4_rawdev rd;
|
|
1280 |
rd.specdata1 =
|
|
1281 |
(uint32)getmajor(va.va_rdev);
|
|
1282 |
rd.specdata2 =
|
|
1283 |
(uint32)getminor(va.va_rdev);
|
|
1284 |
IXDR_PUT_U_INT32(ptr, rd.specdata1);
|
|
1285 |
IXDR_PUT_U_INT32(ptr, rd.specdata2);
|
|
1286 |
}
|
|
1287 |
if (ae & FATTR4_SPACE_AVAIL_MASK) {
|
|
1288 |
IXDR_PUT_HYPER(ptr, sbe.space_avail);
|
|
1289 |
}
|
|
1290 |
if (ae & FATTR4_SPACE_FREE_MASK) {
|
|
1291 |
IXDR_PUT_HYPER(ptr, sbe.space_free);
|
|
1292 |
}
|
|
1293 |
if (ae & FATTR4_SPACE_TOTAL_MASK) {
|
|
1294 |
IXDR_PUT_HYPER(ptr, sbe.space_total);
|
|
1295 |
}
|
|
1296 |
if (ae & FATTR4_SPACE_USED_MASK) {
|
|
1297 |
u_longlong_t su;
|
|
1298 |
su = (fattr4_space_used) DEV_BSIZE *
|
|
1299 |
(fattr4_space_used) va.va_nblocks;
|
|
1300 |
IXDR_PUT_HYPER(ptr, su);
|
|
1301 |
}
|
|
1302 |
if (ae & FATTR4_SYSTEM_MASK) {
|
|
1303 |
ASSERT(0);
|
|
1304 |
}
|
|
1305 |
/* Check the redzone boundary */
|
|
1306 |
if (ptr > ptr_redzone) {
|
|
1307 |
if (nents || IS_MIN_ATTR_MASK(ar)) {
|
|
1308 |
no_space = TRUE;
|
|
1309 |
continue;
|
|
1310 |
}
|
|
1311 |
MINIMIZE_ATTR_MASK(ar);
|
|
1312 |
ae = ar;
|
|
1313 |
ptr = lastentry_ptr;
|
|
1314 |
goto reencode_attrs;
|
|
1315 |
}
|
|
1316 |
}
|
|
1317 |
/*
|
|
1318 |
* Redzone check is done at the end of this section.
|
|
1319 |
* This particular section will encode a maximum of
|
|
1320 |
* 14 * BYTES_PER_XDR_UNIT of data.
|
|
1321 |
*/
|
|
1322 |
if (ae &
|
|
1323 |
(FATTR4_TIME_ACCESS_MASK |
|
|
1324 |
FATTR4_TIME_ACCESS_SET_MASK |
|
|
1325 |
FATTR4_TIME_BACKUP_MASK |
|
|
1326 |
FATTR4_TIME_CREATE_MASK |
|
|
1327 |
FATTR4_TIME_DELTA_MASK |
|
|
1328 |
FATTR4_TIME_METADATA_MASK |
|
|
1329 |
FATTR4_TIME_MODIFY_MASK |
|
|
1330 |
FATTR4_TIME_MODIFY_SET_MASK |
|
|
1331 |
FATTR4_MOUNTED_ON_FILEID_MASK)) {
|
|
1332 |
|
|
1333 |
if (ae & FATTR4_TIME_ACCESS_MASK) {
|
|
1334 |
u_longlong_t sec =
|
|
1335 |
(u_longlong_t)va.va_atime.tv_sec;
|
|
1336 |
uint_t nsec =
|
|
1337 |
(uint_t)va.va_atime.tv_nsec;
|
|
1338 |
IXDR_PUT_HYPER(ptr, sec);
|
|
1339 |
IXDR_PUT_INT32(ptr, nsec);
|
|
1340 |
}
|
|
1341 |
if (ae & FATTR4_TIME_ACCESS_SET_MASK) {
|
|
1342 |
ASSERT(0);
|
|
1343 |
}
|
|
1344 |
if (ae & FATTR4_TIME_BACKUP_MASK) {
|
|
1345 |
ASSERT(0);
|
|
1346 |
}
|
|
1347 |
if (ae & FATTR4_TIME_CREATE_MASK) {
|
|
1348 |
ASSERT(0);
|
|
1349 |
}
|
|
1350 |
if (ae & FATTR4_TIME_DELTA_MASK) {
|
|
1351 |
u_longlong_t sec = 0;
|
|
1352 |
uint_t nsec = 1000;
|
|
1353 |
IXDR_PUT_HYPER(ptr, sec);
|
|
1354 |
IXDR_PUT_INT32(ptr, nsec);
|
|
1355 |
}
|
|
1356 |
if (ae & FATTR4_TIME_METADATA_MASK) {
|
|
1357 |
u_longlong_t sec =
|
|
1358 |
(u_longlong_t)va.va_ctime.tv_sec;
|
|
1359 |
uint_t nsec =
|
|
1360 |
(uint_t)va.va_ctime.tv_nsec;
|
|
1361 |
IXDR_PUT_HYPER(ptr, sec);
|
|
1362 |
IXDR_PUT_INT32(ptr, nsec);
|
|
1363 |
}
|
|
1364 |
if (ae & FATTR4_TIME_MODIFY_MASK) {
|
|
1365 |
u_longlong_t sec =
|
|
1366 |
(u_longlong_t)va.va_mtime.tv_sec;
|
|
1367 |
uint_t nsec =
|
|
1368 |
(uint_t)va.va_mtime.tv_nsec;
|
|
1369 |
IXDR_PUT_HYPER(ptr, sec);
|
|
1370 |
IXDR_PUT_INT32(ptr, nsec);
|
|
1371 |
}
|
|
1372 |
if (ae & FATTR4_TIME_MODIFY_SET_MASK) {
|
|
1373 |
ASSERT(0);
|
|
1374 |
}
|
|
1375 |
if (ae & FATTR4_MOUNTED_ON_FILEID_MASK) {
|
|
1376 |
IXDR_PUT_HYPER(ptr, dp->d_ino);
|
|
1377 |
}
|
|
1378 |
/* Check the redzone boundary */
|
|
1379 |
if (ptr > ptr_redzone) {
|
|
1380 |
if (nents || IS_MIN_ATTR_MASK(ar)) {
|
|
1381 |
no_space = TRUE;
|
|
1382 |
continue;
|
|
1383 |
}
|
|
1384 |
MINIMIZE_ATTR_MASK(ar);
|
|
1385 |
ae = ar;
|
|
1386 |
ptr = lastentry_ptr;
|
|
1387 |
goto reencode_attrs;
|
|
1388 |
}
|
|
1389 |
}
|
|
1390 |
}
|
|
1391 |
|
|
1392 |
/* Reset to directory's vfs info when encoding complete */
|
|
1393 |
if (vfs_different) {
|
|
1394 |
dsbe = sbe;
|
|
1395 |
dpce = pce;
|
|
1396 |
vfs_different = 0;
|
|
1397 |
}
|
|
1398 |
|
|
1399 |
/* "go back" and encode the attributes' length */
|
|
1400 |
attr_length =
|
|
1401 |
(char *)ptr -
|
|
1402 |
(char *)attr_offset_ptr -
|
|
1403 |
BYTES_PER_XDR_UNIT;
|
|
1404 |
IXDR_PUT_U_INT32(attr_offset_ptr, attr_length);
|
|
1405 |
|
|
1406 |
/*
|
|
1407 |
* If there was trouble obtaining a mapping for either
|
|
1408 |
* the owner or group attributes, then remove them from
|
|
1409 |
* bitmap4 for this entry and reset the bitmap value
|
|
1410 |
* in the data stream.
|
|
1411 |
*/
|
|
1412 |
if (owner_error || group_error) {
|
|
1413 |
if (owner_error)
|
|
1414 |
ae &= ~FATTR4_OWNER_MASK;
|
|
1415 |
if (group_error)
|
|
1416 |
ae &= ~FATTR4_OWNER_GROUP_MASK;
|
|
1417 |
IXDR_PUT_HYPER(attrmask_ptr, ae);
|
|
1418 |
}
|
|
1419 |
|
|
1420 |
/* END OF ATTRIBUTE ENCODING */
|
|
1421 |
|
|
1422 |
lastentry_ptr = ptr;
|
|
1423 |
nents++;
|
|
1424 |
rddir_next_offset = dp->d_off;
|
|
1425 |
}
|
|
1426 |
|
|
1427 |
/*
|
|
1428 |
* Check for the case that another VOP_READDIR() has to be done.
|
|
1429 |
* - no space encoding error
|
|
1430 |
* - no entry successfully encoded
|
|
1431 |
* - still more directory to read
|
|
1432 |
*/
|
|
1433 |
if (!no_space && nents == 0 && !iseofdir)
|
|
1434 |
goto readagain;
|
|
1435 |
|
|
1436 |
*cs->statusp = resp->status = NFS4_OK;
|
|
1437 |
|
|
1438 |
/*
|
|
1439 |
* If no_space is set then we terminated prematurely,
|
|
1440 |
* rewind to the last entry and this can never be EOF.
|
|
1441 |
*/
|
|
1442 |
if (no_space) {
|
|
1443 |
ptr = lastentry_ptr;
|
|
1444 |
eof = FALSE; /* ended encoded prematurely */
|
|
1445 |
} else {
|
|
1446 |
eof = (iseofdir ? TRUE : FALSE);
|
|
1447 |
}
|
|
1448 |
|
|
1449 |
/*
|
|
1450 |
* If we have entries, always return them, otherwise only error
|
|
1451 |
* if we ran out of space.
|
|
1452 |
*/
|
|
1453 |
if (nents || !no_space) {
|
|
1454 |
ASSERT(ptr != NULL);
|
|
1455 |
/* encode the BOOLEAN marking no further entries */
|
|
1456 |
IXDR_PUT_U_INT32(ptr, false);
|
|
1457 |
/* encode the BOOLEAN signifying end of directory */
|
|
1458 |
IXDR_PUT_U_INT32(ptr, eof);
|
|
1459 |
|
|
1460 |
resp->data_len = (char *)ptr - (char *)beginning_ptr;
|
|
1461 |
resp->mblk->b_wptr += resp->data_len;
|
|
1462 |
} else {
|
|
1463 |
freeb(mp);
|
|
1464 |
resp->mblk = NULL;
|
|
1465 |
resp->data_len = 0;
|
|
1466 |
*cs->statusp = resp->status = NFS4ERR_TOOSMALL;
|
|
1467 |
}
|
|
1468 |
|
|
1469 |
kmem_free((caddr_t)rddir_data, rddir_data_len);
|
|
1470 |
if (vp)
|
|
1471 |
VN_RELE(vp);
|
|
1472 |
if (owner.utf8string_len != 0)
|
|
1473 |
kmem_free(owner.utf8string_val, owner.utf8string_len);
|
|
1474 |
if (group.utf8string_len != 0)
|
|
1475 |
kmem_free(group.utf8string_val, group.utf8string_len);
|
|
1476 |
}
|