| 1 | // Package mtab contains tools to work with /etc/mtab file. |
| 2 | package mtabscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/ |
| 3 | |
| 4 | import ( |
| 5 | "bufioscip-go gomod github.com/golang/go/src go1.12 bufio/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.12 io/" |
| 7 | "osscip-go gomod github.com/golang/go/src go1.12 os/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src go1.12 strings/" |
| 9 | ) |
| 10 | |
| 11 | type MountPointscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint# struct { |
| 12 | Devscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Dev. string |
| 13 | Mountscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Mount. string |
| 14 | Typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Type. string |
| 15 | Optsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Opts. string |
| 16 | } |
| 17 | |
| 18 | // Mounts returns a list of mount point from /etc/mtab. |
| 19 | func Mountsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/Mounts().() ([]MountPointscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#, error) { |
| 20 | file, err := osscip-go gomod github.com/golang/go/src go1.12 os/.Openscip-go gomod github.com/golang/go/src go1.12 os/Open().("/etc/mtab") |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | defer file.Closescip-go gomod github.com/golang/go/src go1.12 os/File#Close().() |
| 25 | r := bufioscip-go gomod github.com/golang/go/src go1.12 bufio/.NewReaderscip-go gomod github.com/golang/go/src go1.12 bufio/NewReader().(file) |
| 26 | var out []MountPointscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint# |
| 27 | for { |
| 28 | line, err := r.ReadStringscip-go gomod github.com/golang/go/src go1.12 bufio/Reader#ReadString().('\n') |
| 29 | if err == ioscip-go gomod github.com/golang/go/src go1.12 io/.EOFscip-go gomod github.com/golang/go/src go1.12 io/EOF. { |
| 30 | break |
| 31 | } else if err != nil { |
| 32 | return nil, err |
| 33 | } |
| 34 | fields := stringsscip-go gomod github.com/golang/go/src go1.12 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.12 strings/Fields().(line) |
| 35 | out = append(out, MountPointscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#{ |
| 36 | Devscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Dev.: fields[0], |
| 37 | Mountscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Mount.: fields[1], |
| 38 | Typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Type.: fields[2], |
| 39 | Optsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs/mtab`/MountPoint#Opts.: fields[3], |
| 40 | }) |
| 41 | } |
| 42 | return out, nil |
| 43 | } |