Superblock.d.ts 5.2 KB

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