All files / json-pack/src/nfs/v4/server/operations LockStateid.ts

100% Statements 9/9
50% Branches 1/2
100% Functions 3/3
100% Lines 9/9

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 5526x                 26x             73x             73x           73x           73x             100x               100x 100x      
import * as struct from '../../structs';
 
/**
 * Lock stateid record for NFSv4 lock operations.
 * Per RFC 7530 ยง9.1.4.1, all locks held on a particular file by a particular
 * owner share a single stateid, with the seqid incremented on each LOCK/LOCKU.
 * The stateid remains valid even after all locks are freed, as long as the
 * associated open file remains open.
 */
export class LockStateid {
  constructor(
    /**
     * The "other" field of the stateid (96 bits).
     * Uniquely identifies this lock-owner+file combination.
     * Remains constant across all LOCK/LOCKU operations.
     */
    public readonly other: Uint8Array,
 
    /**
     * Current seqid value for this lock stateid.
     * Incremented on each LOCK or LOCKU operation that affects locks.
     * Starts at 1 when first created.
     */
    public seqid: number,
 
    /**
     * Key identifying the lock-owner that owns this stateid.
     * Format: `${clientid}:${hex(owner)}`.
     */
    public readonly lockOwnerKey: string,
 
    /**
     * Absolute file system path of the file this stateid applies to.
     * A lock-owner can have different stateids for different files.
     */
    public readonly path: string,
  ) {}
 
  /**
   * Get the full stateid with current seqid.
   */
  toStateid(): struct.Nfsv4Stateid {
    return new struct.Nfsv4Stateid(this.seqid, this.other);
  }
 
  /**
   * Increment seqid and return new stateid.
   * Per RFC 7530, seqid wraps from 0xFFFFFFFF to 1 (not 0).
   */
  incrementAndGetStateid(): struct.Nfsv4Stateid {
    this.seqid = this.seqid === 0xffffffff ? 1 : this.seqid + 1;
    return this.toStateid();
  }
}