2
0

Trans2QueryFSInformationResponse.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. namespace SharpCifs.Smb
  18. {
  19. internal class Trans2QueryFsInformationResponse : SmbComTransactionResponse
  20. {
  21. internal const int SMB_INFO_ALLOCATION = 1;
  22. internal const int SmbQueryFsSizeInfo = unchecked(0x103);
  23. internal const int SmbFsFullSizeInformation = 1007;
  24. internal class SmbInfoAllocation : IAllocInfo
  25. {
  26. internal long Alloc;
  27. internal long Free;
  28. internal int SectPerAlloc;
  29. internal int BytesPerSect;
  30. // information levels
  31. // Also handles SmbQueryFSSizeInfo
  32. public virtual long GetCapacity()
  33. {
  34. return Alloc * SectPerAlloc * BytesPerSect;
  35. }
  36. public virtual long GetFree()
  37. {
  38. return Free * SectPerAlloc * BytesPerSect;
  39. }
  40. public override string ToString()
  41. {
  42. return "SmbInfoAllocation[" + "alloc=" + Alloc + ",free=" + Free + ",sectPerAlloc=" + SectPerAlloc + ",bytesPerSect=" + BytesPerSect
  43. + "]";
  44. }
  45. internal SmbInfoAllocation(Trans2QueryFsInformationResponse enclosing)
  46. {
  47. this._enclosing = enclosing;
  48. }
  49. private readonly Trans2QueryFsInformationResponse _enclosing;
  50. }
  51. private int _informationLevel;
  52. internal IAllocInfo Info;
  53. internal Trans2QueryFsInformationResponse(int informationLevel)
  54. {
  55. this._informationLevel = informationLevel;
  56. Command = SmbComTransaction2;
  57. SubCommand = Smb.SmbComTransaction.Trans2QueryFsInformation;
  58. }
  59. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  60. {
  61. return 0;
  62. }
  63. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  64. {
  65. return 0;
  66. }
  67. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  68. {
  69. return 0;
  70. }
  71. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
  72. )
  73. {
  74. return 0;
  75. }
  76. internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
  77. len)
  78. {
  79. return 0;
  80. }
  81. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  82. {
  83. switch (_informationLevel)
  84. {
  85. case SMB_INFO_ALLOCATION:
  86. {
  87. return ReadSmbInfoAllocationWireFormat(buffer, bufferIndex);
  88. }
  89. case SmbQueryFsSizeInfo:
  90. {
  91. return ReadSmbQueryFsSizeInfoWireFormat(buffer, bufferIndex);
  92. }
  93. case SmbFsFullSizeInformation:
  94. {
  95. return ReadFsFullSizeInformationWireFormat(buffer, bufferIndex);
  96. }
  97. default:
  98. {
  99. return 0;
  100. }
  101. }
  102. }
  103. internal virtual int ReadSmbInfoAllocationWireFormat(byte[] buffer, int bufferIndex
  104. )
  105. {
  106. int start = bufferIndex;
  107. SmbInfoAllocation info = new SmbInfoAllocation
  108. (this);
  109. bufferIndex += 4;
  110. // skip idFileSystem
  111. info.SectPerAlloc = ReadInt4(buffer, bufferIndex);
  112. bufferIndex += 4;
  113. info.Alloc = ReadInt4(buffer, bufferIndex);
  114. bufferIndex += 4;
  115. info.Free = ReadInt4(buffer, bufferIndex);
  116. bufferIndex += 4;
  117. info.BytesPerSect = ReadInt2(buffer, bufferIndex);
  118. bufferIndex += 4;
  119. this.Info = info;
  120. return bufferIndex - start;
  121. }
  122. internal virtual int ReadSmbQueryFsSizeInfoWireFormat(byte[] buffer, int bufferIndex
  123. )
  124. {
  125. int start = bufferIndex;
  126. SmbInfoAllocation info = new SmbInfoAllocation
  127. (this);
  128. info.Alloc = ReadInt8(buffer, bufferIndex);
  129. bufferIndex += 8;
  130. info.Free = ReadInt8(buffer, bufferIndex);
  131. bufferIndex += 8;
  132. info.SectPerAlloc = ReadInt4(buffer, bufferIndex);
  133. bufferIndex += 4;
  134. info.BytesPerSect = ReadInt4(buffer, bufferIndex);
  135. bufferIndex += 4;
  136. this.Info = info;
  137. return bufferIndex - start;
  138. }
  139. internal virtual int ReadFsFullSizeInformationWireFormat(byte[] buffer, int bufferIndex
  140. )
  141. {
  142. int start = bufferIndex;
  143. SmbInfoAllocation info = new SmbInfoAllocation
  144. (this);
  145. // Read total allocation units.
  146. info.Alloc = ReadInt8(buffer, bufferIndex);
  147. bufferIndex += 8;
  148. // read caller available allocation units
  149. info.Free = ReadInt8(buffer, bufferIndex);
  150. bufferIndex += 8;
  151. // skip actual free units
  152. bufferIndex += 8;
  153. info.SectPerAlloc = ReadInt4(buffer, bufferIndex);
  154. bufferIndex += 4;
  155. info.BytesPerSect = ReadInt4(buffer, bufferIndex);
  156. bufferIndex += 4;
  157. this.Info = info;
  158. return bufferIndex - start;
  159. }
  160. public override string ToString()
  161. {
  162. return "Trans2QueryFSInformationResponse[" + base.ToString() + "]";
  163. }
  164. }
  165. }