Created
September 6, 2013 20:02
-
-
Save t-8ch/6469165 to your computer and use it in GitHub Desktop.
ZFS and Rust (d39cec65b025ad4c6de50e778ffd1177279b5b3d)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Works as expected... if one gets it to compile | |
#include <libzfs.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int zp_iter(zpool_handle_t *z, void *a) { | |
printf("name:\t%s\n", zpool_get_name(z)); | |
return 0; | |
} | |
int main(void) { | |
libzfs_handle_t *zh = libzfs_init(); | |
zpool_iter(zh, zp_iter, NULL); | |
exit(0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::libc::{c_int, c_void, c_schar}; | |
struct LibZFSHandle; | |
struct ZPoolHandle; /* { | |
zpool_hdl: *mut c_void, // some pointers | |
zpool_next: *mut c_void, | |
zpool_name: [c_schar, ..256u], // The (known) content of this buffer is nowhere to be found | |
// near the actual address of the first argument to `iter`. | |
// more stuff | |
} */ | |
#[link_args = "-lzfs"] | |
extern { | |
// extern libzfs_handle_t *libzfs_init(void); | |
fn libzfs_init() -> *mut LibZFSHandle; | |
// typedef int (*zpool_iter_f)(zpool_handle_t *, void *); | |
// extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); | |
fn zpool_iter(a: *mut LibZFSHandle, | |
b: &fn(x: *mut ZPoolHandle,y: *mut c_void)-> c_int, | |
c: c_int) | |
-> c_int; | |
// extern const char *zpool_get_name(zpool_handle_t *); | |
fn zpool_get_name(arg1: *mut ZPoolHandle) -> *c_schar; | |
} | |
fn iter(h: *mut ZPoolHandle, v: *mut c_void) -> c_int { | |
// This gets called for every available pool, like it is supposed to. | |
// However `h` is always NULL. | |
0 | |
} | |
#[fixed_stack_segment] | |
fn main() { | |
unsafe { | |
let h = libzfs_init(); | |
zpool_iter(h, iter, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment