forked from bicomsystems/go-libzfs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bookmark.go
executable file
·51 lines (48 loc) · 1.14 KB
/
bookmark.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
package zfs
// #include <stdlib.h>
// #include <string.h>
// #include <libzfs.h>
// #include "common.h"
// #include "zpool.h"
// #include "zfs.h"
import "C"
import (
"strings"
"syscall"
)
func (self *Dataset) CreateBookmark(name string) (*Dataset, error) {
sourcePath, _ := self.Path()
var bookmarkPath string
if self.Type != DatasetTypeSnapshot && self.Type != DatasetTypeBookmark {
return nil, NewError(
EInvalidname,
"invalid source "+sourcePath+" must be snapshot or bookmark",
)
} else if self.Type == DatasetTypeSnapshot {
tmp := strings.Split(sourcePath, "@")
bookmarkPath = tmp[0] + "#" + name
} else {
tmp := strings.Split(sourcePath, "#")
bookmarkPath = tmp[0] + "#" + name
}
nvl := C.fnvlist_alloc()
C.fnvlist_add_string(nvl, C.CString(bookmarkPath), C.CString(sourcePath))
var errlist **C.nvlist_t
_, err := C.lzc_bookmark(nvl, errlist)
C.fnvlist_free(nvl)
if err != nil {
if errno, ok := err.(syscall.Errno); ok {
return nil, NewError(
ErrorCode(errno),
err.Error(),
)
} else {
return nil, NewError(
EUndefined,
err.Error(),
)
}
}
dm, err := DatasetOpen(bookmarkPath)
return dm, err
}