Superblock.d.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { Node } from './Node';
  2. import { Link } from './Link';
  3. import { File } from './File';
  4. import { Buffer } from '@jsonjoy.com/fs-node-builtins/lib/internal/buffer';
  5. import { type IProcess } from './process';
  6. import { DirectoryJSON, NestedDirectoryJSON } from './json';
  7. import type { PathLike } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
  8. import { TFileId, StatError } from './types';
  9. import { Result } from './result';
  10. import { FanOut } from 'thingies/lib/fanout';
  11. import { FsEvent } from './watch/FsEvent';
  12. /**
  13. * Represents a filesystem superblock, which is the root of a virtual
  14. * filesystem in Linux.
  15. * @see https://lxr.linux.no/linux+v3.11.2/include/linux/fs.h#L1242
  16. */
  17. export declare class Superblock {
  18. static fromJSON(json: DirectoryJSON, cwd?: string, opts?: {
  19. process?: IProcess;
  20. }): Superblock;
  21. static fromNestedJSON(json: NestedDirectoryJSON, cwd?: string, opts?: {
  22. process?: IProcess;
  23. }): Superblock;
  24. /**
  25. * Global file descriptor counter. UNIX file descriptors start from 0 and go sequentially
  26. * up, so here, in order not to conflict with them, we choose some big number and descrease
  27. * the file descriptor of every new opened file.
  28. * @type {number}
  29. * @todo This should not be static, right?
  30. */
  31. static fd: number;
  32. root: Link;
  33. ino: number;
  34. inodes: {
  35. [ino: number]: Node;
  36. };
  37. releasedInos: number[];
  38. fds: {
  39. [fd: number]: File;
  40. };
  41. releasedFds: number[];
  42. maxFiles: number;
  43. openFiles: number;
  44. /** The `process`-like object used by this filesystem instance. */
  45. readonly process: IProcess;
  46. constructor(opts?: {
  47. process?: IProcess;
  48. });
  49. /** Fan-out of file system change events. Multiple consumers may subscribe. */
  50. readonly changes: FanOut<FsEvent>;
  51. protected emit(change: FsEvent): void;
  52. createLink(): Link;
  53. createLink(parent: Link, name: string, isDirectory?: boolean, mode?: number): Link;
  54. deleteLink(link: Link): boolean;
  55. private _emitDeleteRecursive;
  56. private newInoNumber;
  57. private newFdNumber;
  58. createNode(mode: number): Node;
  59. deleteNode(node: Node): void;
  60. walk(steps: string[], resolveSymlinks: boolean, checkExistence: boolean, checkAccess: boolean, funcName?: string): Result<Link | null, StatError>;
  61. walk(filename: string, resolveSymlinks: boolean, checkExistence: boolean, checkAccess: boolean, funcName?: string): Result<Link | null, StatError>;
  62. walk(link: Link, resolveSymlinks: boolean, checkExistence: boolean, checkAccess: boolean, funcName?: string): Result<Link | null, StatError>;
  63. walk(stepsOrFilenameOrLink: string[] | string | Link, resolveSymlinks: boolean, checkExistence: boolean, checkAccess: boolean, funcName?: string): Result<Link | null, StatError>;
  64. getLink(steps: string[]): Link | null;
  65. getLinkOrThrow(filename: string, funcName?: string): Link;
  66. getResolvedLink(filenameOrSteps: string | string[]): Link | null;
  67. /**
  68. * Just like `getLinkOrThrow`, but also dereference/resolves symbolic links.
  69. */
  70. getResolvedLinkOrThrow(filename: string, funcName?: string): Link;
  71. getResolvedLinkResult(filename: string, funcName?: string): Result<Link, StatError>;
  72. resolveSymlinks(link: Link): Link | null;
  73. /**
  74. * Just like `getLinkOrThrow`, but also verifies that the link is a directory.
  75. */
  76. getLinkAsDirOrThrow(filename: string, funcName?: string): Link;
  77. getLinkParent(steps: string[]): Link | null;
  78. getLinkParentAsDirOrThrow(filenameOrSteps: string | string[], funcName?: string): Link;
  79. getFileByFd(fd: number): File;
  80. getFileByFdOrThrow(fd: number, funcName?: string): File;
  81. _toJSON(link?: Link, json?: {}, path?: string, asBuffer?: boolean): DirectoryJSON<string | null>;
  82. toJSON(paths?: PathLike | PathLike[], json?: {}, isRelative?: boolean, asBuffer?: boolean): DirectoryJSON<string | null>;
  83. fromJSON(json: DirectoryJSON, cwd?: string): void;
  84. fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): void;
  85. reset(): void;
  86. mountSync(mountpoint: string, json: DirectoryJSON): void;
  87. openLink(link: Link, flagsNum: number, resolveSymlinks?: boolean): File;
  88. protected openFile(filename: string, flagsNum: number, modeNum: number | undefined, resolveSymlinks?: boolean): File;
  89. readonly open: (filename: string, flagsNum: number, modeNum: number, resolveSymlinks?: boolean) => number;
  90. readonly writeFile: (id: TFileId, buf: Buffer, flagsNum: number, modeNum: number) => void;
  91. readonly read: (fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number | null) => number;
  92. readonly readv: (fd: number, buffers: ArrayBufferView[], position: number | null) => number;
  93. readonly link: (filename1: string, filename2: string) => void;
  94. readonly unlink: (filename: string) => void;
  95. readonly symlink: (targetFilename: string, pathFilename: string) => Link;
  96. readonly rename: (oldPathFilename: string, newPathFilename: string) => void;
  97. readonly mkdir: (filename: string, modeNum: number) => void;
  98. /**
  99. * Creates directory tree recursively.
  100. */
  101. readonly mkdirp: (filename: string, modeNum: number) => string | undefined;
  102. readonly rmdir: (filename: string, recursive?: boolean) => void;
  103. readonly rm: (filename: string, force?: boolean, recursive?: boolean) => void;
  104. protected closeFile(file: File): void;
  105. readonly close: (fd: number) => void;
  106. write(fd: number, buf: Buffer, offset?: number, length?: number, position?: number | null): number;
  107. readonly ftruncate: (fd: number, len?: number) => void;
  108. readonly fchmod: (fd: number, modeNum: number) => void;
  109. readonly chmod: (filename: string, modeNum: number) => void;
  110. readonly lchmod: (filename: string, modeNum: number) => void;
  111. readonly fchown: (fd: number, uid: number, gid: number) => void;
  112. readonly chown: (filename: string, uid: number, gid: number) => void;
  113. readonly lchown: (filename: string, uid: number, gid: number) => void;
  114. readonly futimes: (fd: number, atime: number, mtime: number) => void;
  115. readonly utimes: (filename: string, atime: number, mtime: number, followSymlinks?: boolean) => void;
  116. }