MountEncoder.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.MountEncoder = void 0;
  4. const Writer_1 = require("@jsonjoy.com/util/lib/buffers/Writer");
  5. const XdrEncoder_1 = require("../../../xdr/XdrEncoder");
  6. const errors_1 = require("../errors");
  7. class MountEncoder {
  8. constructor(writer = new Writer_1.Writer()) {
  9. this.writer = writer;
  10. this.xdr = new XdrEncoder_1.XdrEncoder(writer);
  11. }
  12. encodeMessage(message, proc, isRequest) {
  13. if (isRequest)
  14. this.writeRequest(message, proc);
  15. else
  16. this.writeResponse(message, proc);
  17. return this.writer.flush();
  18. }
  19. writeMessage(message, proc, isRequest) {
  20. if (isRequest)
  21. this.writeRequest(message, proc);
  22. else
  23. this.writeResponse(message, proc);
  24. }
  25. writeRequest(request, proc) {
  26. switch (proc) {
  27. case 0:
  28. return;
  29. case 1:
  30. return this.writeMntRequest(request);
  31. case 2:
  32. return;
  33. case 3:
  34. return this.writeUmntRequest(request);
  35. case 4:
  36. return;
  37. case 5:
  38. return;
  39. default:
  40. throw new errors_1.Nfsv3EncodingError(`Unknown MOUNT procedure: ${proc}`);
  41. }
  42. }
  43. writeResponse(response, proc) {
  44. switch (proc) {
  45. case 0:
  46. return;
  47. case 1:
  48. return this.writeMntResponse(response);
  49. case 2:
  50. return this.writeDumpResponse(response);
  51. case 3:
  52. return;
  53. case 4:
  54. return;
  55. case 5:
  56. return this.writeExportResponse(response);
  57. default:
  58. throw new errors_1.Nfsv3EncodingError(`Unknown MOUNT procedure: ${proc}`);
  59. }
  60. }
  61. writeFhandle3(fh) {
  62. const data = fh.data.uint8;
  63. this.xdr.writeVarlenOpaque(data);
  64. }
  65. writeDirpath(path) {
  66. this.xdr.writeStr(path);
  67. }
  68. writeMountBody(body) {
  69. const xdr = this.xdr;
  70. if (!body) {
  71. xdr.writeBoolean(false);
  72. return;
  73. }
  74. xdr.writeBoolean(true);
  75. xdr.writeStr(body.hostname);
  76. this.writeDirpath(body.directory);
  77. this.writeMountBody(body.next);
  78. }
  79. writeGroupNode(group) {
  80. const xdr = this.xdr;
  81. if (!group) {
  82. xdr.writeBoolean(false);
  83. return;
  84. }
  85. xdr.writeBoolean(true);
  86. xdr.writeStr(group.name);
  87. this.writeGroupNode(group.next);
  88. }
  89. writeExportNode(exportNode) {
  90. const xdr = this.xdr;
  91. if (!exportNode) {
  92. xdr.writeBoolean(false);
  93. return;
  94. }
  95. xdr.writeBoolean(true);
  96. this.writeDirpath(exportNode.dir);
  97. this.writeGroupNode(exportNode.groups);
  98. this.writeExportNode(exportNode.next);
  99. }
  100. writeMntRequest(req) {
  101. this.writeDirpath(req.dirpath);
  102. }
  103. writeMntResponse(res) {
  104. const xdr = this.xdr;
  105. xdr.writeUnsignedInt(res.status);
  106. if (res.status === 0 && res.mountinfo) {
  107. this.writeFhandle3(res.mountinfo.fhandle);
  108. xdr.writeUnsignedInt(res.mountinfo.authFlavors.length);
  109. for (const flavor of res.mountinfo.authFlavors) {
  110. xdr.writeUnsignedInt(flavor);
  111. }
  112. }
  113. }
  114. writeDumpResponse(res) {
  115. this.writeMountBody(res.mountlist);
  116. }
  117. writeUmntRequest(req) {
  118. this.writeDirpath(req.dirpath);
  119. }
  120. writeExportResponse(res) {
  121. this.writeExportNode(res.exports);
  122. }
  123. }
  124. exports.MountEncoder = MountEncoder;
  125. //# sourceMappingURL=MountEncoder.js.map