Skip to content

Instantly share code, notes, and snippets.

@gammazero
Created October 13, 2020 23:47
Show Gist options
  • Save gammazero/6de3265ef5e0d1b36d613ca7c8571602 to your computer and use it in GitHub Desktop.
Save gammazero/6de3265ef5e0d1b36d613ca7c8571602 to your computer and use it in GitHub Desktop.
package main
import (
"path"
"syscall"
)
// isMountPoint returns true if the given directory is a mountpoint
func isMountPoint(fileName string) (bool, error) {
dir := path.Clean(fileName)
if dir == "/" {
return true, nil
}
var stDir, stParent syscall.Stat_t
err := syscall.Stat(dir, &stDir)
if err != nil {
return false, err
}
err = syscall.Stat(path.Dir(dir), &stParent)
if err != nil {
return false, err
}
return stDir.Dev != stParent.Dev, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment