Nfsv4Decoder.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Nfsv4Decoder = 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 Nfsv4Decoder {
  11. constructor(reader = new Reader_1.Reader()) {
  12. this.xdr = new XdrDecoder_1.XdrDecoder(reader);
  13. }
  14. decodeCompound(reader, isRequest) {
  15. if (isRequest) {
  16. return this.decodeCompoundRequest(reader);
  17. }
  18. else {
  19. return this.decodeCompoundResponse(reader);
  20. }
  21. }
  22. decodeCompoundRequest(reader) {
  23. const xdr = this.xdr;
  24. xdr.reader = reader;
  25. const tag = xdr.readString();
  26. const minorversion = xdr.readUnsignedInt();
  27. const argarray = [];
  28. const count = xdr.readUnsignedInt();
  29. for (let i = 0; i < count; i++) {
  30. const op = xdr.readUnsignedInt();
  31. const request = this.decodeRequest(op);
  32. if (request)
  33. argarray.push(request);
  34. }
  35. return new msg.Nfsv4CompoundRequest(tag, minorversion, argarray);
  36. }
  37. decodeCompoundResponse(reader) {
  38. const xdr = this.xdr;
  39. xdr.reader = reader;
  40. const status = xdr.readUnsignedInt();
  41. const tag = xdr.readString();
  42. const resarray = [];
  43. const count = xdr.readUnsignedInt();
  44. for (let i = 0; i < count; i++) {
  45. const op = xdr.readUnsignedInt();
  46. const response = this.decodeResponse(op);
  47. if (response)
  48. resarray.push(response);
  49. }
  50. return new msg.Nfsv4CompoundResponse(status, tag, resarray);
  51. }
  52. decodeRequest(op) {
  53. const xdr = this.xdr;
  54. switch (op) {
  55. case 3:
  56. return msg.Nfsv4AccessRequest.decode(xdr);
  57. case 4:
  58. return msg.Nfsv4CloseRequest.decode(xdr);
  59. case 5:
  60. return msg.Nfsv4CommitRequest.decode(xdr);
  61. case 6:
  62. return this.decodeCreateRequest();
  63. case 7:
  64. return msg.Nfsv4DelegpurgeRequest.decode(xdr);
  65. case 8:
  66. return msg.Nfsv4DelegreturnRequest.decode(xdr);
  67. case 9:
  68. return this.decodeGetattrRequest();
  69. case 10:
  70. return this.decodeGetfhRequest();
  71. case 11:
  72. return this.decodeLinkRequest();
  73. case 12:
  74. return this.decodeLockRequest();
  75. case 13:
  76. return this.decodeLocktRequest();
  77. case 14:
  78. return this.decodeLockuRequest();
  79. case 15:
  80. return this.decodeLookupRequest();
  81. case 16:
  82. return this.decodeLookuppRequest();
  83. case 17:
  84. return this.decodeNverifyRequest();
  85. case 18:
  86. return this.decodeOpenRequest();
  87. case 19:
  88. return this.decodeOpenattrRequest();
  89. case 20:
  90. return this.decodeOpenConfirmRequest();
  91. case 21:
  92. return this.decodeOpenDowngradeRequest();
  93. case 22:
  94. return this.decodePutfhRequest();
  95. case 23:
  96. return new msg.Nfsv4PutpubfhRequest();
  97. case 24:
  98. return new msg.Nfsv4PutrootfhRequest();
  99. case 25:
  100. return this.decodeReadRequest();
  101. case 26:
  102. return this.decodeReaddirRequest();
  103. case 27:
  104. return this.decodeReadlinkRequest();
  105. case 28:
  106. return this.decodeRemoveRequest();
  107. case 29:
  108. return this.decodeRenameRequest();
  109. case 30:
  110. return this.decodeRenewRequest();
  111. case 31:
  112. return this.decodeRestorefhRequest();
  113. case 32:
  114. return new msg.Nfsv4SavefhRequest();
  115. case 33:
  116. return this.decodeSecinfoRequest();
  117. case 34:
  118. return this.decodeSetattrRequest();
  119. case 35:
  120. return this.decodeSetclientidRequest();
  121. case 36:
  122. return this.decodeSetclientidConfirmRequest();
  123. case 37:
  124. return this.decodeVerifyRequest();
  125. case 38:
  126. return this.decodeWriteRequest();
  127. case 39:
  128. return this.decodeReleaseLockOwnerRequest();
  129. case 10044:
  130. return this.decodeIllegalRequest();
  131. default:
  132. return this.decodeIllegalRequest();
  133. }
  134. }
  135. decodeResponse(op) {
  136. const xdr = this.xdr;
  137. switch (op) {
  138. case 3:
  139. return this.decodeAccessResponse();
  140. case 4:
  141. return this.decodeCloseResponse();
  142. case 5:
  143. return this.decodeCommitResponse();
  144. case 6:
  145. return this.decodeCreateResponse();
  146. case 7:
  147. return this.decodeDelegpurgeResponse();
  148. case 8:
  149. return this.decodeDelegreturnResponse();
  150. case 9:
  151. return this.decodeGetattrResponse();
  152. case 10:
  153. return this.decodeGetfhResponse();
  154. case 11:
  155. return this.decodeLinkResponse();
  156. case 12:
  157. return this.decodeLockResponse();
  158. case 13:
  159. return this.decodeLocktResponse();
  160. case 14:
  161. return this.decodeLockuResponse();
  162. case 15:
  163. return this.decodeLookupResponse();
  164. case 16:
  165. return this.decodeLookuppResponse();
  166. case 17:
  167. return this.decodeNverifyResponse();
  168. case 18:
  169. return this.decodeOpenResponse();
  170. case 19:
  171. return this.decodeOpenattrResponse();
  172. case 20:
  173. return this.decodeOpenConfirmResponse();
  174. case 21:
  175. return this.decodeOpenDowngradeResponse();
  176. case 22:
  177. return this.decodePutfhResponse();
  178. case 23:
  179. return msg.Nfsv4PutpubfhResponse.decode(xdr);
  180. case 24:
  181. return this.decodePutrootfhResponse();
  182. case 25:
  183. return this.decodeReadResponse();
  184. case 26:
  185. return this.decodeReaddirResponse();
  186. case 27:
  187. return this.decodeReadlinkResponse();
  188. case 28:
  189. return this.decodeRemoveResponse();
  190. case 29:
  191. return this.decodeRenameResponse();
  192. case 30:
  193. return this.decodeRenewResponse();
  194. case 31:
  195. return this.decodeRestorefhResponse();
  196. case 32:
  197. return this.decodeSavefhResponse();
  198. case 33:
  199. return this.decodeSecinfoResponse();
  200. case 34:
  201. return this.decodeSetattrResponse();
  202. case 35:
  203. return this.decodeSetclientidResponse();
  204. case 36:
  205. return this.decodeSetclientidConfirmResponse();
  206. case 37:
  207. return this.decodeVerifyResponse();
  208. case 38:
  209. return this.decodeWriteResponse();
  210. case 39:
  211. return this.decodeReleaseLockOwnerResponse();
  212. case 10044:
  213. return this.decodeIllegalResponse();
  214. default:
  215. return this.decodeIllegalResponse();
  216. }
  217. }
  218. readFh() {
  219. const data = this.xdr.readVarlenOpaque();
  220. return new structs.Nfsv4Fh(data);
  221. }
  222. readVerifier() {
  223. const data = this.xdr.readOpaque(8);
  224. return new structs.Nfsv4Verifier(data);
  225. }
  226. readStateid() {
  227. return structs.Nfsv4Stateid.decode(this.xdr);
  228. }
  229. readBitmap() {
  230. const xdr = this.xdr;
  231. const count = xdr.readUnsignedInt();
  232. if (count > 8)
  233. throw 10036;
  234. const mask = [];
  235. for (let i = 0; i < count; i++)
  236. mask.push(xdr.readUnsignedInt());
  237. return new structs.Nfsv4Bitmap(mask);
  238. }
  239. readFattr() {
  240. const attrmask = this.readBitmap();
  241. const attrVals = this.xdr.readVarlenOpaque();
  242. return new structs.Nfsv4Fattr(attrmask, attrVals);
  243. }
  244. readChangeInfo() {
  245. const xdr = this.xdr;
  246. const atomic = xdr.readBoolean();
  247. const before = xdr.readUnsignedHyper();
  248. const after = xdr.readUnsignedHyper();
  249. return new structs.Nfsv4ChangeInfo(atomic, before, after);
  250. }
  251. readClientAddr() {
  252. const xdr = this.xdr;
  253. const rNetid = xdr.readString();
  254. const rAddr = xdr.readString();
  255. return new structs.Nfsv4ClientAddr(rNetid, rAddr);
  256. }
  257. readCbClient() {
  258. const cbProgram = this.xdr.readUnsignedInt();
  259. const cbLocation = this.readClientAddr();
  260. return new structs.Nfsv4CbClient(cbProgram, cbLocation);
  261. }
  262. readClientId() {
  263. const verifier = this.readVerifier();
  264. const id = this.xdr.readVarlenOpaque();
  265. return new structs.Nfsv4ClientId(verifier, id);
  266. }
  267. readOpenOwner() {
  268. const xdr = this.xdr;
  269. const clientid = xdr.readUnsignedHyper();
  270. const owner = xdr.readVarlenOpaque();
  271. return new structs.Nfsv4OpenOwner(clientid, owner);
  272. }
  273. readLockOwner() {
  274. const xdr = this.xdr;
  275. const clientid = xdr.readUnsignedHyper();
  276. const owner = xdr.readVarlenOpaque();
  277. return new structs.Nfsv4LockOwner(clientid, owner);
  278. }
  279. readOpenToLockOwner() {
  280. const xdr = this.xdr;
  281. const openSeqid = xdr.readUnsignedInt();
  282. const openStateid = this.readStateid();
  283. const lockSeqid = xdr.readUnsignedInt();
  284. const lockOwner = this.readLockOwner();
  285. return new structs.Nfsv4OpenToLockOwner(openSeqid, openStateid, lockSeqid, lockOwner);
  286. }
  287. readLockOwnerInfo() {
  288. const xdr = this.xdr;
  289. const newLockOwner = xdr.readBoolean();
  290. if (newLockOwner) {
  291. const openToLockOwner = this.readOpenToLockOwner();
  292. return new structs.Nfsv4LockOwnerInfo(true, new structs.Nfsv4LockNewOwner(openToLockOwner));
  293. }
  294. else {
  295. const lockStateid = this.readStateid();
  296. const lockSeqid = xdr.readUnsignedInt();
  297. return new structs.Nfsv4LockOwnerInfo(false, new structs.Nfsv4LockExistingOwner(lockStateid, lockSeqid));
  298. }
  299. }
  300. readOpenClaim() {
  301. const xdr = this.xdr;
  302. const claimType = xdr.readUnsignedInt();
  303. switch (claimType) {
  304. case 0: {
  305. const file = xdr.readString();
  306. return new structs.Nfsv4OpenClaim(claimType, new structs.Nfsv4OpenClaimNull(file));
  307. }
  308. case 1: {
  309. const delegateType = xdr.readUnsignedInt();
  310. return new structs.Nfsv4OpenClaim(claimType, new structs.Nfsv4OpenClaimPrevious(delegateType));
  311. }
  312. case 2: {
  313. const delegateStateid = this.readStateid();
  314. const file = xdr.readString();
  315. return new structs.Nfsv4OpenClaim(claimType, new structs.Nfsv4OpenClaimDelegateCur(delegateStateid, file));
  316. }
  317. case 3: {
  318. const file = xdr.readString();
  319. return new structs.Nfsv4OpenClaim(claimType, new structs.Nfsv4OpenClaimDelegatePrev(file));
  320. }
  321. default:
  322. throw new errors_1.Nfsv4DecodingError(`Unknown open claim type: ${claimType}`);
  323. }
  324. }
  325. readOpenHow() {
  326. const xdr = this.xdr;
  327. const opentype = xdr.readUnsignedInt();
  328. if (opentype === 0)
  329. return new structs.Nfsv4OpenHow(opentype);
  330. const mode = xdr.readUnsignedInt();
  331. switch (mode) {
  332. case 0:
  333. case 1: {
  334. const createattrs = this.readFattr();
  335. return new structs.Nfsv4OpenHow(opentype, new structs.Nfsv4CreateHow(mode, new structs.Nfsv4CreateAttrs(createattrs)));
  336. }
  337. case 2: {
  338. const createverf = this.readVerifier();
  339. return new structs.Nfsv4OpenHow(opentype, new structs.Nfsv4CreateHow(mode, new structs.Nfsv4CreateVerf(createverf)));
  340. }
  341. default:
  342. throw new errors_1.Nfsv4DecodingError(`Unknown create mode: ${mode}`);
  343. }
  344. }
  345. readOpenDelegation() {
  346. const xdr = this.xdr;
  347. const delegationType = xdr.readUnsignedInt();
  348. switch (delegationType) {
  349. case 0:
  350. return new structs.Nfsv4OpenDelegation(delegationType);
  351. case 1: {
  352. const stateid = this.readStateid();
  353. const recall = xdr.readBoolean();
  354. const aceCount = xdr.readUnsignedInt();
  355. const permissions = [];
  356. for (let i = 0; i < aceCount; i++) {
  357. permissions.push(this.readAce());
  358. }
  359. return new structs.Nfsv4OpenDelegation(delegationType, new structs.Nfsv4OpenReadDelegation(stateid, recall, permissions));
  360. }
  361. case 2: {
  362. const stateid = this.readStateid();
  363. const recall = xdr.readBoolean();
  364. const spaceLimit = xdr.readUnsignedHyper();
  365. const aceCount = xdr.readUnsignedInt();
  366. const permissions = [];
  367. for (let i = 0; i < aceCount; i++) {
  368. permissions.push(this.readAce());
  369. }
  370. return new structs.Nfsv4OpenDelegation(delegationType, new structs.Nfsv4OpenWriteDelegation(stateid, recall, spaceLimit, permissions));
  371. }
  372. default:
  373. throw new errors_1.Nfsv4DecodingError(`Unknown delegation type: ${delegationType}`);
  374. }
  375. }
  376. readAce() {
  377. const xdr = this.xdr;
  378. const type = xdr.readUnsignedInt();
  379. const flag = xdr.readUnsignedInt();
  380. const accessMask = xdr.readUnsignedInt();
  381. const who = xdr.readString();
  382. return new structs.Nfsv4Ace(type, flag, accessMask, who);
  383. }
  384. readSecInfoFlavor() {
  385. const xdr = this.xdr;
  386. const flavor = xdr.readUnsignedInt();
  387. if (flavor === 6) {
  388. const oid = xdr.readVarlenOpaque();
  389. const qop = xdr.readUnsignedInt();
  390. const service = xdr.readUnsignedInt();
  391. const flavorInfo = new structs.Nfsv4RpcSecGssInfo(oid, qop, service);
  392. return new structs.Nfsv4SecInfoFlavor(flavor, flavorInfo);
  393. }
  394. return new structs.Nfsv4SecInfoFlavor(flavor);
  395. }
  396. decodeAccessResponse() {
  397. const xdr = this.xdr;
  398. const status = xdr.readUnsignedInt();
  399. if (status === 0) {
  400. const supported = xdr.readUnsignedInt();
  401. const access = xdr.readUnsignedInt();
  402. return new msg.Nfsv4AccessResponse(status, new msg.Nfsv4AccessResOk(supported, access));
  403. }
  404. return new msg.Nfsv4AccessResponse(status);
  405. }
  406. decodeCloseRequest() {
  407. const xdr = this.xdr;
  408. const seqid = xdr.readUnsignedInt();
  409. const openStateid = this.readStateid();
  410. return new msg.Nfsv4CloseRequest(seqid, openStateid);
  411. }
  412. decodeCloseResponse() {
  413. const status = this.xdr.readUnsignedInt();
  414. if (status === 0) {
  415. const openStateid = this.readStateid();
  416. return new msg.Nfsv4CloseResponse(status, new msg.Nfsv4CloseResOk(openStateid));
  417. }
  418. return new msg.Nfsv4CloseResponse(status);
  419. }
  420. decodeCommitResponse() {
  421. const status = this.xdr.readUnsignedInt();
  422. if (status === 0) {
  423. const writeverf = this.readVerifier();
  424. return new msg.Nfsv4CommitResponse(status, new msg.Nfsv4CommitResOk(writeverf));
  425. }
  426. return new msg.Nfsv4CommitResponse(status);
  427. }
  428. decodeCreateRequest() {
  429. const xdr = this.xdr;
  430. const type = xdr.readUnsignedInt();
  431. let objtype;
  432. switch (type) {
  433. case 5: {
  434. const linkdata = xdr.readString();
  435. objtype = new structs.Nfsv4CreateType(type, new structs.Nfsv4CreateTypeLink(linkdata));
  436. break;
  437. }
  438. case 3:
  439. case 4: {
  440. const specdata1 = xdr.readUnsignedInt();
  441. const specdata2 = xdr.readUnsignedInt();
  442. const devdata = new structs.Nfsv4SpecData(specdata1, specdata2);
  443. objtype = new structs.Nfsv4CreateType(type, new structs.Nfsv4CreateTypeDevice(devdata));
  444. break;
  445. }
  446. default: {
  447. objtype = new structs.Nfsv4CreateType(type, new structs.Nfsv4CreateTypeVoid());
  448. break;
  449. }
  450. }
  451. const objname = xdr.readString();
  452. const createattrs = this.readFattr();
  453. return new msg.Nfsv4CreateRequest(objtype, objname, createattrs);
  454. }
  455. decodeCreateResponse() {
  456. const status = this.xdr.readUnsignedInt();
  457. if (status === 0) {
  458. const cinfo = this.readChangeInfo();
  459. const attrset = this.readBitmap();
  460. return new msg.Nfsv4CreateResponse(status, new msg.Nfsv4CreateResOk(cinfo, attrset));
  461. }
  462. return new msg.Nfsv4CreateResponse(status);
  463. }
  464. decodeDelegpurgeResponse() {
  465. const status = this.xdr.readUnsignedInt();
  466. return new msg.Nfsv4DelegpurgeResponse(status);
  467. }
  468. decodeDelegreturnResponse() {
  469. const status = this.xdr.readUnsignedInt();
  470. return new msg.Nfsv4DelegreturnResponse(status);
  471. }
  472. decodeGetattrRequest() {
  473. const attrRequest = this.readBitmap();
  474. return new msg.Nfsv4GetattrRequest(attrRequest);
  475. }
  476. decodeGetattrResponse() {
  477. const status = this.xdr.readUnsignedInt();
  478. if (status === 0) {
  479. const objAttributes = this.readFattr();
  480. return new msg.Nfsv4GetattrResponse(status, new msg.Nfsv4GetattrResOk(objAttributes));
  481. }
  482. return new msg.Nfsv4GetattrResponse(status);
  483. }
  484. decodeGetfhRequest() {
  485. return new msg.Nfsv4GetfhRequest();
  486. }
  487. decodeGetfhResponse() {
  488. const status = this.xdr.readUnsignedInt();
  489. if (status === 0) {
  490. const object = this.readFh();
  491. return new msg.Nfsv4GetfhResponse(status, new msg.Nfsv4GetfhResOk(object));
  492. }
  493. return new msg.Nfsv4GetfhResponse(status);
  494. }
  495. decodeLinkRequest() {
  496. const newname = this.xdr.readString();
  497. return new msg.Nfsv4LinkRequest(newname);
  498. }
  499. decodeLinkResponse() {
  500. const status = this.xdr.readUnsignedInt();
  501. if (status === 0) {
  502. const cinfo = this.readChangeInfo();
  503. return new msg.Nfsv4LinkResponse(status, new msg.Nfsv4LinkResOk(cinfo));
  504. }
  505. return new msg.Nfsv4LinkResponse(status);
  506. }
  507. decodeLockRequest() {
  508. const xdr = this.xdr;
  509. const locktype = xdr.readUnsignedInt();
  510. const reclaim = xdr.readBoolean();
  511. const offset = xdr.readUnsignedHyper();
  512. const length = xdr.readUnsignedHyper();
  513. const locker = this.readLockOwnerInfo();
  514. return new msg.Nfsv4LockRequest(locktype, reclaim, offset, length, locker);
  515. }
  516. decodeLockResponse() {
  517. const xdr = this.xdr;
  518. const status = xdr.readUnsignedInt();
  519. if (status === 0) {
  520. const lockStateid = this.readStateid();
  521. return new msg.Nfsv4LockResponse(status, new msg.Nfsv4LockResOk(lockStateid));
  522. }
  523. else if (status === 10010) {
  524. const offset = xdr.readUnsignedHyper();
  525. const length = xdr.readUnsignedHyper();
  526. const locktype = xdr.readUnsignedInt();
  527. const owner = this.readLockOwner();
  528. return new msg.Nfsv4LockResponse(status, undefined, new msg.Nfsv4LockResDenied(offset, length, locktype, owner));
  529. }
  530. return new msg.Nfsv4LockResponse(status);
  531. }
  532. decodeLocktRequest() {
  533. const xdr = this.xdr;
  534. const locktype = xdr.readUnsignedInt();
  535. const offset = xdr.readUnsignedHyper();
  536. const length = xdr.readUnsignedHyper();
  537. const owner = this.readLockOwner();
  538. return new msg.Nfsv4LocktRequest(locktype, offset, length, owner);
  539. }
  540. decodeLocktResponse() {
  541. const xdr = this.xdr;
  542. const status = xdr.readUnsignedInt();
  543. if (status === 10010) {
  544. const offset = xdr.readUnsignedHyper();
  545. const length = xdr.readUnsignedHyper();
  546. const locktype = xdr.readUnsignedInt();
  547. const owner = this.readLockOwner();
  548. return new msg.Nfsv4LocktResponse(status, new msg.Nfsv4LocktResDenied(offset, length, locktype, owner));
  549. }
  550. return new msg.Nfsv4LocktResponse(status);
  551. }
  552. decodeLockuRequest() {
  553. const xdr = this.xdr;
  554. const locktype = xdr.readUnsignedInt();
  555. const seqid = xdr.readUnsignedInt();
  556. const lockStateid = this.readStateid();
  557. const offset = xdr.readUnsignedHyper();
  558. const length = xdr.readUnsignedHyper();
  559. return new msg.Nfsv4LockuRequest(locktype, seqid, lockStateid, offset, length);
  560. }
  561. decodeLockuResponse() {
  562. const status = this.xdr.readUnsignedInt();
  563. if (status === 0) {
  564. const lockStateid = this.readStateid();
  565. return new msg.Nfsv4LockuResponse(status, new msg.Nfsv4LockuResOk(lockStateid));
  566. }
  567. return new msg.Nfsv4LockuResponse(status);
  568. }
  569. decodeLookupRequest() {
  570. const objname = this.xdr.readString();
  571. return new msg.Nfsv4LookupRequest(objname);
  572. }
  573. decodeLookupResponse() {
  574. const status = this.xdr.readUnsignedInt();
  575. return new msg.Nfsv4LookupResponse(status);
  576. }
  577. decodeLookuppRequest() {
  578. return new msg.Nfsv4LookuppRequest();
  579. }
  580. decodeLookuppResponse() {
  581. const status = this.xdr.readUnsignedInt();
  582. return new msg.Nfsv4LookuppResponse(status);
  583. }
  584. decodeNverifyRequest() {
  585. const objAttributes = this.readFattr();
  586. return new msg.Nfsv4NverifyRequest(objAttributes);
  587. }
  588. decodeNverifyResponse() {
  589. const status = this.xdr.readUnsignedInt();
  590. return new msg.Nfsv4NverifyResponse(status);
  591. }
  592. decodeOpenRequest() {
  593. const xdr = this.xdr;
  594. const seqid = xdr.readUnsignedInt();
  595. const shareAccess = xdr.readUnsignedInt();
  596. const shareDeny = xdr.readUnsignedInt();
  597. const owner = this.readOpenOwner();
  598. const openhow = this.readOpenHow();
  599. const claim = this.readOpenClaim();
  600. return new msg.Nfsv4OpenRequest(seqid, shareAccess, shareDeny, owner, openhow, claim);
  601. }
  602. decodeOpenResponse() {
  603. const xdr = this.xdr;
  604. const status = xdr.readUnsignedInt();
  605. if (status === 0) {
  606. const stateid = this.readStateid();
  607. const cinfo = this.readChangeInfo();
  608. const rflags = xdr.readUnsignedInt();
  609. const attrset = this.readBitmap();
  610. const delegation = this.readOpenDelegation();
  611. return new msg.Nfsv4OpenResponse(status, new msg.Nfsv4OpenResOk(stateid, cinfo, rflags, attrset, delegation));
  612. }
  613. return new msg.Nfsv4OpenResponse(status);
  614. }
  615. decodeOpenattrRequest() {
  616. const createdir = this.xdr.readBoolean();
  617. return new msg.Nfsv4OpenattrRequest(createdir);
  618. }
  619. decodeOpenattrResponse() {
  620. const status = this.xdr.readUnsignedInt();
  621. return new msg.Nfsv4OpenattrResponse(status);
  622. }
  623. decodeOpenConfirmRequest() {
  624. const openStateid = this.readStateid();
  625. const seqid = this.xdr.readUnsignedInt();
  626. return new msg.Nfsv4OpenConfirmRequest(openStateid, seqid);
  627. }
  628. decodeOpenConfirmResponse() {
  629. const status = this.xdr.readUnsignedInt();
  630. if (status === 0) {
  631. const openStateid = this.readStateid();
  632. return new msg.Nfsv4OpenConfirmResponse(status, new msg.Nfsv4OpenConfirmResOk(openStateid));
  633. }
  634. return new msg.Nfsv4OpenConfirmResponse(status);
  635. }
  636. decodeOpenDowngradeRequest() {
  637. const xdr = this.xdr;
  638. const openStateid = this.readStateid();
  639. const seqid = xdr.readUnsignedInt();
  640. const shareAccess = xdr.readUnsignedInt();
  641. const shareDeny = xdr.readUnsignedInt();
  642. return new msg.Nfsv4OpenDowngradeRequest(openStateid, seqid, shareAccess, shareDeny);
  643. }
  644. decodeOpenDowngradeResponse() {
  645. const status = this.xdr.readUnsignedInt();
  646. if (status === 0) {
  647. const openStateid = this.readStateid();
  648. return new msg.Nfsv4OpenDowngradeResponse(status, new msg.Nfsv4OpenDowngradeResOk(openStateid));
  649. }
  650. return new msg.Nfsv4OpenDowngradeResponse(status);
  651. }
  652. decodePutfhRequest() {
  653. const object = this.readFh();
  654. return new msg.Nfsv4PutfhRequest(object);
  655. }
  656. decodePutfhResponse() {
  657. const status = this.xdr.readUnsignedInt();
  658. return new msg.Nfsv4PutfhResponse(status);
  659. }
  660. decodePutrootfhResponse() {
  661. const status = this.xdr.readUnsignedInt();
  662. return new msg.Nfsv4PutrootfhResponse(status);
  663. }
  664. decodeReadRequest() {
  665. const xdr = this.xdr;
  666. const stateid = this.readStateid();
  667. const offset = xdr.readUnsignedHyper();
  668. const count = xdr.readUnsignedInt();
  669. return new msg.Nfsv4ReadRequest(stateid, offset, count);
  670. }
  671. decodeReadResponse() {
  672. const xdr = this.xdr;
  673. const status = xdr.readUnsignedInt();
  674. if (status === 0) {
  675. const eof = xdr.readBoolean();
  676. const data = xdr.readVarlenOpaque();
  677. return new msg.Nfsv4ReadResponse(status, new msg.Nfsv4ReadResOk(eof, data));
  678. }
  679. return new msg.Nfsv4ReadResponse(status);
  680. }
  681. decodeReaddirRequest() {
  682. const xdr = this.xdr;
  683. const cookie = xdr.readUnsignedHyper();
  684. const cookieverf = this.readVerifier();
  685. const dircount = xdr.readUnsignedInt();
  686. const maxcount = xdr.readUnsignedInt();
  687. const attrRequest = this.readBitmap();
  688. return new msg.Nfsv4ReaddirRequest(cookie, cookieverf, dircount, maxcount, attrRequest);
  689. }
  690. decodeReaddirResponse() {
  691. const xdr = this.xdr;
  692. const status = xdr.readUnsignedInt();
  693. if (status === 0) {
  694. const cookieverf = this.readVerifier();
  695. const entries = [];
  696. while (xdr.readBoolean()) {
  697. const cookie = xdr.readUnsignedHyper();
  698. const name = xdr.readString();
  699. const attrs = this.readFattr();
  700. entries.push(new structs.Nfsv4Entry(cookie, name, attrs));
  701. }
  702. const eof = xdr.readBoolean();
  703. return new msg.Nfsv4ReaddirResponse(status, new msg.Nfsv4ReaddirResOk(cookieverf, entries, eof));
  704. }
  705. return new msg.Nfsv4ReaddirResponse(status);
  706. }
  707. decodeReadlinkRequest() {
  708. return new msg.Nfsv4ReadlinkRequest();
  709. }
  710. decodeReadlinkResponse() {
  711. const xdr = this.xdr;
  712. const status = xdr.readUnsignedInt();
  713. if (status === 0) {
  714. const link = xdr.readString();
  715. return new msg.Nfsv4ReadlinkResponse(status, new msg.Nfsv4ReadlinkResOk(link));
  716. }
  717. return new msg.Nfsv4ReadlinkResponse(status);
  718. }
  719. decodeRemoveRequest() {
  720. const target = this.xdr.readString();
  721. return new msg.Nfsv4RemoveRequest(target);
  722. }
  723. decodeRemoveResponse() {
  724. const status = this.xdr.readUnsignedInt();
  725. if (status === 0) {
  726. const cinfo = this.readChangeInfo();
  727. return new msg.Nfsv4RemoveResponse(status, new msg.Nfsv4RemoveResOk(cinfo));
  728. }
  729. return new msg.Nfsv4RemoveResponse(status);
  730. }
  731. decodeRenameRequest() {
  732. const xdr = this.xdr;
  733. const oldname = xdr.readString();
  734. const newname = xdr.readString();
  735. return new msg.Nfsv4RenameRequest(oldname, newname);
  736. }
  737. decodeRenameResponse() {
  738. const xdr = this.xdr;
  739. const status = xdr.readUnsignedInt();
  740. if (status === 0) {
  741. const sourceCinfo = this.readChangeInfo();
  742. const targetCinfo = this.readChangeInfo();
  743. return new msg.Nfsv4RenameResponse(status, new msg.Nfsv4RenameResOk(sourceCinfo, targetCinfo));
  744. }
  745. return new msg.Nfsv4RenameResponse(status);
  746. }
  747. decodeRenewRequest() {
  748. const clientid = this.xdr.readUnsignedHyper();
  749. return new msg.Nfsv4RenewRequest(clientid);
  750. }
  751. decodeRenewResponse() {
  752. const status = this.xdr.readUnsignedInt();
  753. return new msg.Nfsv4RenewResponse(status);
  754. }
  755. decodeRestorefhRequest() {
  756. return new msg.Nfsv4RestorefhRequest();
  757. }
  758. decodeRestorefhResponse() {
  759. const status = this.xdr.readUnsignedInt();
  760. return new msg.Nfsv4RestorefhResponse(status);
  761. }
  762. decodeSavefhRequest() {
  763. return new msg.Nfsv4SavefhRequest();
  764. }
  765. decodeSavefhResponse() {
  766. const status = this.xdr.readUnsignedInt();
  767. return new msg.Nfsv4SavefhResponse(status);
  768. }
  769. decodeSecinfoRequest() {
  770. const name = this.xdr.readString();
  771. return new msg.Nfsv4SecinfoRequest(name);
  772. }
  773. decodeSecinfoResponse() {
  774. const xdr = this.xdr;
  775. const status = xdr.readUnsignedInt();
  776. if (status === 0) {
  777. const count = xdr.readUnsignedInt();
  778. const flavors = [];
  779. for (let i = 0; i < count; i++)
  780. flavors.push(this.readSecInfoFlavor());
  781. return new msg.Nfsv4SecinfoResponse(status, new msg.Nfsv4SecinfoResOk(flavors));
  782. }
  783. return new msg.Nfsv4SecinfoResponse(status);
  784. }
  785. decodeSetattrRequest() {
  786. const stateid = this.readStateid();
  787. const objAttributes = this.readFattr();
  788. return new msg.Nfsv4SetattrRequest(stateid, objAttributes);
  789. }
  790. decodeSetattrResponse() {
  791. const status = this.xdr.readUnsignedInt();
  792. const attrset = this.readBitmap();
  793. return new msg.Nfsv4SetattrResponse(status, new msg.Nfsv4SetattrResOk(attrset));
  794. }
  795. decodeSetclientidRequest() {
  796. const client = this.readClientId();
  797. const callback = this.readCbClient();
  798. const callbackIdent = this.xdr.readUnsignedInt();
  799. return new msg.Nfsv4SetclientidRequest(client, callback, callbackIdent);
  800. }
  801. decodeSetclientidResponse() {
  802. const xdr = this.xdr;
  803. const status = xdr.readUnsignedInt();
  804. if (status === 0) {
  805. const clientid = xdr.readUnsignedHyper();
  806. const setclientidConfirm = this.readVerifier();
  807. return new msg.Nfsv4SetclientidResponse(status, new msg.Nfsv4SetclientidResOk(clientid, setclientidConfirm));
  808. }
  809. return new msg.Nfsv4SetclientidResponse(status);
  810. }
  811. decodeSetclientidConfirmRequest() {
  812. const clientid = this.xdr.readUnsignedHyper();
  813. const setclientidConfirm = this.readVerifier();
  814. return new msg.Nfsv4SetclientidConfirmRequest(clientid, setclientidConfirm);
  815. }
  816. decodeSetclientidConfirmResponse() {
  817. const status = this.xdr.readUnsignedInt();
  818. return new msg.Nfsv4SetclientidConfirmResponse(status);
  819. }
  820. decodeVerifyRequest() {
  821. const objAttributes = this.readFattr();
  822. return new msg.Nfsv4VerifyRequest(objAttributes);
  823. }
  824. decodeVerifyResponse() {
  825. const status = this.xdr.readUnsignedInt();
  826. return new msg.Nfsv4VerifyResponse(status);
  827. }
  828. decodeWriteRequest() {
  829. const xdr = this.xdr;
  830. const stateid = this.readStateid();
  831. const offset = xdr.readUnsignedHyper();
  832. const stable = xdr.readUnsignedInt();
  833. const data = xdr.readVarlenOpaque();
  834. return new msg.Nfsv4WriteRequest(stateid, offset, stable, data);
  835. }
  836. decodeWriteResponse() {
  837. const xdr = this.xdr;
  838. const status = xdr.readUnsignedInt();
  839. if (status === 0) {
  840. const count = xdr.readUnsignedInt();
  841. const committed = xdr.readUnsignedInt();
  842. const writeverf = this.readVerifier();
  843. return new msg.Nfsv4WriteResponse(status, new msg.Nfsv4WriteResOk(count, committed, writeverf));
  844. }
  845. return new msg.Nfsv4WriteResponse(status);
  846. }
  847. decodeReleaseLockOwnerRequest() {
  848. const lockOwner = this.readLockOwner();
  849. return new msg.Nfsv4ReleaseLockOwnerRequest(lockOwner);
  850. }
  851. decodeReleaseLockOwnerResponse() {
  852. const status = this.xdr.readUnsignedInt();
  853. return new msg.Nfsv4ReleaseLockOwnerResponse(status);
  854. }
  855. decodeIllegalRequest() {
  856. return new msg.Nfsv4IllegalRequest();
  857. }
  858. decodeIllegalResponse() {
  859. const status = this.xdr.readUnsignedInt();
  860. return new msg.Nfsv4IllegalResponse(status);
  861. }
  862. decodeCbCompound(reader, isRequest) {
  863. this.xdr.reader = reader;
  864. const startPos = reader.x;
  865. try {
  866. if (isRequest) {
  867. return this.decodeCbCompoundRequest();
  868. }
  869. else {
  870. return this.decodeCbCompoundResponse();
  871. }
  872. }
  873. catch (err) {
  874. if (err instanceof RangeError) {
  875. reader.x = startPos;
  876. return undefined;
  877. }
  878. throw err;
  879. }
  880. }
  881. decodeCbCompoundRequest() {
  882. const xdr = this.xdr;
  883. const tag = xdr.readString();
  884. const minorversion = xdr.readUnsignedInt();
  885. const callbackIdent = xdr.readUnsignedInt();
  886. const argarray = [];
  887. const count = xdr.readUnsignedInt();
  888. for (let i = 0; i < count; i++) {
  889. const op = xdr.readUnsignedInt();
  890. const request = this.decodeCbRequest(op);
  891. if (request)
  892. argarray.push(request);
  893. }
  894. return new msg.Nfsv4CbCompoundRequest(tag, minorversion, callbackIdent, argarray);
  895. }
  896. decodeCbCompoundResponse() {
  897. const xdr = this.xdr;
  898. const status = xdr.readUnsignedInt();
  899. const tag = xdr.readString();
  900. const resarray = [];
  901. const count = xdr.readUnsignedInt();
  902. for (let i = 0; i < count; i++) {
  903. const op = xdr.readUnsignedInt();
  904. const response = this.decodeCbResponse(op);
  905. if (response)
  906. resarray.push(response);
  907. }
  908. return new msg.Nfsv4CbCompoundResponse(status, tag, resarray);
  909. }
  910. decodeCbRequest(op) {
  911. switch (op) {
  912. case 3:
  913. return this.decodeCbGetattrRequest();
  914. case 4:
  915. return this.decodeCbRecallRequest();
  916. case 10044:
  917. return this.decodeCbIllegalRequest();
  918. default:
  919. throw new errors_1.Nfsv4DecodingError(`Unknown callback operation: ${op}`);
  920. }
  921. }
  922. decodeCbResponse(op) {
  923. switch (op) {
  924. case 3:
  925. return this.decodeCbGetattrResponse();
  926. case 4:
  927. return this.decodeCbRecallResponse();
  928. case 10044:
  929. return this.decodeCbIllegalResponse();
  930. default:
  931. throw new errors_1.Nfsv4DecodingError(`Unknown callback operation: ${op}`);
  932. }
  933. }
  934. decodeCbGetattrRequest() {
  935. const fh = this.readFh();
  936. const attrRequest = this.readBitmap();
  937. return new msg.Nfsv4CbGetattrRequest(fh, attrRequest);
  938. }
  939. decodeCbGetattrResponse() {
  940. const status = this.xdr.readUnsignedInt();
  941. if (status === 0) {
  942. const objAttributes = this.readFattr();
  943. return new msg.Nfsv4CbGetattrResponse(status, new msg.Nfsv4CbGetattrResOk(objAttributes));
  944. }
  945. return new msg.Nfsv4CbGetattrResponse(status);
  946. }
  947. decodeCbRecallRequest() {
  948. const stateid = this.readStateid();
  949. const truncate = this.xdr.readBoolean();
  950. const fh = this.readFh();
  951. return new msg.Nfsv4CbRecallRequest(stateid, truncate, fh);
  952. }
  953. decodeCbRecallResponse() {
  954. const status = this.xdr.readUnsignedInt();
  955. return new msg.Nfsv4CbRecallResponse(status);
  956. }
  957. decodeCbIllegalRequest() {
  958. return new msg.Nfsv4CbIllegalRequest();
  959. }
  960. decodeCbIllegalResponse() {
  961. const status = this.xdr.readUnsignedInt();
  962. return new msg.Nfsv4CbIllegalResponse(status);
  963. }
  964. }
  965. exports.Nfsv4Decoder = Nfsv4Decoder;
  966. //# sourceMappingURL=Nfsv4Decoder.js.map