SmbComWrite.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. this._fid = fid;
  35. _count = len;
  36. this._offset = offset;
  37. this._remaining = remaining;
  38. this._b = b;
  39. this._off = off;
  40. Command = SmbComWrite;
  41. }
  42. internal virtual void SetParam(int fid,
  43. long offset,
  44. int remaining,
  45. byte[] b,
  46. int off,
  47. int len)
  48. {
  49. this._fid = fid;
  50. this._offset = (int)(offset & unchecked(0xFFFFFFFFL));
  51. this._remaining = remaining;
  52. this._b = b;
  53. this._off = off;
  54. _count = len;
  55. Digest = null;
  56. }
  57. internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
  58. {
  59. int start = dstIndex;
  60. WriteInt2(_fid, dst, dstIndex);
  61. dstIndex += 2;
  62. WriteInt2(_count, dst, dstIndex);
  63. dstIndex += 2;
  64. WriteInt4(_offset, dst, dstIndex);
  65. dstIndex += 4;
  66. WriteInt2(_remaining, dst, dstIndex);
  67. dstIndex += 2;
  68. return dstIndex - start;
  69. }
  70. internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
  71. {
  72. int start = dstIndex;
  73. dst[dstIndex++] = 0x01;
  74. WriteInt2(_count, dst, dstIndex);
  75. dstIndex += 2;
  76. Array.Copy(_b, _off, dst, dstIndex, _count);
  77. dstIndex += _count;
  78. return dstIndex - start;
  79. }
  80. internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex)
  81. {
  82. return 0;
  83. }
  84. internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
  85. {
  86. return 0;
  87. }
  88. public override string ToString()
  89. {
  90. return "SmbComWrite["
  91. + base.ToString()
  92. + ",fid=" + _fid
  93. + ",count=" + _count
  94. + ",offset=" + _offset
  95. + ",remaining=" + _remaining + "]";
  96. }
  97. }
  98. }