2
0

SftpStatVfsResponseBuilder.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using Renci.SshNet.Sftp;
  2. using Renci.SshNet.Sftp.Responses;
  3. namespace Renci.SshNet.Tests.Classes.Sftp
  4. {
  5. internal sealed class SftpStatVfsResponseBuilder
  6. {
  7. private uint _protocolVersion;
  8. private uint _responseId;
  9. private ulong _bsize;
  10. private ulong _frsize;
  11. private ulong _blocks;
  12. private ulong _bfree;
  13. private ulong _bavail;
  14. private ulong _files;
  15. private ulong _ffree;
  16. private ulong _favail;
  17. private ulong _sid;
  18. private ulong _flag;
  19. private ulong _namemax;
  20. public SftpStatVfsResponseBuilder WithProtocolVersion(uint protocolVersion)
  21. {
  22. _protocolVersion = protocolVersion;
  23. return this;
  24. }
  25. public SftpStatVfsResponseBuilder WithResponseId(uint responseId)
  26. {
  27. _responseId = responseId;
  28. return this;
  29. }
  30. public SftpStatVfsResponseBuilder WithBSize(ulong bsize)
  31. {
  32. _bsize = bsize;
  33. return this;
  34. }
  35. public SftpStatVfsResponseBuilder WithFrSize(ulong frsize)
  36. {
  37. _frsize = frsize;
  38. return this;
  39. }
  40. public SftpStatVfsResponseBuilder WithBlocks(ulong blocks)
  41. {
  42. _blocks = blocks;
  43. return this;
  44. }
  45. public SftpStatVfsResponseBuilder WithBFree(ulong bfree)
  46. {
  47. _bfree = bfree;
  48. return this;
  49. }
  50. public SftpStatVfsResponseBuilder WithBAvail(ulong bavail)
  51. {
  52. _bavail = bavail;
  53. return this;
  54. }
  55. public SftpStatVfsResponseBuilder WithFiles(ulong files)
  56. {
  57. _files = files;
  58. return this;
  59. }
  60. public SftpStatVfsResponseBuilder WithFFree(ulong ffree)
  61. {
  62. _ffree = ffree;
  63. return this;
  64. }
  65. public SftpStatVfsResponseBuilder WithFAvail(ulong favail)
  66. {
  67. _favail = favail;
  68. return this;
  69. }
  70. public SftpStatVfsResponseBuilder WithSid(ulong sid)
  71. {
  72. _sid = sid;
  73. return this;
  74. }
  75. public SftpStatVfsResponseBuilder WithIsReadOnly(bool isReadOnly)
  76. {
  77. if (isReadOnly)
  78. {
  79. _flag &= SftpFileSystemInformation.SSH_FXE_STATVFS_ST_RDONLY;
  80. }
  81. else
  82. {
  83. _flag |= SftpFileSystemInformation.SSH_FXE_STATVFS_ST_RDONLY;
  84. }
  85. return this;
  86. }
  87. public SftpStatVfsResponseBuilder WithSupportsSetUid(bool supportsSetUid)
  88. {
  89. if (supportsSetUid)
  90. {
  91. _flag |= SftpFileSystemInformation.SSH_FXE_STATVFS_ST_NOSUID;
  92. }
  93. else
  94. {
  95. _flag &= SftpFileSystemInformation.SSH_FXE_STATVFS_ST_NOSUID;
  96. }
  97. return this;
  98. }
  99. public SftpStatVfsResponseBuilder WithNameMax(ulong nameMax)
  100. {
  101. _namemax = nameMax;
  102. return this;
  103. }
  104. public StatVfsResponse Build()
  105. {
  106. var fileSystemInfo = new SftpFileSystemInformation(_bsize,
  107. _frsize,
  108. _blocks,
  109. _bfree,
  110. _bavail,
  111. _files,
  112. _ffree,
  113. _favail,
  114. _sid,
  115. _flag,
  116. _namemax);
  117. return new StatVfsResponse(_protocolVersion)
  118. {
  119. ResponseId = _responseId,
  120. Information = fileSystemInfo
  121. };
  122. }
  123. }
  124. internal sealed class StatVfsResponse : SftpResponse
  125. {
  126. public override SftpMessageTypes SftpMessageType
  127. {
  128. get { return SftpMessageTypes.ExtendedReply; }
  129. }
  130. public SftpFileSystemInformation Information { get; set; }
  131. public StatVfsResponse(uint protocolVersion)
  132. : base(protocolVersion)
  133. {
  134. }
  135. protected override void LoadData()
  136. {
  137. base.LoadData();
  138. Information = new SftpFileSystemInformation(ReadUInt64(), // FileSystemBlockSize
  139. ReadUInt64(), // BlockSize
  140. ReadUInt64(), // TotalBlocks
  141. ReadUInt64(), // FreeBlocks
  142. ReadUInt64(), // AvailableBlocks
  143. ReadUInt64(), // TotalNodes
  144. ReadUInt64(), // FreeNodes
  145. ReadUInt64(), // AvailableNodes
  146. ReadUInt64(), // Sid
  147. ReadUInt64(), // Flags
  148. ReadUInt64() // MaxNameLenght
  149. );
  150. }
  151. protected override void SaveData()
  152. {
  153. base.SaveData();
  154. Information.SaveData(DataStream);
  155. }
  156. }
  157. }