//go:build darwin package main import ( "slices" "golang.org/x/sys/unix" ) // nonPersistentFilesystems returns the device ID of every mounted // filesystem that is not persistent, with its type, from the system's // list of mounted filesystems. The device ID is read with lstat on the // mount point. Where one filesystem is mounted over another on the same // mount point, the later one in the list counts. A mount point that // lstat cannot reach is left out. func nonPersistentFilesystems() (map[uint64]string, error) { // The first call counts the filesystems, the second lists them. n, err := unix.Getfsstat(nil, unix.MNT_NOWAIT) if err != nil { return nil, err } list := make([]unix.Statfs_t, n) n, err = unix.Getfsstat(list, unix.MNT_NOWAIT) if err != nil { return nil, err } mounts := make(map[string]string, n) for _, st := range list[:n] { mounts[unix.ByteSliceToString(st.Mntonname[:])] = unix.ByteSliceToString(st.Fstypename[:]) } types := nonPersistentFilesystemTypes() devices := make(map[uint64]string) for mountPoint, fsType := range mounts { if !slices.Contains(types, fsType) { continue } if dev, ok := deviceOfPath(mountPoint); ok { devices[dev] = fsType } } return devices, nil }