@@ -3664,6 +3664,22 @@ __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,
3664
3664
return ret ;
3665
3665
}
3666
3666
3667
+ /*
3668
+ * The buffer space for this field was reserved during a previous
3669
+ * call to nfsd4_encode_entry4().
3670
+ */
3671
+ static void nfsd4_encode_entry4_nfs_cookie4 (const struct nfsd4_readdir * readdir ,
3672
+ u64 offset )
3673
+ {
3674
+ __be64 cookie = cpu_to_be64 (offset );
3675
+ struct xdr_stream * xdr = readdir -> xdr ;
3676
+
3677
+ if (!readdir -> cookie_offset )
3678
+ return ;
3679
+ write_bytes_to_xdr_buf (xdr -> buf , readdir -> cookie_offset , & cookie ,
3680
+ sizeof (cookie ));
3681
+ }
3682
+
3667
3683
static inline int attributes_need_mount (u32 * bmval )
3668
3684
{
3669
3685
if (bmval [0 ] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME ))
@@ -3756,7 +3772,6 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen,
3756
3772
u32 name_and_cookie ;
3757
3773
int entry_bytes ;
3758
3774
__be32 nfserr = nfserr_toosmall ;
3759
- __be64 wire_offset ;
3760
3775
__be32 * p ;
3761
3776
3762
3777
/* In nfsv4, "." and ".." never make it onto the wire.. */
@@ -3765,11 +3780,8 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen,
3765
3780
return 0 ;
3766
3781
}
3767
3782
3768
- if (cd -> cookie_offset ) {
3769
- wire_offset = cpu_to_be64 (offset );
3770
- write_bytes_to_xdr_buf (xdr -> buf , cd -> cookie_offset ,
3771
- & wire_offset , 8 );
3772
- }
3783
+ /* Encode the previous entry's cookie value */
3784
+ nfsd4_encode_entry4_nfs_cookie4 (cd , offset );
3773
3785
3774
3786
p = xdr_reserve_space (xdr , 4 );
3775
3787
if (!p )
@@ -4451,7 +4463,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr,
4451
4463
int maxcount ;
4452
4464
int bytes_left ;
4453
4465
loff_t offset ;
4454
- __be64 wire_offset ;
4455
4466
struct xdr_stream * xdr = resp -> xdr ;
4456
4467
int starting_len = xdr -> buf -> len ;
4457
4468
__be32 * p ;
@@ -4509,11 +4520,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr,
4509
4520
if (nfserr )
4510
4521
goto err_no_verf ;
4511
4522
4512
- if (readdir -> cookie_offset ) {
4513
- wire_offset = cpu_to_be64 (offset );
4514
- write_bytes_to_xdr_buf (xdr -> buf , readdir -> cookie_offset ,
4515
- & wire_offset , 8 );
4516
- }
4523
+ /* Encode the final entry's cookie value */
4524
+ nfsd4_encode_entry4_nfs_cookie4 (readdir , offset );
4517
4525
4518
4526
p = xdr_reserve_space (xdr , 8 );
4519
4527
if (!p ) {
0 commit comments