2323import java .nio .ByteBuffer ;
2424
2525import org .dcache .nfs .nfsstat ;
26- import org .dcache .nfs .status .InvalException ;
27- import org .dcache .nfs .status .IsDirException ;
28- import org .dcache .nfs .status .NfsIoException ;
2926import org .dcache .nfs .status .OpenModeException ;
3027import org .dcache .nfs .v4 .xdr .READ4res ;
3128import org .dcache .nfs .v4 .xdr .READ4resok ;
3431import org .dcache .nfs .v4 .xdr .nfs_opnum4 ;
3532import org .dcache .nfs .v4 .xdr .nfs_resop4 ;
3633import org .dcache .nfs .v4 .xdr .stateid4 ;
37- import org .dcache .nfs .vfs .Stat ;
3834import org .slf4j .Logger ;
3935import org .slf4j .LoggerFactory ;
4036
@@ -50,17 +46,8 @@ public OperationREAD(nfs_argop4 args) {
5046 public void process (CompoundContext context , nfs_resop4 result ) throws IOException {
5147 final READ4res res = result .opread ;
5248
53- Stat inodeStat = context .getFs ().getattr (context .currentInode ());
5449 stateid4 stateid = Stateids .getCurrentStateidIfNeeded (context , _args .opread .stateid );
5550
56- if (inodeStat .type () == Stat .Type .DIRECTORY ) {
57- throw new IsDirException ();
58- }
59-
60- if (inodeStat .type () == Stat .Type .SYMLINK ) {
61- throw new InvalException ();
62- }
63-
6451 NFS4Client client ;
6552 if (context .getMinorversion () == 0 ) {
6653 /*
@@ -85,19 +72,17 @@ public void process(CompoundContext context, nfs_resop4 result) throws IOExcepti
8572
8673 ByteBuffer buf = ByteBuffer .allocate (count );
8774
88- int bytesReaded = context .getFs ().read (inode , buf , offset );
89- if (bytesReaded < 0 ) {
90- throw new NfsIoException ("IO not allowed" );
91- }
92-
93- buf .flip ();
94- res .status = nfsstat .NFS_OK ;
9575 res .resok4 = new READ4resok ();
76+ int bytesRead = context .getFs ().read (inode , buf , offset , res .resok4 ::setEOF );
9677
97- res .resok4 .data = buf ;
98-
99- if (offset + bytesReaded >= inodeStat .getSize ()) {
78+ if (bytesRead < 0 ) {
79+ buf .clear ();
10080 res .resok4 .eof = true ;
81+ } else {
82+ buf .flip ();
10183 }
84+
85+ res .status = nfsstat .NFS_OK ;
86+ res .resok4 .data = buf ;
10287 }
10388}
0 commit comments