SmbComWrite.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  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. using System;
  18. namespace SharpCifs.Smb
  19. {
  20. internal class SmbComWrite : ServerMessageBlock
  21. {
  22. private int _fid;
  23. private int _count;
  24. private int _offset;
  25. private int _remaining;
  26. private int _off;
  27. private byte[] _b;
  28. public SmbComWrite()
  29. {
  30. Command = SmbComWrite;
  31. }
  32. internal SmbComWrite(int fid, int offset, int remaining, byte[] b, int off, int len
  33. )
  34. {
  35. this._fid = fid;
  36. _count = len;
  37. this._offset = offset;
  38. this._remaining = remaining;
  39. this._b = b;
  40. this._off = off;
  41. Command = SmbComWrite;
  42. }
  43. internal virtual void SetParam(int fid, long offset, int remaining, byte[] b, int
  44. off, int len)
  45. {
  46. this._fid = fid;
  47. this._offset = (int)(offset & unchecked(0xFFFFFFFFL));
  48. this._remaining = remaining;
  49. this._b = b;
  50. this._off = off;
  51. _count = len;
  52. Digest = null;
  53. }
  54. internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
  55. {
  56. int start = dstIndex;
  57. WriteInt2(_fid, dst, dstIndex);
  58. dstIndex += 2;
  59. WriteInt2(_count, dst, dstIndex);
  60. dstIndex += 2;
  61. WriteInt4(_offset, dst, dstIndex);
  62. dstIndex += 4;
  63. WriteInt2(_remaining, dst, dstIndex);
  64. dstIndex += 2;
  65. return dstIndex - start;
  66. }
  67. internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
  68. {
  69. int start = dstIndex;
  70. dst[dstIndex++] = 0x01;
  71. WriteInt2(_count, dst, dstIndex);
  72. dstIndex += 2;
  73. Array.Copy(_b, _off, dst, dstIndex, _count);
  74. dstIndex += _count;
  75. return dstIndex - start;
  76. }
  77. internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
  78. )
  79. {
  80. return 0;
  81. }
  82. internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
  83. {
  84. return 0;
  85. }
  86. public override string ToString()
  87. {
  88. return "SmbComWrite[" + base.ToString() + ",fid=" + _fid + ",count=" +
  89. _count + ",offset=" + _offset + ",remaining=" + _remaining + "]";
  90. }
  91. }
  92. }