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
extern crate libzfs_sys as sys;
use std::ffi::CStr;
#[derive(Debug, PartialEq)]
pub struct ZpropList {
head: *mut sys::zprop_list,
pos: *mut sys::zprop_list_t,
}
impl ZpropList {
pub fn new(pl: *mut sys::zprop_list_t) -> ZpropList {
ZpropList { head: pl, pos: pl }
}
}
impl Iterator for ZpropList {
type Item = ZpropItem;
fn next(&mut self) -> Option<Self::Item> {
if self.pos.is_null() {
None
} else {
let out = Some(ZpropItem { raw: self.pos });
self.pos = unsafe { (*self.pos).pl_next };
out
}
}
}
impl Drop for ZpropList {
fn drop(&mut self) {
unsafe {
sys::zprop_free_list(self.head);
}
}
}
pub struct ZpropItem {
raw: *mut sys::zprop_list_t,
}
impl ZpropItem {
pub fn prop(&self) -> sys::zfs_prop_t {
unsafe { sys::to_zfs_prop_t((*self.raw).pl_prop).unwrap() }
}
pub fn user_prop(&self) -> &CStr {
unsafe { CStr::from_ptr((*self.raw).pl_user_prop) }
}
}
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct ZProp {
pub name: String,
pub value: String,
}