disk_darwin.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //go:build darwin
  2. package analytic
  3. import "strings"
  4. // macOSVirtualFilesystems contains macOS-specific virtual filesystem types
  5. var macOSVirtualFilesystems = map[string]bool{
  6. "devtmpfs": true,
  7. "kernfs": true,
  8. "fdesc": true,
  9. "map": true,
  10. "synthfs": true,
  11. "volfs": true,
  12. "ctlfs": true,
  13. "objfs": true,
  14. "procfs": true,
  15. "lifs": true,
  16. "mtab": true,
  17. "nullfs": true,
  18. "unionfs": true,
  19. "osxfuse": true,
  20. "macfuse": true,
  21. "fuse": true,
  22. "bindfs": true,
  23. "autofs_nowait": true,
  24. }
  25. // shouldSkipPath checks if a macOS path should be skipped from disk calculation
  26. func shouldSkipPath(mountpoint, device string) bool {
  27. // Skip Time Machine snapshots and system snapshots
  28. if strings.Contains(mountpoint, ".timemachine") ||
  29. strings.Contains(mountpoint, ".Snapshot") ||
  30. strings.Contains(mountpoint, "/.vol/") ||
  31. strings.Contains(device, "@") { // APFS snapshots contain @
  32. return true
  33. }
  34. // Skip read-only system volumes (including root partition on macOS Catalina+)
  35. // The root "/" partition is read-only and shares space with "/System/Volumes/Data"
  36. if strings.HasPrefix(mountpoint, "/System/Volumes/") &&
  37. !strings.HasPrefix(mountpoint, "/System/Volumes/Data") {
  38. return true
  39. }
  40. // Skip root partition "/" on macOS Catalina+ to avoid double counting with Data volume
  41. // In modern macOS, "/" and "/System/Volumes/Data" are the same APFS container
  42. if mountpoint == "/" {
  43. return true
  44. }
  45. // Skip preboot and recovery volumes
  46. if strings.Contains(mountpoint, "Preboot") ||
  47. strings.Contains(mountpoint, "Recovery") ||
  48. strings.Contains(mountpoint, "Update") ||
  49. strings.Contains(mountpoint, "VM") {
  50. return true
  51. }
  52. // Skip network mounts
  53. if strings.HasPrefix(device, "//") ||
  54. strings.HasPrefix(device, "afp://") ||
  55. strings.HasPrefix(device, "smb://") ||
  56. strings.HasPrefix(device, "nfs://") {
  57. return true
  58. }
  59. // Skip virtual disk images
  60. if strings.Contains(device, ".dmg") ||
  61. strings.Contains(device, ".sparsebundle") ||
  62. strings.Contains(device, ".sparseimage") {
  63. return true
  64. }
  65. return false
  66. }
  67. // getAdditionalVirtualFilesystems returns macOS-specific virtual filesystem types
  68. func getAdditionalVirtualFilesystems() map[string]bool {
  69. return macOSVirtualFilesystems
  70. }