File: os_shared.go

package info (click to toggle)
golang-github-appc-spec 0.8.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,108 kB
  • ctags: 1,103
  • sloc: sh: 163; makefile: 17
file content (35 lines) | stat: -rw-r--r-- 818 bytes parent folder | download | duplicates (3)
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
// +build !linux

package main

import (
	"fmt"
	"path/filepath"
	"syscall"
)

func checkMountStatfs(d string, readonly bool) error {
	// or....
	// os.Stat(path).Sys().(*syscall.Stat_t).Dev
	sfs1 := &syscall.Statfs_t{}
	if err := syscall.Statfs(d, sfs1); err != nil {
		return fmt.Errorf("error calling statfs on %q: %v", d, err)
	}
	sfs2 := &syscall.Statfs_t{}
	if err := syscall.Statfs(filepath.Dir(d), sfs2); err != nil {
		return fmt.Errorf("error calling statfs on %q: %v", d, err)
	}
	if isSameFilesystem(sfs1, sfs2) {
		return fmt.Errorf("%q is not a mount point", d)
	}
	ro := sfs1.Flags&syscall.O_RDONLY == 1
	if ro != readonly {
		return fmt.Errorf("%q mounted ro=%t, want %t", d, ro, readonly)
	}

	return nil
}

func checkMountImpl(d string, readonly bool) error {
	return checkMountStatfs(d, readonly)
}