-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from kolyshkin/mounted
mountinfo.Mounted: optimize by adding fast paths
- Loading branch information
Showing
6 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/moby/sys/mountinfo | ||
|
||
go 1.14 | ||
|
||
require golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= | ||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// +build linux freebsd,cgo | ||
|
||
package mountinfo | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func mounted(path string) (bool, error) { | ||
var st unix.Stat_t | ||
|
||
err := unix.Lstat(path, &st) | ||
switch err { | ||
case unix.ENOENT: | ||
// Nonexistent path, so not a mount point. | ||
return false, nil | ||
case nil: | ||
dev := st.Dev | ||
err = unix.Lstat(filepath.Dir(path), &st) | ||
if err == nil && dev != st.Dev { | ||
// Device number differs from that of parent, | ||
// so definitely a mount point. | ||
return true, nil | ||
} | ||
} | ||
|
||
entries, err := GetMounts(SingleEntryFilter(path)) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return len(entries) > 0, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters