--- src/storage_pool.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/storage_pool.rs b/src/storage_pool.rs index 96258f0..ad0a51a 100644 --- a/src/storage_pool.rs +++ b/src/storage_pool.rs @@ -18,7 +18,7 @@ extern crate libc; -use std::str; +use std::{ptr, str}; use connect::sys::virConnectPtr; use storage_vol::sys::virStorageVolPtr; @@ -101,6 +101,11 @@ extern "C" { info: sys::virStoragePoolInfoPtr, ) -> libc::c_int; fn virStoragePoolNumOfVolumes(ptr: sys::virStoragePoolPtr) -> libc::c_int; + fn virStoragePoolListVolumes( + ptr: sys::virStoragePoolPtr, + names: *mut *mut libc::c_char, + maxnames: libc::c_int, + ) -> libc::c_int; } pub type StoragePoolXMLFlags = self::libc::c_uint; @@ -276,6 +281,22 @@ impl StoragePool { } } + pub fn list_volumes(&self) -> Result<Vec<String>, Error> { + unsafe { + let mut names: [*mut libc::c_char; 1024] = [ptr::null_mut(); 1024]; + let size = virStoragePoolListVolumes(self.as_ptr(), names.as_mut_ptr(), 1024); + if size == -1 { + return Err(Error::new()); + } + + let mut array: Vec<String> = Vec::new(); + for x in 0..size as usize { + array.push(c_chars_to_string!(names[x])); + } + return Ok(array); + } + } + pub fn get_uuid_string(&self) -> Result<String, Error> { unsafe { let mut uuid: [libc::c_char; 37] = [0; 37]; -- 2.28.0