fs.go 855 B

123456789101112131415161718192021222324252627282930313233
  1. package procfs
  2. import (
  3. "fmt"
  4. "os"
  5. "path"
  6. )
  7. // FS represents the pseudo-filesystem proc, which provides an interface to
  8. // kernel data structures.
  9. type FS string
  10. // DefaultMountPoint is the common mount point of the proc filesystem.
  11. const DefaultMountPoint = "/proc"
  12. // NewFS returns a new FS mounted under the given mountPoint. It will error
  13. // if the mount point can't be read.
  14. func NewFS(mountPoint string) (FS, error) {
  15. info, err := os.Stat(mountPoint)
  16. if err != nil {
  17. return "", fmt.Errorf("could not read %s: %s", mountPoint, err)
  18. }
  19. if !info.IsDir() {
  20. return "", fmt.Errorf("mount point %s is not a directory", mountPoint)
  21. }
  22. return FS(mountPoint), nil
  23. }
  24. // Path returns the path of the given subsystem relative to the procfs root.
  25. func (fs FS) Path(p ...string) string {
  26. return path.Join(append([]string{string(fs)}, p...)...)
  27. }