mounts.go 787 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package linux
  2. import (
  3. "bufio"
  4. "os"
  5. "strings"
  6. )
  7. type Mounts struct {
  8. Mounts []Mount `json:"mounts"`
  9. }
  10. type Mount struct {
  11. Device string `json:"device"`
  12. MountPoint string `json:"mountpoint"`
  13. FSType string `json:"fstype"`
  14. Options string `json:"options"`
  15. }
  16. const (
  17. DefaultBufferSize = 1024
  18. )
  19. func ReadMounts(path string) (*Mounts, error) {
  20. fin, err := os.Open(path)
  21. if err != nil {
  22. return nil, err
  23. }
  24. defer fin.Close()
  25. var mounts = Mounts{}
  26. scanner := bufio.NewScanner(fin)
  27. for scanner.Scan() {
  28. fields := strings.Fields(scanner.Text())
  29. var mount = &Mount{
  30. fields[0],
  31. fields[1],
  32. fields[2],
  33. fields[3],
  34. }
  35. mounts.Mounts = append(mounts.Mounts, *mount)
  36. }
  37. if err := scanner.Err(); err != nil {
  38. return nil, err
  39. }
  40. return &mounts, nil
  41. }