Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | 26x 26x 26x 26x 422x 137x 84x 150x 1x 49x 15x 15x 15x 5x 30x 30x 62x 3x 19x 4x 4x 20x 1x 63x 3x 3x 26x 16x 217x 108x 3x 5x 2x 104x 22x 12x 3x 67x 90x 90x 1x 1x 1x 2x 3x 14x 213x 214x 181x 36x 36x 36x 102x 85x 85x 19x 19x 5x | import {attrNumsToBitmap} from './attributes';
import * as msg from './messages';
import * as structs from './structs';
import {Nfsv4CreateMode, Nfsv4FType, type Nfsv4LockType, Nfsv4OpenFlags} from './constants';
/**
* Static builder helpers for NFS v4 operations.
* Provides a simpler API for constructing NFS v4 request messages.
*
* @example
* ```ts
* const response = await client.compound([
* nfs.PUTROOTFH(),
* nfs.LOOKUP('file.txt'),
* nfs.GETATTR([0x00000001]),
* ]);
* ```
*/
export const nfs = {
/**
* PUTROOTFH - Set current filehandle to root of export.
*/
PUTROOTFH(): msg.Nfsv4PutrootfhRequest {
return new msg.Nfsv4PutrootfhRequest();
},
/**
* PUTFH - Set current filehandle.
* @param fh - Filehandle to set as current
*/
PUTFH(fh: structs.Nfsv4Fh): msg.Nfsv4PutfhRequest {
return new msg.Nfsv4PutfhRequest(fh);
},
/**
* PUTPUBFH - Set current filehandle to public filehandle.
*/
PUTPUBFH(): msg.Nfsv4PutpubfhRequest {
return new msg.Nfsv4PutpubfhRequest();
},
/**
* GETFH - Get current filehandle.
*/
GETFH(): msg.Nfsv4GetfhRequest {
return new msg.Nfsv4GetfhRequest();
},
/**
* LOOKUP - Lookup filename in current directory.
* @param name - Filename to lookup
*/
LOOKUP(name: string): msg.Nfsv4LookupRequest {
return new msg.Nfsv4LookupRequest(name);
},
/**
* LOOKUPP - Lookup parent directory (..).
*/
LOOKUPP(): msg.Nfsv4LookuppRequest {
return new msg.Nfsv4LookuppRequest();
},
/**
* GETATTR - Get file attributes.
* @param attrBitmap - Attribute bitmap (array of uint32 values)
*/
GETATTR(attrBitmap: number[]): msg.Nfsv4GetattrRequest {
return new msg.Nfsv4GetattrRequest(new structs.Nfsv4Bitmap(attrBitmap));
},
/**
* READDIR - Read directory entries.
* @param attrBitmap - Attribute bitmap for entries (single uint32 or array)
* @param cookieverf - Cookie verifier (8 bytes), defaults to zeros
* @param cookie - Starting cookie, defaults to 0
* @param dircount - Max bytes for directory info, defaults to 1000
* @param maxcount - Max bytes for reply, defaults to 8192
*/
READDIR(
attrBitmap: number | number[],
cookieverf?: Uint8Array,
cookie?: bigint,
dircount?: number,
maxcount?: number,
): msg.Nfsv4ReaddirRequest {
const bitmap = Array.isArray(attrBitmap) ? attrBitmap : [attrBitmap];
const verifier = cookieverf || new Uint8Array(8);
return new msg.Nfsv4ReaddirRequest(
cookie ?? BigInt(0),
new structs.Nfsv4Verifier(verifier),
dircount ?? 1000,
maxcount ?? 8192,
new structs.Nfsv4Bitmap(bitmap),
);
},
/**
* ACCESS - Check access permissions.
* @param accessMask - Access mask (default: 0x3f for all bits)
*/
ACCESS(accessMask: number = 0x0000003f): msg.Nfsv4AccessRequest {
return new msg.Nfsv4AccessRequest(accessMask);
},
/**
* READ - Read file data.
* @param offset - Byte offset to read from
* @param count - Number of bytes to read
* @param stateid - State ID (defaults to all zeros)
*/
READ(offset: bigint, count: number, stateid?: structs.Nfsv4Stateid): msg.Nfsv4ReadRequest {
const sid = stateid || new structs.Nfsv4Stateid(0, new Uint8Array(12));
return new msg.Nfsv4ReadRequest(sid, offset, count);
},
/**
* WRITE - Write file data.
* @param stateid - State ID to write to
* @param offset - Byte offset
* @param stable - Stable flag (Nfsv4StableHow)
* @param data - Data to write
*/
WRITE(stateid: structs.Nfsv4Stateid, offset: bigint, stable: number, data: Uint8Array): msg.Nfsv4WriteRequest {
return new msg.Nfsv4WriteRequest(stateid, offset, stable, data);
},
/**
* COMMIT - Commit written data to stable storage.
* @param offset - Byte offset
* @param count - Number of bytes
*/
COMMIT(offset: bigint, count: number): msg.Nfsv4CommitRequest {
return new msg.Nfsv4CommitRequest(offset, count);
},
/**
* CREATE - Create a new file.
* @param objtype - Object type to create
* @param objname - Name of object to create
* @param createattrs - Attributes for the new object
*/
CREATE(objtype: structs.Nfsv4CreateType, objname: string, createattrs: structs.Nfsv4Fattr): msg.Nfsv4CreateRequest {
return new msg.Nfsv4CreateRequest(objtype, objname, createattrs);
},
/**
* LINK - Create a hard link.
* @param newname - Name for the new link
*/
LINK(newname: string): msg.Nfsv4LinkRequest {
return new msg.Nfsv4LinkRequest(newname);
},
/**
* READLINK - Read symbolic link.
*/
READLINK(): msg.Nfsv4ReadlinkRequest {
return new msg.Nfsv4ReadlinkRequest();
},
/**
* SAVEFH - Save current filehandle.
*/
SAVEFH(): msg.Nfsv4SavefhRequest {
return new msg.Nfsv4SavefhRequest();
},
/**
* RESTOREFH - Restore saved filehandle to current.
*/
RESTOREFH(): msg.Nfsv4RestorefhRequest {
return new msg.Nfsv4RestorefhRequest();
},
/**
* SETATTR - Set file attributes.
* @param stateid - State ID
* @param attrs - Attributes to set
*/
SETATTR(stateid: structs.Nfsv4Stateid, attrs: structs.Nfsv4Fattr): msg.Nfsv4SetattrRequest {
return new msg.Nfsv4SetattrRequest(stateid, attrs);
},
/**
* VERIFY - Verify attributes match.
* @param attrs - Attributes to verify
*/
VERIFY(attrs: structs.Nfsv4Fattr): msg.Nfsv4VerifyRequest {
return new msg.Nfsv4VerifyRequest(attrs);
},
/**
* NVERIFY - Verify attributes don't match.
* @param attrs - Attributes to verify don't match
*/
NVERIFY(attrs: structs.Nfsv4Fattr): msg.Nfsv4NverifyRequest {
return new msg.Nfsv4NverifyRequest(attrs);
},
/**
* REMOVE - Remove file or directory.
* @param name - Name of file/directory to remove
*/
REMOVE(name: string): msg.Nfsv4RemoveRequest {
return new msg.Nfsv4RemoveRequest(name);
},
/**
* RENAME - Rename file or directory.
* @param oldname - Current name
* @param newname - New name
*/
RENAME(oldname: string, newname: string): msg.Nfsv4RenameRequest {
return new msg.Nfsv4RenameRequest(oldname, newname);
},
/**
* RENEW - Renew client lease.
* @param clientid - Client ID
*/
RENEW(clientid: bigint): msg.Nfsv4RenewRequest {
return new msg.Nfsv4RenewRequest(clientid);
},
/**
* SETCLIENTID - Establish client ID.
* @param client - Client identifier
* @param callback - Callback info
* @param callbackIdent - Callback identifier
*/
SETCLIENTID(
client: structs.Nfsv4ClientId,
callback: structs.Nfsv4CbClient,
callbackIdent: number,
): msg.Nfsv4SetclientidRequest {
return new msg.Nfsv4SetclientidRequest(client, callback, callbackIdent);
},
/**
* SETCLIENTID_CONFIRM - Confirm client ID.
* @param clientid - Client ID to confirm
* @param verifier - Verifier from SETCLIENTID response
*/
SETCLIENTID_CONFIRM(clientid: bigint, verifier: structs.Nfsv4Verifier): msg.Nfsv4SetclientidConfirmRequest {
return new msg.Nfsv4SetclientidConfirmRequest(clientid, verifier);
},
/**
* OPEN - Open a file.
* @param seqid - Sequence ID for open-owner
* @param shareAccess - Share access mode (OPEN4_SHARE_ACCESS_*)
* @param shareDeny - Share deny mode (OPEN4_SHARE_DENY_*)
* @param owner - Open owner (clientid + owner bytes)
* @param openhow - Open how structure (use OpenHow helper)
* @param claim - Open claim (use OpenClaim helper)
*/
OPEN(
seqid: number,
shareAccess: number,
shareDeny: number,
owner: structs.Nfsv4OpenOwner,
openhow: structs.Nfsv4OpenHow,
claim: structs.Nfsv4OpenClaim,
): msg.Nfsv4OpenRequest {
return new msg.Nfsv4OpenRequest(seqid, shareAccess, shareDeny, owner, openhow, claim);
},
/**
* CLOSE - Close an open file.
* @param seqid - Sequence ID
* @param openStateid - State ID from OPEN
*/
CLOSE(seqid: number, openStateid: structs.Nfsv4Stateid): msg.Nfsv4CloseRequest {
return new msg.Nfsv4CloseRequest(seqid, openStateid);
},
/**
* OPEN_CONFIRM - Confirm an open.
* @param openStateid - State ID from OPEN
* @param seqid - Sequence ID
*/
OPEN_CONFIRM(openStateid: structs.Nfsv4Stateid, seqid: number): msg.Nfsv4OpenConfirmRequest {
return new msg.Nfsv4OpenConfirmRequest(openStateid, seqid);
},
/**
* OPEN_DOWNGRADE - Downgrade open access/deny modes.
* @param openStateid - State ID from OPEN
* @param seqid - Sequence ID
* @param shareAccess - New share access mode
* @param shareDeny - New share deny mode
*/
OPEN_DOWNGRADE(
openStateid: structs.Nfsv4Stateid,
seqid: number,
shareAccess: number,
shareDeny: number,
): msg.Nfsv4OpenDowngradeRequest {
return new msg.Nfsv4OpenDowngradeRequest(openStateid, seqid, shareAccess, shareDeny);
},
/**
* OPENATTR - Open named attribute directory.
* @param createdir - Whether to create the directory if it doesn't exist
*/
OPENATTR(createdir: boolean = false): msg.Nfsv4OpenattrRequest {
return new msg.Nfsv4OpenattrRequest(createdir);
},
/**
* SECINFO - Get security information for a file.
* @param name - Filename to get security info for
*/
SECINFO(name: string): msg.Nfsv4SecinfoRequest {
return new msg.Nfsv4SecinfoRequest(name);
},
/**
* DELEGPURGE - Purge delegations (not supported).
* @param clientid - Client ID
*/
DELEGPURGE(clientid: bigint): msg.Nfsv4DelegpurgeRequest {
return new msg.Nfsv4DelegpurgeRequest(clientid);
},
/**
* DELEGRETURN - Return delegation (not supported).
* @param stateid - Delegation stateid
*/
DELEGRETURN(stateid: structs.Nfsv4Stateid): msg.Nfsv4DelegreturnRequest {
return new msg.Nfsv4DelegreturnRequest(stateid);
},
/**
* LOCK - Lock byte range.
* @param locktype - Lock type (READ_LT, WRITE_LT, READW_LT, or WRITEW_LT)
* @param reclaim - True if reclaiming lock after server restart
* @param offset - Starting byte offset
* @param length - Length in bytes (0xFFFFFFFFFFFFFFFF for EOF)
* @param locker - Lock owner info (new or existing lock owner)
*/
LOCK(
locktype: Nfsv4LockType,
reclaim: boolean,
offset: bigint,
length: bigint,
locker: structs.Nfsv4LockOwnerInfo,
): msg.Nfsv4LockRequest {
return new msg.Nfsv4LockRequest(locktype, reclaim, offset, length, locker);
},
/**
* LOCKT - Test for conflicting lock (non-blocking).
* @param locktype - Lock type (READ_LT or WRITE_LT)
* @param offset - Starting byte offset
* @param length - Length in bytes (0xFFFFFFFFFFFFFFFF for EOF)
* @param owner - Lock owner
*/
LOCKT(locktype: number, offset: bigint, length: bigint, owner: structs.Nfsv4LockOwner): msg.Nfsv4LocktRequest {
return new msg.Nfsv4LocktRequest(locktype, offset, length, owner);
},
/**
* LOCKU - Unlock byte range.
* @param locktype - Lock type (READ_LT or WRITE_LT)
* @param seqid - Sequence number
* @param lockStateid - Lock stateid from LOCK operation
* @param offset - Starting byte offset
* @param length - Length in bytes
*/
LOCKU(
locktype: number,
seqid: number,
lockStateid: structs.Nfsv4Stateid,
offset: bigint,
length: bigint,
): msg.Nfsv4LockuRequest {
return new msg.Nfsv4LockuRequest(locktype, seqid, lockStateid, offset, length);
},
/**
* RELEASE_LOCKOWNER - Release all locks for a lock-owner.
* @param lockOwner - Lock owner to release
*/
RELEASE_LOCKOWNER(lockOwner: structs.Nfsv4LockOwner): msg.Nfsv4ReleaseLockOwnerRequest {
return new msg.Nfsv4ReleaseLockOwnerRequest(lockOwner);
},
/**
* Create an Nfsv4Verifier (8-byte opaque data).
* @param data - 8-byte Uint8Array, defaults to zeros
*/
Verifier(data?: Uint8Array): structs.Nfsv4Verifier {
return new structs.Nfsv4Verifier(data || new Uint8Array(8));
},
/**
* Create an Nfsv4Stateid (state identifier).
* @param seqid - Sequence ID (default: 0)
* @param other - 12-byte opaque data (default: zeros)
*/
Stateid(seqid: number = 0, other?: Uint8Array): structs.Nfsv4Stateid {
return new structs.Nfsv4Stateid(seqid, other || new Uint8Array(12));
},
/**
* Create Nfsv4Fattr from attribute numbers (automatically converts to bitmap).
* @param attrNums - Array of attribute numbers (Nfsv4Attr enum values)
* @param attrVals - Encoded attribute values as byte array
*/
Fattr(attrNums: number[], attrVals: Uint8Array): structs.Nfsv4Fattr {
const bitmap = new structs.Nfsv4Bitmap(attrNumsToBitmap(attrNums));
return new structs.Nfsv4Fattr(bitmap, attrVals);
},
/**
* Create Nfsv4ClientId (client identifier).
* @param verifier - 8-byte verifier
* @param id - Variable-length client ID bytes
*/
ClientId(verifier: structs.Nfsv4Verifier, id: Uint8Array): structs.Nfsv4ClientId {
return new structs.Nfsv4ClientId(verifier, id);
},
/**
* Create Nfsv4CbClient (callback client information).
* @param cbProgram - Callback program number
* @param rNetid - Network ID string (e.g., 'tcp', 'udp')
* @param rAddr - Network address string (e.g., '127.0.0.1.8.1')
*/
CbClient(cbProgram: number, rNetid: string, rAddr: string): structs.Nfsv4CbClient {
const cbLocation = new structs.Nfsv4ClientAddr(rNetid, rAddr);
return new structs.Nfsv4CbClient(cbProgram, cbLocation);
},
/**
* Create Nfsv4Bitmap from attribute numbers.
* @param attrNums - Array of attribute numbers (Nfsv4Attr enum values)
*/
Bitmap(attrNums: number[]): structs.Nfsv4Bitmap {
return new structs.Nfsv4Bitmap(attrNumsToBitmap(attrNums));
},
/**
* Create Nfsv4CreateType for regular file creation.
*/
CreateTypeFile(): structs.Nfsv4CreateType {
return new structs.Nfsv4CreateType(Nfsv4FType.NF4REG, new structs.Nfsv4CreateTypeVoid());
},
/**
* Create Nfsv4CreateType for directory creation.
*/
CreateTypeDir(): structs.Nfsv4CreateType {
return new structs.Nfsv4CreateType(Nfsv4FType.NF4DIR, new structs.Nfsv4CreateTypeVoid());
},
/**
* Create Nfsv4OpenOwner (open owner identifier).
* @param clientid - Client ID
* @param owner - Owner bytes (unique identifier)
*/
OpenOwner(clientid: bigint, owner: Uint8Array): structs.Nfsv4OpenOwner {
return new structs.Nfsv4OpenOwner(clientid, owner);
},
/**
* Create Nfsv4OpenClaim for CLAIM_NULL (open by filename).
* @param filename - Name of file to open
*/
OpenClaimNull(filename: string): structs.Nfsv4OpenClaim {
return new structs.Nfsv4OpenClaim(0, new structs.Nfsv4OpenClaimNull(filename));
},
/**
* Create Nfsv4OpenHow for OPEN4_NOCREATE (open existing file).
*/
OpenHowNoCreate(): structs.Nfsv4OpenHow {
return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_NOCREATE);
},
/**
* Create Nfsv4OpenHow for OPEN4_CREATE with UNCHECKED4 mode.
* @param createattrs - Optional file attributes to set on create
*/
OpenHowCreateUnchecked(createattrs?: structs.Nfsv4Fattr): structs.Nfsv4OpenHow {
const attrs = createattrs || new structs.Nfsv4Fattr(new structs.Nfsv4Bitmap([]), new Uint8Array(0));
const how = new structs.Nfsv4CreateHow(Nfsv4CreateMode.UNCHECKED4, new structs.Nfsv4CreateAttrs(attrs));
return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_CREATE, how);
},
/**
* Create Nfsv4OpenHow for OPEN4_CREATE with GUARDED4 mode.
* @param createattrs - Optional file attributes to set on create
*/
OpenHowCreateGuarded(createattrs?: structs.Nfsv4Fattr): structs.Nfsv4OpenHow {
const attrs = createattrs || new structs.Nfsv4Fattr(new structs.Nfsv4Bitmap([]), new Uint8Array(0));
const how = new structs.Nfsv4CreateHow(Nfsv4CreateMode.GUARDED4, new structs.Nfsv4CreateAttrs(attrs));
return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_CREATE, how);
},
/**
* Create Nfsv4OpenHow for OPEN4_CREATE with EXCLUSIVE4 mode.
* @param verifier - 8-byte verifier for exclusive create
*/
OpenHowCreateExclusive(verifier: structs.Nfsv4Verifier): structs.Nfsv4OpenHow {
const how = new structs.Nfsv4CreateHow(Nfsv4CreateMode.EXCLUSIVE4, new structs.Nfsv4CreateVerf(verifier));
return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_CREATE, how);
},
/**
* Create Nfsv4LockOwner (lock owner identifier).
* @param clientid - Client ID
* @param owner - Owner bytes (unique identifier)
*/
LockOwner(clientid: bigint, owner: Uint8Array): structs.Nfsv4LockOwner {
return new structs.Nfsv4LockOwner(clientid, owner);
},
/**
* Create Nfsv4LockOwnerInfo for new lock owner (open_to_lock_owner).
* @param openSeqid - Current open-owner seqid
* @param openStateid - Open stateid from OPEN operation
* @param lockSeqid - Initial lock-owner seqid (typically 0)
* @param lockOwner - Lock owner identifier
*/
NewLockOwner(
openSeqid: number,
openStateid: structs.Nfsv4Stateid,
lockSeqid: number,
lockOwner: structs.Nfsv4LockOwner,
): structs.Nfsv4LockOwnerInfo {
const openToLockOwner = new structs.Nfsv4OpenToLockOwner(openSeqid, openStateid, lockSeqid, lockOwner);
return new structs.Nfsv4LockOwnerInfo(true, new structs.Nfsv4LockNewOwner(openToLockOwner));
},
/**
* Create Nfsv4LockOwnerInfo for existing lock owner.
* @param lockStateid - Lock stateid from previous LOCK operation
* @param lockSeqid - Lock-owner seqid
*/
ExistingLockOwner(lockStateid: structs.Nfsv4Stateid, lockSeqid: number): structs.Nfsv4LockOwnerInfo {
const owner = new structs.Nfsv4LockExistingOwner(lockStateid, lockSeqid);
return new structs.Nfsv4LockOwnerInfo(false, owner);
},
/**
* ILLEGAL - Illegal operation (for testing RFC 7530 ยง15.2.4 compliance).
* This operation is used to test server handling of illegal operation codes.
* Per RFC 7530, the server should respond with NFS4ERR_OP_ILLEGAL.
*/
ILLEGAL(): msg.Nfsv4IllegalRequest {
return new msg.Nfsv4IllegalRequest();
},
};
|