Superblock.d.ts 4.9 KB

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