1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package main
import (
"os"
"path/filepath"
"strings"
)
func findMounts(mounts []Mount, path string) ([]Mount, error) {
var err error
path, err = filepath.Abs(path)
if err != nil {
return nil, err
}
path, err = filepath.EvalSymlinks(path)
if err != nil {
return nil, err
}
_, err = os.Stat(path)
if err != nil {
return nil, err
}
var m []Mount
for _, v := range mounts {
if path == v.Device {
return []Mount{v}, nil
}
if strings.HasPrefix(path, v.Mountpoint) {
var nm []Mount
// keep all entries that are as close or closer to the target
for _, mv := range m {
if len(mv.Mountpoint) >= len(v.Mountpoint) {
nm = append(nm, mv)
}
}
m = nm
// add entry only if we didn't already find something closer
if len(nm) == 0 || len(v.Mountpoint) >= len(nm[0].Mountpoint) {
m = append(m, v)
}
}
}
return m, nil
}
func deviceType(m Mount) string {
if isNetworkFs(m) {
return networkDevice
}
if isSpecialFs(m) {
return specialDevice
}
if isFuseFs(m) {
return fuseDevice
}
return localDevice
}
// remote: [ "nfs", "smbfs", "cifs", "ncpfs", "afs", "coda", "ftpfs", "mfs", "sshfs", "fuse.sshfs", "nfs4" ]
// special: [ "tmpfs", "devpts", "devtmpfs", "proc", "sysfs", "usbfs", "devfs", "fdescfs", "linprocfs" ]
|