Nfsv3Decoder.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Nfsv3Decoder = void 0;
  4. const tslib_1 = require("tslib");
  5. const Reader_1 = require("@jsonjoy.com/buffers/lib/Reader");
  6. const XdrDecoder_1 = require("../../xdr/XdrDecoder");
  7. const errors_1 = require("./errors");
  8. const msg = tslib_1.__importStar(require("./messages"));
  9. const structs = tslib_1.__importStar(require("./structs"));
  10. class Nfsv3Decoder {
  11. constructor(reader = new Reader_1.Reader()) {
  12. this.xdr = new XdrDecoder_1.XdrDecoder(reader);
  13. }
  14. decodeMessage(reader, proc, isRequest) {
  15. this.xdr.reader = reader;
  16. const startPos = reader.x;
  17. try {
  18. if (isRequest) {
  19. return this.decodeRequest(proc);
  20. }
  21. else {
  22. return this.decodeResponse(proc);
  23. }
  24. }
  25. catch (err) {
  26. if (err instanceof RangeError) {
  27. reader.x = startPos;
  28. return undefined;
  29. }
  30. throw err;
  31. }
  32. }
  33. decodeRequest(proc) {
  34. switch (proc) {
  35. case 1:
  36. return this.decodeGetattrRequest();
  37. case 2:
  38. return this.decodeSetattrRequest();
  39. case 3:
  40. return this.decodeLookupRequest();
  41. case 4:
  42. return this.decodeAccessRequest();
  43. case 5:
  44. return this.decodeReadlinkRequest();
  45. case 6:
  46. return this.decodeReadRequest();
  47. case 7:
  48. return this.decodeWriteRequest();
  49. case 8:
  50. return this.decodeCreateRequest();
  51. case 9:
  52. return this.decodeMkdirRequest();
  53. case 10:
  54. return this.decodeSymlinkRequest();
  55. case 11:
  56. return this.decodeMknodRequest();
  57. case 12:
  58. return this.decodeRemoveRequest();
  59. case 13:
  60. return this.decodeRmdirRequest();
  61. case 14:
  62. return this.decodeRenameRequest();
  63. case 15:
  64. return this.decodeLinkRequest();
  65. case 16:
  66. return this.decodeReaddirRequest();
  67. case 17:
  68. return this.decodeReaddirplusRequest();
  69. case 18:
  70. return this.decodeFsstatRequest();
  71. case 19:
  72. return this.decodeFsinfoRequest();
  73. case 20:
  74. return this.decodePathconfRequest();
  75. case 21:
  76. return this.decodeCommitRequest();
  77. default:
  78. throw new errors_1.Nfsv3DecodingError(`Unknown procedure: \${proc}`);
  79. }
  80. }
  81. decodeResponse(proc) {
  82. switch (proc) {
  83. case 1:
  84. return this.decodeGetattrResponse();
  85. case 2:
  86. return this.decodeSetattrResponse();
  87. case 3:
  88. return this.decodeLookupResponse();
  89. case 4:
  90. return this.decodeAccessResponse();
  91. case 5:
  92. return this.decodeReadlinkResponse();
  93. case 6:
  94. return this.decodeReadResponse();
  95. case 7:
  96. return this.decodeWriteResponse();
  97. case 8:
  98. return this.decodeCreateResponse();
  99. case 9:
  100. return this.decodeMkdirResponse();
  101. case 10:
  102. return this.decodeSymlinkResponse();
  103. case 11:
  104. return this.decodeMknodResponse();
  105. case 12:
  106. return this.decodeRemoveResponse();
  107. case 13:
  108. return this.decodeRmdirResponse();
  109. case 14:
  110. return this.decodeRenameResponse();
  111. case 15:
  112. return this.decodeLinkResponse();
  113. case 16:
  114. return this.decodeReaddirResponse();
  115. case 17:
  116. return this.decodeReaddirplusResponse();
  117. case 18:
  118. return this.decodeFsstatResponse();
  119. case 19:
  120. return this.decodeFsinfoResponse();
  121. case 20:
  122. return this.decodePathconfResponse();
  123. case 21:
  124. return this.decodeCommitResponse();
  125. default:
  126. throw new errors_1.Nfsv3DecodingError(`Unknown procedure: \${proc}`);
  127. }
  128. }
  129. readFh() {
  130. const data = this.xdr.readVarlenOpaque();
  131. return new structs.Nfsv3Fh(data);
  132. }
  133. readFilename() {
  134. return this.xdr.readString();
  135. }
  136. readTime() {
  137. const xdr = this.xdr;
  138. const seconds = xdr.readUnsignedInt();
  139. const nseconds = xdr.readUnsignedInt();
  140. return new structs.Nfsv3Time(seconds, nseconds);
  141. }
  142. readSpecData() {
  143. const xdr = this.xdr;
  144. const specdata1 = xdr.readUnsignedInt();
  145. const specdata2 = xdr.readUnsignedInt();
  146. return new structs.Nfsv3SpecData(specdata1, specdata2);
  147. }
  148. readFattr() {
  149. const xdr = this.xdr;
  150. const type = xdr.readUnsignedInt();
  151. const mode = xdr.readUnsignedInt();
  152. const nlink = xdr.readUnsignedInt();
  153. const uid = xdr.readUnsignedInt();
  154. const gid = xdr.readUnsignedInt();
  155. const size = xdr.readUnsignedHyper();
  156. const used = xdr.readUnsignedHyper();
  157. const rdev = this.readSpecData();
  158. const fsid = xdr.readUnsignedHyper();
  159. const fileid = xdr.readUnsignedHyper();
  160. const atime = this.readTime();
  161. const mtime = this.readTime();
  162. const ctime = this.readTime();
  163. return new structs.Nfsv3Fattr(type, mode, nlink, uid, gid, size, used, rdev, fsid, fileid, atime, mtime, ctime);
  164. }
  165. readPostOpAttr() {
  166. const attributesFollow = this.xdr.readBoolean();
  167. const attributes = attributesFollow ? this.readFattr() : undefined;
  168. return new structs.Nfsv3PostOpAttr(attributesFollow, attributes);
  169. }
  170. readWccAttr() {
  171. const size = this.xdr.readUnsignedHyper();
  172. const mtime = this.readTime();
  173. const ctime = this.readTime();
  174. return new structs.Nfsv3WccAttr(size, mtime, ctime);
  175. }
  176. readPreOpAttr() {
  177. const attributesFollow = this.xdr.readBoolean();
  178. const attributes = attributesFollow ? this.readWccAttr() : undefined;
  179. return new structs.Nfsv3PreOpAttr(attributesFollow, attributes);
  180. }
  181. readWccData() {
  182. const before = this.readPreOpAttr();
  183. const after = this.readPostOpAttr();
  184. return new structs.Nfsv3WccData(before, after);
  185. }
  186. readPostOpFh() {
  187. const handleFollows = this.xdr.readBoolean();
  188. const handle = handleFollows ? this.readFh() : undefined;
  189. return new structs.Nfsv3PostOpFh(handleFollows, handle);
  190. }
  191. readSetMode() {
  192. const set = this.xdr.readBoolean();
  193. const mode = set ? this.xdr.readUnsignedInt() : undefined;
  194. return new structs.Nfsv3SetMode(set, mode);
  195. }
  196. readSetUid() {
  197. const set = this.xdr.readBoolean();
  198. const uid = set ? this.xdr.readUnsignedInt() : undefined;
  199. return new structs.Nfsv3SetUid(set, uid);
  200. }
  201. readSetGid() {
  202. const set = this.xdr.readBoolean();
  203. const gid = set ? this.xdr.readUnsignedInt() : undefined;
  204. return new structs.Nfsv3SetGid(set, gid);
  205. }
  206. readSetSize() {
  207. const set = this.xdr.readBoolean();
  208. const size = set ? this.xdr.readUnsignedHyper() : undefined;
  209. return new structs.Nfsv3SetSize(set, size);
  210. }
  211. readSetAtime() {
  212. const how = this.xdr.readUnsignedInt();
  213. const atime = how === 2 ? this.readTime() : undefined;
  214. return new structs.Nfsv3SetAtime(how, atime);
  215. }
  216. readSetMtime() {
  217. const how = this.xdr.readUnsignedInt();
  218. const mtime = how === 2 ? this.readTime() : undefined;
  219. return new structs.Nfsv3SetMtime(how, mtime);
  220. }
  221. readSattr() {
  222. const mode = this.readSetMode();
  223. const uid = this.readSetUid();
  224. const gid = this.readSetGid();
  225. const size = this.readSetSize();
  226. const atime = this.readSetAtime();
  227. const mtime = this.readSetMtime();
  228. return new structs.Nfsv3Sattr(mode, uid, gid, size, atime, mtime);
  229. }
  230. readSattrGuard() {
  231. const check = this.xdr.readBoolean();
  232. const objCtime = check ? this.readTime() : undefined;
  233. return new structs.Nfsv3SattrGuard(check, objCtime);
  234. }
  235. readDirOpArgs() {
  236. const dir = this.readFh();
  237. const name = this.readFilename();
  238. return new structs.Nfsv3DirOpArgs(dir, name);
  239. }
  240. readCreateHow() {
  241. const xdr = this.xdr;
  242. const mode = xdr.readUnsignedInt();
  243. let objAttributes;
  244. let verf;
  245. if (mode === 0 || mode === 1) {
  246. objAttributes = this.readSattr();
  247. }
  248. else if (mode === 2) {
  249. const verfData = xdr.readOpaque(8);
  250. verf = verfData;
  251. }
  252. return new structs.Nfsv3CreateHow(mode, objAttributes, verf);
  253. }
  254. readMknodData() {
  255. const type = this.xdr.readUnsignedInt();
  256. let chr;
  257. let blk;
  258. let sock;
  259. let pipe;
  260. switch (type) {
  261. case 4:
  262. chr = new structs.Nfsv3DeviceData(this.readSattr(), this.readSpecData());
  263. break;
  264. case 3:
  265. blk = new structs.Nfsv3DeviceData(this.readSattr(), this.readSpecData());
  266. break;
  267. case 6:
  268. sock = this.readSattr();
  269. break;
  270. case 7:
  271. pipe = this.readSattr();
  272. break;
  273. }
  274. return new structs.Nfsv3MknodData(type, chr, blk, sock, pipe);
  275. }
  276. readEntry() {
  277. const xdr = this.xdr;
  278. const valueFollows = xdr.readBoolean();
  279. if (!valueFollows)
  280. return undefined;
  281. const fileid = xdr.readUnsignedHyper();
  282. const name = this.readFilename();
  283. const cookie = xdr.readUnsignedHyper();
  284. const nextentry = this.readEntry();
  285. return new structs.Nfsv3Entry(fileid, name, cookie, nextentry);
  286. }
  287. readEntryPlus() {
  288. const xdr = this.xdr;
  289. const valueFollows = xdr.readBoolean();
  290. if (!valueFollows)
  291. return undefined;
  292. const fileid = xdr.readUnsignedHyper();
  293. const name = this.readFilename();
  294. const cookie = xdr.readUnsignedHyper();
  295. const nameAttributes = this.readPostOpAttr();
  296. const nameHandle = this.readPostOpFh();
  297. const nextentry = this.readEntryPlus();
  298. return new structs.Nfsv3EntryPlus(fileid, name, cookie, nameAttributes, nameHandle, nextentry);
  299. }
  300. readDirList() {
  301. const entries = this.readEntry();
  302. const eof = this.xdr.readBoolean();
  303. return new structs.Nfsv3DirList(eof, entries);
  304. }
  305. readDirListPlus() {
  306. const entries = this.readEntryPlus();
  307. const eof = this.xdr.readBoolean();
  308. return new structs.Nfsv3DirListPlus(eof, entries);
  309. }
  310. decodeGetattrRequest() {
  311. const object = this.readFh();
  312. return new msg.Nfsv3GetattrRequest(object);
  313. }
  314. decodeGetattrResponse() {
  315. const status = this.xdr.readUnsignedInt();
  316. let resok;
  317. if (status === 0) {
  318. const objAttributes = this.readFattr();
  319. resok = new msg.Nfsv3GetattrResOk(objAttributes);
  320. }
  321. return new msg.Nfsv3GetattrResponse(status, resok);
  322. }
  323. decodeSetattrRequest() {
  324. const object = this.readFh();
  325. const newAttributes = this.readSattr();
  326. const guard = this.readSattrGuard();
  327. return new msg.Nfsv3SetattrRequest(object, newAttributes, guard);
  328. }
  329. decodeSetattrResponse() {
  330. const status = this.xdr.readUnsignedInt();
  331. let resok;
  332. let resfail;
  333. const objWcc = this.readWccData();
  334. if (status === 0) {
  335. resok = new msg.Nfsv3SetattrResOk(objWcc);
  336. }
  337. else {
  338. resfail = new msg.Nfsv3SetattrResFail(objWcc);
  339. }
  340. return new msg.Nfsv3SetattrResponse(status, resok, resfail);
  341. }
  342. decodeLookupRequest() {
  343. const what = this.readDirOpArgs();
  344. return new msg.Nfsv3LookupRequest(what);
  345. }
  346. decodeLookupResponse() {
  347. const status = this.xdr.readUnsignedInt();
  348. let resok;
  349. let resfail;
  350. if (status === 0) {
  351. const object = this.readFh();
  352. const objAttributes = this.readPostOpAttr();
  353. const dirAttributes = this.readPostOpAttr();
  354. resok = new msg.Nfsv3LookupResOk(object, objAttributes, dirAttributes);
  355. }
  356. else {
  357. const dirAttributes = this.readPostOpAttr();
  358. resfail = new msg.Nfsv3LookupResFail(dirAttributes);
  359. }
  360. return new msg.Nfsv3LookupResponse(status, resok, resfail);
  361. }
  362. decodeAccessRequest() {
  363. const object = this.readFh();
  364. const access = this.xdr.readUnsignedInt();
  365. return new msg.Nfsv3AccessRequest(object, access);
  366. }
  367. decodeAccessResponse() {
  368. const xdr = this.xdr;
  369. const status = xdr.readUnsignedInt();
  370. let resok;
  371. let resfail;
  372. const objAttributes = this.readPostOpAttr();
  373. if (status === 0) {
  374. const access = xdr.readUnsignedInt();
  375. resok = new msg.Nfsv3AccessResOk(objAttributes, access);
  376. }
  377. else {
  378. resfail = new msg.Nfsv3AccessResFail(objAttributes);
  379. }
  380. return new msg.Nfsv3AccessResponse(status, resok, resfail);
  381. }
  382. decodeReadlinkRequest() {
  383. const symlink = this.readFh();
  384. return new msg.Nfsv3ReadlinkRequest(symlink);
  385. }
  386. decodeReadlinkResponse() {
  387. const status = this.xdr.readUnsignedInt();
  388. let resok;
  389. let resfail;
  390. const symlinkAttributes = this.readPostOpAttr();
  391. if (status === 0) {
  392. const data = this.readFilename();
  393. resok = new msg.Nfsv3ReadlinkResOk(symlinkAttributes, data);
  394. }
  395. else {
  396. resfail = new msg.Nfsv3ReadlinkResFail(symlinkAttributes);
  397. }
  398. return new msg.Nfsv3ReadlinkResponse(status, resok, resfail);
  399. }
  400. decodeReadRequest() {
  401. const file = this.readFh();
  402. const xdr = this.xdr;
  403. const offset = xdr.readUnsignedHyper();
  404. const count = xdr.readUnsignedInt();
  405. return new msg.Nfsv3ReadRequest(file, offset, count);
  406. }
  407. decodeReadResponse() {
  408. const status = this.xdr.readUnsignedInt();
  409. let resok;
  410. let resfail;
  411. const fileAttributes = this.readPostOpAttr();
  412. if (status === 0) {
  413. const xdr = this.xdr;
  414. const count = xdr.readUnsignedInt();
  415. const eof = xdr.readBoolean();
  416. const data = xdr.readVarlenOpaque();
  417. resok = new msg.Nfsv3ReadResOk(fileAttributes, count, eof, data);
  418. }
  419. else {
  420. resfail = new msg.Nfsv3ReadResFail(fileAttributes);
  421. }
  422. return new msg.Nfsv3ReadResponse(status, resok, resfail);
  423. }
  424. decodeWriteRequest() {
  425. const file = this.readFh();
  426. const xdr = this.xdr;
  427. const offset = xdr.readUnsignedHyper();
  428. const count = xdr.readUnsignedInt();
  429. const stable = xdr.readUnsignedInt();
  430. const data = xdr.readVarlenOpaque();
  431. return new msg.Nfsv3WriteRequest(file, offset, count, stable, data);
  432. }
  433. decodeWriteResponse() {
  434. const xdr = this.xdr;
  435. const status = xdr.readUnsignedInt();
  436. let resok;
  437. let resfail;
  438. const fileWcc = this.readWccData();
  439. if (status === 0) {
  440. const count = xdr.readUnsignedInt();
  441. const committed = xdr.readUnsignedInt();
  442. const verf = xdr.readOpaque(8);
  443. resok = new msg.Nfsv3WriteResOk(fileWcc, count, committed, verf);
  444. }
  445. else {
  446. resfail = new msg.Nfsv3WriteResFail(fileWcc);
  447. }
  448. return new msg.Nfsv3WriteResponse(status, resok, resfail);
  449. }
  450. decodeCreateRequest() {
  451. const where = this.readDirOpArgs();
  452. const how = this.readCreateHow();
  453. return new msg.Nfsv3CreateRequest(where, how);
  454. }
  455. decodeCreateResponse() {
  456. const status = this.xdr.readUnsignedInt();
  457. let resok;
  458. let resfail;
  459. if (status === 0) {
  460. const obj = this.readPostOpFh();
  461. const objAttributes = this.readPostOpAttr();
  462. const dirWcc = this.readWccData();
  463. resok = new msg.Nfsv3CreateResOk(obj, objAttributes, dirWcc);
  464. }
  465. else {
  466. const dirWcc = this.readWccData();
  467. resfail = new msg.Nfsv3CreateResFail(dirWcc);
  468. }
  469. return new msg.Nfsv3CreateResponse(status, resok, resfail);
  470. }
  471. decodeMkdirRequest() {
  472. const where = this.readDirOpArgs();
  473. const attributes = this.readSattr();
  474. return new msg.Nfsv3MkdirRequest(where, attributes);
  475. }
  476. decodeMkdirResponse() {
  477. const status = this.xdr.readUnsignedInt();
  478. let resok;
  479. let resfail;
  480. if (status === 0) {
  481. const obj = this.readPostOpFh();
  482. const objAttributes = this.readPostOpAttr();
  483. const dirWcc = this.readWccData();
  484. resok = new msg.Nfsv3MkdirResOk(obj, objAttributes, dirWcc);
  485. }
  486. else {
  487. const dirWcc = this.readWccData();
  488. resfail = new msg.Nfsv3MkdirResFail(dirWcc);
  489. }
  490. return new msg.Nfsv3MkdirResponse(status, resok, resfail);
  491. }
  492. decodeSymlinkRequest() {
  493. const where = this.readDirOpArgs();
  494. const symlinkAttributes = this.readSattr();
  495. const symlinkData = this.readFilename();
  496. return new msg.Nfsv3SymlinkRequest(where, symlinkAttributes, symlinkData);
  497. }
  498. decodeSymlinkResponse() {
  499. const status = this.xdr.readUnsignedInt();
  500. let resok;
  501. let resfail;
  502. if (status === 0) {
  503. const obj = this.readPostOpFh();
  504. const objAttributes = this.readPostOpAttr();
  505. const dirWcc = this.readWccData();
  506. resok = new msg.Nfsv3SymlinkResOk(obj, objAttributes, dirWcc);
  507. }
  508. else {
  509. const dirWcc = this.readWccData();
  510. resfail = new msg.Nfsv3SymlinkResFail(dirWcc);
  511. }
  512. return new msg.Nfsv3SymlinkResponse(status, resok, resfail);
  513. }
  514. decodeMknodRequest() {
  515. const where = this.readDirOpArgs();
  516. const what = this.readMknodData();
  517. return new msg.Nfsv3MknodRequest(where, what);
  518. }
  519. decodeMknodResponse() {
  520. const status = this.xdr.readUnsignedInt();
  521. let resok;
  522. let resfail;
  523. if (status === 0) {
  524. const obj = this.readPostOpFh();
  525. const objAttributes = this.readPostOpAttr();
  526. const dirWcc = this.readWccData();
  527. resok = new msg.Nfsv3MknodResOk(obj, objAttributes, dirWcc);
  528. }
  529. else {
  530. const dirWcc = this.readWccData();
  531. resfail = new msg.Nfsv3MknodResFail(dirWcc);
  532. }
  533. return new msg.Nfsv3MknodResponse(status, resok, resfail);
  534. }
  535. decodeRemoveRequest() {
  536. const object = this.readDirOpArgs();
  537. return new msg.Nfsv3RemoveRequest(object);
  538. }
  539. decodeRemoveResponse() {
  540. const status = this.xdr.readUnsignedInt();
  541. let resok;
  542. let resfail;
  543. const dirWcc = this.readWccData();
  544. if (status === 0) {
  545. resok = new msg.Nfsv3RemoveResOk(dirWcc);
  546. }
  547. else {
  548. resfail = new msg.Nfsv3RemoveResFail(dirWcc);
  549. }
  550. return new msg.Nfsv3RemoveResponse(status, resok, resfail);
  551. }
  552. decodeRmdirRequest() {
  553. const object = this.readDirOpArgs();
  554. return new msg.Nfsv3RmdirRequest(object);
  555. }
  556. decodeRmdirResponse() {
  557. const status = this.xdr.readUnsignedInt();
  558. let resok;
  559. let resfail;
  560. const dirWcc = this.readWccData();
  561. if (status === 0) {
  562. resok = new msg.Nfsv3RmdirResOk(dirWcc);
  563. }
  564. else {
  565. resfail = new msg.Nfsv3RmdirResFail(dirWcc);
  566. }
  567. return new msg.Nfsv3RmdirResponse(status, resok, resfail);
  568. }
  569. decodeRenameRequest() {
  570. const from = this.readDirOpArgs();
  571. const to = this.readDirOpArgs();
  572. return new msg.Nfsv3RenameRequest(from, to);
  573. }
  574. decodeRenameResponse() {
  575. const status = this.xdr.readUnsignedInt();
  576. let resok;
  577. let resfail;
  578. const fromDirWcc = this.readWccData();
  579. const toDirWcc = this.readWccData();
  580. if (status === 0) {
  581. resok = new msg.Nfsv3RenameResOk(fromDirWcc, toDirWcc);
  582. }
  583. else {
  584. resfail = new msg.Nfsv3RenameResFail(fromDirWcc, toDirWcc);
  585. }
  586. return new msg.Nfsv3RenameResponse(status, resok, resfail);
  587. }
  588. decodeLinkRequest() {
  589. const file = this.readFh();
  590. const link = this.readDirOpArgs();
  591. return new msg.Nfsv3LinkRequest(file, link);
  592. }
  593. decodeLinkResponse() {
  594. const status = this.xdr.readUnsignedInt();
  595. let resok;
  596. let resfail;
  597. const fileAttributes = this.readPostOpAttr();
  598. const linkDirWcc = this.readWccData();
  599. if (status === 0) {
  600. resok = new msg.Nfsv3LinkResOk(fileAttributes, linkDirWcc);
  601. }
  602. else {
  603. resfail = new msg.Nfsv3LinkResFail(fileAttributes, linkDirWcc);
  604. }
  605. return new msg.Nfsv3LinkResponse(status, resok, resfail);
  606. }
  607. decodeReaddirRequest() {
  608. const dir = this.readFh();
  609. const xdr = this.xdr;
  610. const cookie = xdr.readUnsignedHyper();
  611. const cookieverf = xdr.readOpaque(8);
  612. const count = xdr.readUnsignedInt();
  613. return new msg.Nfsv3ReaddirRequest(dir, cookie, cookieverf, count);
  614. }
  615. decodeReaddirResponse() {
  616. const xdr = this.xdr;
  617. const status = xdr.readUnsignedInt();
  618. let resok;
  619. let resfail;
  620. const dirAttributes = this.readPostOpAttr();
  621. if (status === 0) {
  622. const cookieverf = xdr.readOpaque(8);
  623. const reply = this.readDirList();
  624. resok = new msg.Nfsv3ReaddirResOk(dirAttributes, cookieverf, reply);
  625. }
  626. else {
  627. resfail = new msg.Nfsv3ReaddirResFail(dirAttributes);
  628. }
  629. return new msg.Nfsv3ReaddirResponse(status, resok, resfail);
  630. }
  631. decodeReaddirplusRequest() {
  632. const dir = this.readFh();
  633. const xdr = this.xdr;
  634. const cookie = xdr.readUnsignedHyper();
  635. const cookieverf = xdr.readOpaque(8);
  636. const dircount = xdr.readUnsignedInt();
  637. const maxcount = xdr.readUnsignedInt();
  638. return new msg.Nfsv3ReaddirplusRequest(dir, cookie, cookieverf, dircount, maxcount);
  639. }
  640. decodeReaddirplusResponse() {
  641. const xdr = this.xdr;
  642. const status = xdr.readUnsignedInt();
  643. let resok;
  644. let resfail;
  645. const dirAttributes = this.readPostOpAttr();
  646. if (status === 0) {
  647. const cookieverf = xdr.readOpaque(8);
  648. const reply = this.readDirListPlus();
  649. resok = new msg.Nfsv3ReaddirplusResOk(dirAttributes, cookieverf, reply);
  650. }
  651. else {
  652. resfail = new msg.Nfsv3ReaddirplusResFail(dirAttributes);
  653. }
  654. return new msg.Nfsv3ReaddirplusResponse(status, resok, resfail);
  655. }
  656. decodeFsstatRequest() {
  657. const fsroot = this.readFh();
  658. return new msg.Nfsv3FsstatRequest(fsroot);
  659. }
  660. decodeFsstatResponse() {
  661. const xdr = this.xdr;
  662. const status = xdr.readUnsignedInt();
  663. let resok;
  664. let resfail;
  665. const objAttributes = this.readPostOpAttr();
  666. if (status === 0) {
  667. const tbytes = xdr.readUnsignedHyper();
  668. const fbytes = xdr.readUnsignedHyper();
  669. const abytes = xdr.readUnsignedHyper();
  670. const tfiles = xdr.readUnsignedHyper();
  671. const ffiles = xdr.readUnsignedHyper();
  672. const afiles = xdr.readUnsignedHyper();
  673. const invarsec = xdr.readUnsignedInt();
  674. resok = new msg.Nfsv3FsstatResOk(objAttributes, tbytes, fbytes, abytes, tfiles, ffiles, afiles, invarsec);
  675. }
  676. else {
  677. resfail = new msg.Nfsv3FsstatResFail(objAttributes);
  678. }
  679. return new msg.Nfsv3FsstatResponse(status, resok, resfail);
  680. }
  681. decodeFsinfoRequest() {
  682. const fsroot = this.readFh();
  683. return new msg.Nfsv3FsinfoRequest(fsroot);
  684. }
  685. decodeFsinfoResponse() {
  686. const xdr = this.xdr;
  687. const status = xdr.readUnsignedInt();
  688. let resok;
  689. let resfail;
  690. const objAttributes = this.readPostOpAttr();
  691. if (status === 0) {
  692. const rtmax = xdr.readUnsignedInt();
  693. const rtpref = xdr.readUnsignedInt();
  694. const rtmult = xdr.readUnsignedInt();
  695. const wtmax = xdr.readUnsignedInt();
  696. const wtpref = xdr.readUnsignedInt();
  697. const wtmult = xdr.readUnsignedInt();
  698. const dtpref = xdr.readUnsignedInt();
  699. const maxfilesize = xdr.readUnsignedHyper();
  700. const timeDelta = { seconds: xdr.readUnsignedInt(), nseconds: xdr.readUnsignedInt() };
  701. const properties = xdr.readUnsignedInt();
  702. resok = new msg.Nfsv3FsinfoResOk(objAttributes, rtmax, rtpref, rtmult, wtmax, wtpref, wtmult, dtpref, maxfilesize, timeDelta, properties);
  703. }
  704. else {
  705. resfail = new msg.Nfsv3FsinfoResFail(objAttributes);
  706. }
  707. return new msg.Nfsv3FsinfoResponse(status, resok, resfail);
  708. }
  709. decodePathconfRequest() {
  710. const object = this.readFh();
  711. return new msg.Nfsv3PathconfRequest(object);
  712. }
  713. decodePathconfResponse() {
  714. const xdr = this.xdr;
  715. const status = xdr.readUnsignedInt();
  716. let resok;
  717. let resfail;
  718. const objAttributes = this.readPostOpAttr();
  719. if (status === 0) {
  720. const linkmax = xdr.readUnsignedInt();
  721. const namemax = xdr.readUnsignedInt();
  722. const noTrunc = xdr.readBoolean();
  723. const chownRestricted = xdr.readBoolean();
  724. const caseInsensitive = xdr.readBoolean();
  725. const casePreserving = xdr.readBoolean();
  726. resok = new msg.Nfsv3PathconfResOk(objAttributes, linkmax, namemax, noTrunc, chownRestricted, caseInsensitive, casePreserving);
  727. }
  728. else {
  729. resfail = new msg.Nfsv3PathconfResFail(objAttributes);
  730. }
  731. return new msg.Nfsv3PathconfResponse(status, resok, resfail);
  732. }
  733. decodeCommitRequest() {
  734. const file = this.readFh();
  735. const xdr = this.xdr;
  736. const offset = xdr.readUnsignedHyper();
  737. const count = xdr.readUnsignedInt();
  738. return new msg.Nfsv3CommitRequest(file, offset, count);
  739. }
  740. decodeCommitResponse() {
  741. const xdr = this.xdr;
  742. const status = xdr.readUnsignedInt();
  743. let resok;
  744. let resfail;
  745. const fileWcc = this.readWccData();
  746. if (status === 0) {
  747. const verf = xdr.readOpaque(8);
  748. resok = new msg.Nfsv3CommitResOk(fileWcc, verf);
  749. }
  750. else {
  751. resfail = new msg.Nfsv3CommitResFail(fileWcc);
  752. }
  753. return new msg.Nfsv3CommitResponse(status, resok, resfail);
  754. }
  755. }
  756. exports.Nfsv3Decoder = Nfsv3Decoder;
  757. //# sourceMappingURL=Nfsv3Decoder.js.map