1 /* jcifs smb client library in Java 2 * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 package jcifs.smb; 20 21 import jcifs.Config; 22 import jcifs.util.*; 23 24 class SmbComWriteAndX extends AndXServerMessageBlock { 25 26 private static final int READ_ANDX_BATCH_LIMIT = 27 Config.getInt( "jcifs.smb.client.WriteAndX.ReadAndX", 1 ); 28 private static final int CLOSE_BATCH_LIMIT = 29 Config.getInt( "jcifs.smb.client.WriteAndX.Close", 1 ); 30 31 private int fid, 32 remaining, 33 dataLength, 34 dataOffset, 35 off; 36 private byte[] b; 37 private long offset; 38 39 private int pad; 40 41 int writeMode; 42 SmbComWriteAndX()43 SmbComWriteAndX() { 44 super( null ); 45 command = SMB_COM_WRITE_ANDX; 46 } SmbComWriteAndX( int fid, long offset, int remaining, byte[] b, int off, int len, ServerMessageBlock andx )47 SmbComWriteAndX( int fid, long offset, int remaining, 48 byte[] b, int off, int len, ServerMessageBlock andx ) { 49 super( andx ); 50 this.fid = fid; 51 this.offset = offset; 52 this.remaining = remaining; 53 this.b = b; 54 this.off = off; 55 dataLength = len; 56 command = SMB_COM_WRITE_ANDX; 57 } 58 setParam( int fid, long offset, int remaining, byte[] b, int off, int len )59 void setParam( int fid, long offset, int remaining, 60 byte[] b, int off, int len ) { 61 this.fid = fid; 62 this.offset = offset; 63 this.remaining = remaining; 64 this.b = b; 65 this.off = off; 66 dataLength = len; 67 digest = null; /* otherwise recycled commands 68 * like writeandx will choke if session 69 * closes in between */ 70 } getBatchLimit( byte command )71 int getBatchLimit( byte command ) { 72 if( command == SMB_COM_READ_ANDX ) { 73 return READ_ANDX_BATCH_LIMIT; 74 } 75 if( command == SMB_COM_CLOSE ) { 76 return CLOSE_BATCH_LIMIT; 77 } 78 return 0; 79 } writeParameterWordsWireFormat( byte[] dst, int dstIndex )80 int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) { 81 int start = dstIndex; 82 83 dataOffset = (dstIndex - headerStart) + 26; // 26 = off from here to pad 84 85 pad = ( dataOffset - headerStart ) % 4; 86 pad = pad == 0 ? 0 : 4 - pad; 87 dataOffset += pad; 88 89 writeInt2( fid, dst, dstIndex ); 90 dstIndex += 2; 91 writeInt4( offset, dst, dstIndex ); 92 dstIndex += 4; 93 for( int i = 0; i < 4; i++ ) { 94 dst[dstIndex++] = (byte)0xFF; 95 } 96 writeInt2( writeMode, dst, dstIndex ); 97 dstIndex += 2; 98 writeInt2( remaining, dst, dstIndex ); 99 dstIndex += 2; 100 dst[dstIndex++] = (byte)0x00; 101 dst[dstIndex++] = (byte)0x00; 102 writeInt2( dataLength, dst, dstIndex ); 103 dstIndex += 2; 104 writeInt2( dataOffset, dst, dstIndex ); 105 dstIndex += 2; 106 writeInt4( offset >> 32, dst, dstIndex ); 107 dstIndex += 4; 108 109 return dstIndex - start; 110 } writeBytesWireFormat( byte[] dst, int dstIndex )111 int writeBytesWireFormat( byte[] dst, int dstIndex ) { 112 int start = dstIndex; 113 114 while( pad-- > 0 ) { 115 dst[dstIndex++] = (byte)0xEE; 116 } 117 System.arraycopy( b, off, dst, dstIndex, dataLength ); 118 dstIndex += dataLength; 119 120 return dstIndex - start; 121 } readParameterWordsWireFormat( byte[] buffer, int bufferIndex )122 int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) { 123 return 0; 124 } readBytesWireFormat( byte[] buffer, int bufferIndex )125 int readBytesWireFormat( byte[] buffer, int bufferIndex ) { 126 return 0; 127 } toString()128 public String toString() { 129 return new String( "SmbComWriteAndX[" + 130 super.toString() + 131 ",fid=" + fid + 132 ",offset=" + offset + 133 ",writeMode=" + writeMode + 134 ",remaining=" + remaining + 135 ",dataLength=" + dataLength + 136 ",dataOffset=" + dataOffset + "]" ); 137 } 138 } 139