Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Created April 17, 2022 20:55
Show Gist options
  • Save andoriyu/60df6d9a409e644f45a0b57c82c1dc40 to your computer and use it in GitHub Desktop.
Save andoriyu/60df6d9a409e644f45a0b57c82c1dc40 to your computer and use it in GitHub Desktop.
//
// Created by andoriyu on 4/17/22.
//
#include "fuckery.h"
#include <stdio.h>
extern nvlist_t * fuckery_make_nvlist(const char *name, nvlist_t *list) {
FILE *fp1, *fp2, *fp3;
fp1 = fopen("/tmp/fp1.txt", "w+");
fp2 = fopen("/tmp/fp2.txt", "w+");
fp3 = fopen("/tmp/fp3.txt", "w+");
nvlist_t *bookmarks = fnvlist_alloc();
fnvlist_add_boolean(bookmarks, name);
nvlist_print(fp1, bookmarks);
nvlist_t *good = fnvlist_alloc();
fnvlist_add_boolean(good, "tests-zfs--2269423166869859637/10624745202133212450#first");
nvlist_print(fp2, good);
nvlist_print(fp3, list);
fclose(fp1);
fclose(fp2);
fclose(fp3);
fn destroy_bookmarks(&self, bookmarks: &[PathBuf]) -> Result<()> {
let validation_errors: Vec<ValidationError> = bookmarks
.iter()
.map(PathBuf::validate)
.filter(Result::is_err)
.map(Result::unwrap_err)
.collect();
if !validation_errors.is_empty() {
return Err(ValidationErrors(validation_errors));
}
let mut bookmarks_list = NvList::default();
for bookmark in bookmarks {
bookmarks_list.insert(&bookmark.to_string_lossy(), true)?;
}
/*let mut bookmarks_list = {
let name = "tests-zfs--2269423166869859637/10624745202133212450#first";
let name = CString::new(name).unwrap();
unsafe { crate::fuckery::fuckery_make_nvlist(name.as_ptr(), bookmarks_list.as_ptr()) }
};*/ // This works just fine
dbg!(bookmarks_list.as_ptr());
let mut errors_list_ptr = null_mut();
let errno = unsafe {
zfs_core_sys::lzc_destroy_bookmarks(bookmarks_list.as_ptr(), &mut errors_list_ptr)
};
dbg!(errors_list_ptr);
if !errors_list_ptr.is_null() {
let errors = unsafe { NvList::from_ptr(errors_list_ptr) };
if !errors.is_empty() {
return Err(Error::from(errors.into_hashmap()));
}
}
dbg!(errno);
match errno {
0 => Ok(()),
_ => {
let io_error = std::io::Error::from_raw_os_error(errno);
Err(Error::Io(io_error))
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment