aboutsummaryrefslogtreecommitdiff
path: root/contrib/statfs/statfs.go
blob: 163d95af2970036bf2cf5b84a3600ea54fa0c998 (plain)
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
package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"os"

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

const (
	myName = "statfs"
)

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s PATH\n", myName)
		fmt.Fprintf(os.Stderr, "Dump the statfs information for PATH to the console, JSON format.\n")
		os.Exit(1)
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
	}
	path := flag.Arg(0)
	var st unix.Statfs_t
	err := unix.Statfs(path, &st)
	if err != nil {
		fmt.Fprintf(os.Stderr, "statfs syscall returned error: %v\n", err)
		os.Exit(2)
	}
	jsn, _ := json.MarshalIndent(st, "", "\t")
	fmt.Println(string(jsn))
}