//#region src/holders.d.ts /** One lock /proc/locks lists on a file. */ export interface LockRow { /** FLOCK, POSIX or OFDLCK, as the kernel prints it. */ readonly type: string; /** READ or WRITE. */ readonly mode: string; /** The holder's pid; -1 for an open-file-description lock, which no one process owns. */ readonly pid: number; /** The holder is the process that asked. */ readonly self: boolean; /** Byte range, "start-end" ("0-EOF" for a whole-file lock). */ readonly range: string; /** The kernel has queued this request behind a conflicting lock (a "->" row): the pid waits, it does not hold. */ readonly waiter: boolean; /** The pid's command line, or why it could not be read. */ readonly command: string; } /** One file's answer: absent, unreadable with the reason, or its device:inode and every lock on it. */ export type FileLocks = { readonly path: string; readonly absent: true; } | { readonly path: string; readonly unreadable: string; } | { readonly path: string; readonly id: string; readonly locks: readonly LockRow[]; }; /** Every watched file's locks, or why this host cannot say. */ export type LockHolders = { readonly kind: "read"; readonly files: readonly FileLocks[]; } | { readonly kind: "unknown"; readonly reason: string; }; /** How the reader reaches the kernel; `fileLockHolders` passes node:fs, a test passes fixture text. */ export interface LockHoldersIo { /** A file's text; throws with the reason when it cannot be read. */ readonly read: (path: string) => string; /** A file's device and inode; null when it does not exist, throws with the reason for anything else. */ readonly stat: (path: string) => { readonly dev: number; readonly ino: number; } | null; } /** * The `major:minor` a `/proc/locks` line prints for a file on the device `st_dev` (fs/locks.c: `%02x:%02x`, * lowercase hex). Linux encodes a 12-bit major and a 20-bit minor into 32 bits: minor bits 0-7, major bits 8-19, * minor bits 20-31. This is the low half of the layout glibc's `gnu_dev_major`/`gnu_dev_minor` decode; the upper 32 * bits are always zero on Linux, so no high term is read. It references nothing outside itself. */ export declare function procLocksDeviceId(dev: number): string; /** * Every lock on each of `paths`, from `/locks` read through `io`. It references nothing outside itself except * `procLocksDeviceId`, so an embedding worker includes both. */ export declare function readLockHolders(paths: readonly string[], options: { readonly self: number; readonly io: LockHoldersIo; readonly root?: string; }): LockHolders; /** * One line of text for a report, as a stall line prints it: each file by its base name, its locks (the asker as * "(self)", a waiter as "waits", another holder with its command line), "+N more" past `cap`, "none ()" * so a device or inode that matched nothing is visible, "absent", or why it could not be read. It references nothing * outside itself. */ export declare function formatLockHolders(report: LockHolders, cap?: number): string; /** Every lock on each of `paths`, read from this host's /proc/locks. */ export declare function fileLockHolders(paths: readonly string[], options: { readonly self: number; }): LockHolders; //#endregion