StatFs.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.StatFs = void 0;
  4. /**
  5. * Statistics about a file system, like `fs.StatFs`.
  6. */
  7. class StatFs {
  8. static build(superblock, bigint = false) {
  9. const statfs = new StatFs();
  10. const getStatNumber = !bigint ? number => number : number => BigInt(number);
  11. // For in-memory filesystem, provide mock but reasonable values
  12. // Magic number for in-memory filesystem type (similar to ramfs)
  13. statfs.type = getStatNumber(0x858458f6);
  14. // Optimal transfer block size - commonly 4096 bytes
  15. statfs.bsize = getStatNumber(4096);
  16. // Calculate filesystem stats based on current state
  17. const totalInodes = Object.keys(superblock.inodes).length;
  18. // Mock large filesystem capacity (appears as a large filesystem to applications)
  19. const totalBlocks = 1000000;
  20. const usedBlocks = Math.min(totalInodes * 2, totalBlocks); // Rough estimation
  21. const freeBlocks = totalBlocks - usedBlocks;
  22. statfs.blocks = getStatNumber(totalBlocks); // Total data blocks
  23. statfs.bfree = getStatNumber(freeBlocks); // Free blocks in file system
  24. statfs.bavail = getStatNumber(freeBlocks); // Free blocks available to unprivileged users
  25. // File node statistics
  26. const maxFiles = 1000000; // Mock large number of available inodes
  27. statfs.files = getStatNumber(maxFiles); // Total file nodes in file system
  28. statfs.ffree = getStatNumber(maxFiles - totalInodes); // Free file nodes
  29. return statfs;
  30. }
  31. }
  32. exports.StatFs = StatFs;
  33. exports.default = StatFs;
  34. //# sourceMappingURL=StatFs.js.map