-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
102 lines (93 loc) · 1.93 KB
/
list.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"gozfs/nv"
"io"
"os"
"strings"
"time"
)
func decodeAndPrintList(buf []byte) {
l, err := nv.Decode(buf)
if err != nil {
panic(err)
}
printList("", l)
}
func printList(indent string, l nv.List) {
for _, p := range l.Pairs {
if p.Type == nv.NVLIST {
fmt.Fprintf(os.Stderr, "%sName: %s, Type: %s Size: %d\n", indent, p.Name, p.Type, p.EncodedSize)
printList(strings.Repeat(" ", len(indent)+2), p.Value.(nv.List))
} else {
fmt.Fprintf(os.Stderr, "%sName: %s, Type: %s, Size: %d Value: %+v\n", indent, p.Name, p.Type, p.EncodedSize, p.Value)
}
}
}
func list(name string) error {
reader, writer, err := os.Pipe()
if err != nil {
return err
}
go io.Copy(os.Stdout, reader)
defer reader.Close()
defer writer.Close()
var sargs = struct {
Command string `nv:"cmd"`
InNVL struct {
} `nv:"innvl"`
Opts struct {
Fd int32 `nv:"fd"`
} `nv:"opts"`
Version uint64 `nv:"version"`
}{
Command: "zfs_list",
Opts: struct {
Fd int32 `nv:"fd"`
}{
Fd: int32(writer.Fd()),
},
}
fmt.Fprintln(os.Stderr, sargs)
sbytes, err := nv.Encode(sargs)
if err != nil {
panic(err)
}
/*
w := bufio.NewWriter(os.Stderr)
w.Write(bytes)
w.Flush()
return nil
*/
/*
if !reflect.DeepEqual(lbytes, sbytes) {
want, got := diff(lbytes, sbytes)
fmt.Fprintf(os.Stderr, "want:|%s|\n\n got:|%s|\n", want, got)
fmt.Fprintln(os.Stderr, "want:")
decodeAndPrintList(lbytes)
fmt.Fprintln(os.Stderr, " got:")
decodeAndPrintList(sbytes)
}
*/
fmt.Fprintln(os.Stderr, "enter ioctl")
err = ioctl(zfs, name, sbytes, nil)
fmt.Fprintln(os.Stderr, "exit ioctl")
if err != nil {
return err
}
/*
fmt.Fprintln(os.Stderr, "start reading")
buf, err := ioutil.ReadAll(reader)
fmt.Fprintln(os.Stderr, "stop reading")
if err != nil {
return err
}
list, err := nv.Decode(buf)
if err != nil {
return err
}
printList("", list)
*/
time.Sleep(1 * time.Second)
return nil
}