Skip to content

Commit

Permalink
Re-use Statfs_t on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Sep 24, 2020
1 parent 4d0c7e8 commit fcd6da7
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions mounts_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
package main

import (
"fmt"
"os"

"golang.org/x/sys/unix"
)

Expand All @@ -22,64 +19,53 @@ func mounts() ([]Mount, []string, error) {
return nil, nil, err
}

for _, fstat := range fs {
for _, stat := range fs {
opts := "rw"
if fstat.Flags&unix.MNT_RDONLY != 0 {
if stat.Flags&unix.MNT_RDONLY != 0 {
opts = "ro"
}
if fstat.Flags&unix.MNT_SYNCHRONOUS != 0 {
if stat.Flags&unix.MNT_SYNCHRONOUS != 0 {
opts += ",sync"
}
if fstat.Flags&unix.MNT_NOEXEC != 0 {
if stat.Flags&unix.MNT_NOEXEC != 0 {
opts += ",noexec"
}
if fstat.Flags&unix.MNT_NOSUID != 0 {
if stat.Flags&unix.MNT_NOSUID != 0 {
opts += ",nosuid"
}
if fstat.Flags&unix.MNT_UNION != 0 {
if stat.Flags&unix.MNT_UNION != 0 {
opts += ",union"
}
if fstat.Flags&unix.MNT_ASYNC != 0 {
if stat.Flags&unix.MNT_ASYNC != 0 {
opts += ",async"
}
if fstat.Flags&unix.MNT_DONTBROWSE != 0 {
if stat.Flags&unix.MNT_DONTBROWSE != 0 {
opts += ",nobrowse"
}
if fstat.Flags&unix.MNT_AUTOMOUNTED != 0 {
if stat.Flags&unix.MNT_AUTOMOUNTED != 0 {
opts += ",automounted"
}
if fstat.Flags&unix.MNT_JOURNALED != 0 {
if stat.Flags&unix.MNT_JOURNALED != 0 {
opts += ",journaled"
}
if fstat.Flags&unix.MNT_MULTILABEL != 0 {
if stat.Flags&unix.MNT_MULTILABEL != 0 {
opts += ",multilabel"
}
if fstat.Flags&unix.MNT_NOATIME != 0 {
if stat.Flags&unix.MNT_NOATIME != 0 {
opts += ",noatime"
}
if fstat.Flags&unix.MNT_NODEV != 0 {
if stat.Flags&unix.MNT_NODEV != 0 {
opts += ",nodev"
}

device := intToString(fstat.Mntfromname[:])
mountPoint := intToString(fstat.Mntonname[:])
fsType := intToString(fstat.Fstypename[:])
device := intToString(stat.Mntfromname[:])
mountPoint := intToString(stat.Mntonname[:])
fsType := intToString(stat.Fstypename[:])

if len(device) == 0 {
continue
}

var stat unix.Statfs_t
err := unix.Statfs(mountPoint, &stat)
if err != nil {
if err != os.ErrPermission {
warnings = append(warnings, fmt.Sprintf("%s: %s", mountPoint, err))
continue
}

stat = unix.Statfs_t{}
}

d := Mount{
Device: device,
Mountpoint: mountPoint,
Expand Down

0 comments on commit fcd6da7

Please sign in to comment.